[SciPy-User] lmfit-py -- simple least squares minimization

Matt Newville newville@cars.uchicago....
Mon Aug 15 08:05:50 CDT 2011


Hi,

Having used on numpy and scipy for many years and being very pleased
with them, I've found an area which I think might benefit from a
modest improvement, and have tried to implement this.

The scipy.optimize routines are robust, but seem a little unfriendly
to people coming from proprietary environments or Numerical
Recipes-level tools.   Specifically, the Levenberg-Marquardt algorithm
is used heavily in many domains (including the x-ray spectroscopy
fields I am most familiar with), but the MINPACK and
scipy.optimize.leastsq implementation lack convenient ways to:
      -  turn on/off parameters for fitting,  that is, to "fix"
certain parameters.
      -  place simple min/max bounds on parameters
      -  place simple mathematical constraints on parameters.

While these limitations can be worked around, doing so requires
putting many options into the function to be minimized, which is
somewhat inconvenient.    On the other hand, these features do exist
in less robust fitting code that is not based on directly on MINPACK
or as well-supported as scipy.

I've written a module to do this so that the least-squares
minimization from scipy.optimize.leastsq can take bounded and
constrained parameters, and tried to make it of general use.    This
code (BSD-licensed, somewhat documented) is at
         http://github.com/newville/lmfit-py

The constraint mechanism is a bit involved (using the ast module
instead of 'eval'), but the rest of the code is quite straightforward
and simple.   Currently, this supports minimization with
scipy.optimize.leastsq, scipy.optimize.fmin_l_bfgs_b, and
scipy.optimize.anneal. Supporting other algorithms could be possible.

If you find this interesting or useful, I'd appreciate any feedback
you might have.  For example, this is not currently organized as a
scikit -- would that be preferable?

Cheers,

--Matt Newville <newville at cars.uchicago.edu>


More information about the SciPy-User mailing list