3

I have been an IDL programmer for sometime now and looking to transition to Python. I find that MPFIT's IDL version exists in Python. However, I am looking for MPFITFUN version in Python (http://www.physics.wisc.edu/~craigm/idl/down/mpfitfun.pro) or something similar.

Basically, I am looking for a Python function that takes a user-defined function and uses like Levenberg-Marquardt least-squared fit (like MPFIT).

Thanks,

keflavich
  • 18,278
  • 20
  • 86
  • 118
Rohit
  • 5,840
  • 13
  • 42
  • 65

3 Answers3

2

There are fitting functions built into SciPy but I do not know of any which account for uncertainties in data as MPFITFUN does. I have found Sherpa to be an excellent modeling and fitting package for Python which accounts for uncertainties and replaces MPFITFUN: http://cxc.harvard.edu/contrib/sherpa/

Since Sherpa is produced by astronomers it has a lot of built in astrophysical models, but you can build your own function to fit with Sherpa's Levenberg-Marquardt, Nelder-Mead or Monte Carlo algorithms. I used the template from the pysherpa blog: http://pysherpa.blogspot.com/2010/06/user-defined-sherpa-model-types-using.html

E. Douglas
  • 234
  • 1
  • 3
  • 11
2

mpfit.py is available from https://code.google.com/p/astrolibpy/ and an older version hosted at http://cars.uchicago.edu/software/python/mpfit.html.

A good alternative is lmfit: https://pypi.python.org/pypi/lmfit/, https://github.com/lmfit/lmfit-py, http://lmfit.github.io//lmfit-py/

keflavich
  • 18,278
  • 20
  • 86
  • 118
0

I accidentally found that there also exists the MPFITEXPR in Python. Here's the link to the code. You can also download it via Astrolibpy project.

Link:

https://code.google.com/p/astrolibpy/source/browse/mpfit/mpfitexpr.py?r=3545675a0662392e3e09c88beaf275c9e7881cf6

Rohit
  • 5,840
  • 13
  • 42
  • 65