[SciPy-User] Least-squares fittings with bounds: why is scipy not up to the task?

Matthew Newville matt.newville@gmail....
Thu Mar 8 16:09:49 CST 2012


Dear Eric,

On Thursday, March 8, 2012 2:29:22 PM UTC-6, Eric Emsellem wrote:
>     Dear all,
>
>     I know the title looks a little provocative, but this was obviously 
done
>     on purpose. I am very impressed by the capabilities of scipy (et al.,
>     numpy etc) and have been a fan since years! But one thing (in my
>     opinion) seems to be missing  (see below). If it exists, then great 
(and
>     apologies)!
>
>     What I didn't find in Scipy (or numpy or..) is *an efficient
>     least-squares fitting routine which can include bounded, or fixed
>     parameters*. This seems like something many people must be needing! I 
am
>     right now using mpfit.py (from minpack then Craig B. Markwardt for idl
>     and Mark Rivers for python), which I did integrate in the package I am
>     developing. It is much faster than many other routines in scipy 
although
>     Adam Ginsburg did mention some test-bench he conducted some time ago,
>     showing that leastsq was quite efficient. It can include bounds, fixed
>     parameters etc. And it works great! But this is probably not the best
>     way to have such a stand-alone routine... and it is far from being
>     optimised for the modern python.
>
>     So:
>
>     is there ANY plan for having such a module in Scipy?? I think
>     (personally) that this is a MUST DO. This is typically the type of
>     routines that I hear people use in e.g., idl etc. If this could be an
>     optimised, fast (and easy to use) routine, all the better.

Yes, see https://github.com/newville/lmfit-py,  which does everything you 
ask for, and a bit more, with the possible exception of "being included in 
scipy".   For what its worth, I work with Mark Rivers (who's no longer 
actively developing Python), and our group is full of IDL users who are 
very familiar with Markwardt's implementation.

The lmfit-py version uses scipy.optimize.leastsq(), which uses MINPACK 
directly, so has the advantage of not being implemented in pure IDL or 
Python. It is definitely faster than mpfit.py.

With lmfit-py, one writes a python function-to-minimize that takes a list 
of Parameters instead of the array of floating point variables that 
scipy.optimize.leastsq() uses. Each Parameter can be freely varied of 
fixed, have upper and/or lower bounds placed on them, or be written as 
algebraic expressions of other Parameters.   Uncertainties in varied 
Parameters and correlations between Parameters are estimated using the same 
"scaled covariance" method as used in scipy.optimize.curve_fit().   There 
is limited support for optimization methods other than 
scipy.optimize.leastsq(), but I don't find these methods to be very useful 
for the kind of fitting  problems I normally see, so support for them may 
not be perfect.

Whether this gets included into scipy is up to the scipy developers. I'd be 
happy to support this module within scipy or outside scipy.
I have no doubt that improvements could be made to lmfit.py.   If you have 
suggestion, I'd be happy to hear them.

Cheers,

--Matt Newville

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120308/606c1aa1/attachment-0001.html 


More information about the SciPy-User mailing list