Source-linked AI summary

Non-linear Least Squares Fitting in IDL with MPFIT

Craig B. Markwardt

arXiv:0902.2850v1astro-ph.IM

TL;DR

Astronomical analysis needs reliable nonlinear least-squares fitting beyond IDL’s existing procedures. MPFIT translates and enhances MINPACK-1 for IDL, adding general and specialized fitting, constraints, weighting, covariance estimation, and diagnostics; it was adopted in publications and translated into Python and C.

  • Problem

    Existing IDL fitting procedures CURVEFIT and LMFIT were described as somewhat unreliable and as not always exploiting IDL vectorization for astronomical analysis.

  • Method

    MPFIT translates MINPACK-1 into IDL while preserving its capabilities, optimizing performance, and adding general, specialized, constrained, weighted, and diagnostic fitting functionality.

  • Results

    MPFIT was downloaded several thousand times, acknowledged in at least 29 refereed publications and 102 arXiv preprints, and translated into Python and C.

  • Takeaways & Limitations

    MPFIT provides a broadly reusable fitting engine and related routines that have been incorporated into scientific analysis and standalone spectroscopy packages.

Abstract

from arXiv · show

MPFIT is a port to IDL of the non-linear least squares fitting program MINPACK-1. MPFIT inherits the robustness of the original FORTRAN version of MINPACK-1, but is optimized for performance and convenience in IDL. In addition to the main fitting engine, MPFIT, several specialized functions are provided to fit 1-D curves and 2-D images; 1-D and 2-D peaks; and interactive fitting from the IDL command line. Several constraints can be applied to model parameters, including fixed constraints, simple bounding constraints, and "tying" the value to another parameter. Several data weighting methods are allowed, and the parameter covariance matrix is computed. Extensive diagnostic capabilities are available during the fit, via a call-back subroutine, and after the fit is complete. Several different forms of documentation are provided, including a tutorial, reference pages, and frequently asked questions. The package has been translated to C and Python as well. The full IDL and C packages can be found at http://purl.com/net/mpfit

1. Introduction

The paper motivates a robust, functional IDL least-squares fitter because existing CURVEFIT and LMFIT procedures were unreliable and underused IDL vectorization. MPFIT translates MINPACK-1 and builds new functionality on it.

  • Existing IDL procedures CURVEFIT and LMFIT are described as somewhat unreliable for astronomical data analysis.
  • The author developed robust IDL least-squares code to address limitations in the built-in fitting procedures.
  • MPFIT is based on translating the MINPACK-1 FORTRAN package into IDL and adding new functionality.

2. The Heritage of MINPACK

MPFIT inherits MINPACK-1, a robust, self-contained, general, and well-known nonlinear optimization library. Its algorithms linearize residuals, solve updates through QR factorization, and iterate toward user-selected convergence criteria.

  • MINPACK-1 is characterized as robust, self-contained, general, and well-known for nonlinear optimization.
  • MINPACK-1 provides lmder and lmdif, which require residual vectors, while lmder additionally requires user-computed Jacobians and lmdif estimates Jacobians by finite differences.
  • The algorithm linearizes the problem around trial parameters and solves for an improved parameter update using the least-squares equation (J^T J)δp = −J^T r.
  • QR factorization of the Jacobian improves numerical accuracy over the normal-equations form.
  • Levenberg-Marquardt damping produces faster convergence, and iterations continue until user-selected convergence criteria are met.

3. Translation to IDL

The IDL translation preserves MINPACK-1’s capabilities while optimizing speed and adding IDL-oriented functionality. MPFIT is a general engine supplemented by convenience routines for common fitting tasks.

  • MPFIT preserves the quality and capabilities of MINPACK-1 while optimizing speed within IDL and adding functionality suited to IDL semantics.
  • The generic MPFIT engine supports data of arbitrary dimension or weighting rather than targeting one specific problem.
  • Convenience routines address 1-D and 2-D functions, dynamically created formulae, compatibility with CURVEFIT, peak fitting, and elliptical-curve fitting.

4. Innovations of MPFIT

MPFIT extends MINPACK-1 with user interaction, parameter constraints, derivative controls, diagnostics, covariance estimation, and support for externally evaluated functions.

  • MPFIT adds innovations intended to improve usefulness and convenience while exploiting IDL capabilities.
  • Parameter Constraints: Parameters can have individual bounds, be fixed, or be tied to another parameter, with degrees of freedom and pegged parameters tracked.
  • Jacobian Calculations: Users may supply explicit Jacobians or have MPFIT calculate derivatives numerically, with step size and direction configurable per parameter.
  • Covariance Matrix: MPFIT computes the fit-parameter covariance matrix, extending the published MINPACK-1 version.
  • Hard-to-Compute Functions: For difficult functions, MPFIT can temporarily return control to the caller for external evaluation before fitting resumes.
  • Iteration Function: MPFIT can call an iteration procedure after each iteration for parameter reporting or GUI feedback.

5. Documentation

MPFIT provides extensive documentation for learning, reference, usage, and troubleshooting. The materials support both introductory fitting workflows and practical problem solving.

  • MPFIT includes source-code reference documentation attached to the source module.
  • The tutorial progresses from fitting one-dimensional data to applying parameter constraints.
  • An FAQ answers questions about module selection, important quantities, and troubleshooting techniques.

6. Usage

MPFITFUN fits a user-defined function to data with independent variable X, dependent variable Y, and Gaussian errors EY. The invocation returns best-fit parameters together with fit statistics, uncertainties, covariance, and error status.

  • MPFITFUN solves for best-fit parameters PBEST for a model F(X,P) given X, Y, EY, and starting values PSTART.
  • The fit returns the best-fit χ2 value and degrees of freedom through BESTNORM and DOF.
  • Parameter errors and the covariance matrix are returned through ERROR and COVAR.
  • Error conditions are reported through STATUS and ERRMSG.

7. Results

MPFIT achieved sustained adoption and continued development after release. Its use expanded across publications, preprints, standalone scientific packages, and translated implementations.

  • MPFIT was available for ten years, downloaded several thousand times, continuously improved, and updated with contributions from at least ten users.
  • At least 29 refereed publications since 2001 and 102 arXiv preprints acknowledged MPFIT as helpful.
  • Translations into Python and C extended MPFIT beyond IDL, with the C version offering speed and portability.
  • MPFIT was incorporated into standalone packages including PAN for neutron scattering spectroscopy and PintOfAle for X-ray spectroscopy.

8. Resources

The resources provide access to the MPFIT IDL and C code, the Python version, and related MINPACK-1 implementations.

  • The MPFIT IDL and C code is available from the project website.
  • The Python version of MPFIT is available from the listed software page.
  • Related resources include the MINPACK-1 FORTRAN webpage and a pure C translation.
Loading 0902.2850v1…