Overview of lmfit for non-linear optimization and curve-fitting
masterlmfit is a high-level Python interface for non-linear optimization and curve-fitting. It extends scipy.optimize by providing several key enhancements:
- Parameter Objects: Instead of using plain floats, lmfit uses
lmfit.parameter.Parameterobjects. These allow you to:- Vary values during a fit or keep them fixed.
- Set upper and/or lower bounds.
- Constrain a parameter using algebraic expressions of other parameters.
- Access attributes like standard error after a fit to estimate uncertainties.
- Flexible Algorithms: You can switch fitting algorithms without modifying your objective function once a model is set up.
- Advanced Uncertainty Estimation: lmfit provides tools to explicitly explore parameter space for confidence intervals and can use the
numdifftoolspackage (if installed) to estimate uncertainties for algorithms that don't natively support it in SciPy. - Model-Based Curve Fitting: The
lmfit.model.Modelclass turns modeling functions into Python classes, making it easier to parametrize and fit data compared toscipy.optimize.curve_fit. - Built-in Models: Includes many pre-defined models for common lineshapes.