Markwardt IDL Page

What's New

Programs
   Curve Fitting
   Fitting Tutorial
   Introspection
   Save Files
   Array/Set
   Printing
   Graphics
   Mathematics
   Ephemeris/Timing
   Input/Output
   Miscellaneous
   Full Listing
   Documentation

Google

Markwardt IDL Pages
Entire Web

Craig's techie blog.

Home Page of Craig Markwardt



 


IDL Curve Fitting and Function Optimization





MPFIT - Robust non-linear least squares curve fitting

These IDL routines provide a robust and relatively fast way to perform least-squares curve and surface fitting. The algorithms are translated from MINPACK-1, which is a rugged minimization routine found on Netlib, and distributed with permission. This algorithm is more desirable than CURVEFIT because it is generally more stable and less likely to crash than the brute-force approach taken by CURVEFIT, which is based upon Numerical Recipes.

MPFIT has additional capabilities not found in CURVEFIT. Model parameters can be "frozen" (that is, held constant during the fitting process). Simple boundary constraints can be imposed on parameter values, which can be helpful to keep parameters from becoming negative, for example. Please see the documentation for the PARINFO keyword if you wish to use this facility.

You can cite MPFIT in your papers! See the FAQ entry on citations for more information.

A C version of the library is available! See the special page on the C Version of MPFIT.

NEW! (2011-12-21) The function MPPROPERR can be used to estimate the uncertainty of your model function, via standard propagation of error formulae. For example, if you have a best fit model with parameter uncertainties, then MPPROPERR can be used to see where these parameter uncertainties cause the most uncertainty in the model function that is compared to your data. See the function for more documentation and examples.

Craig's presentation at the IDL Visualize 2009 workshop in Washington DC in April 2009 explains how equation solving and parameter constraints work. This zip file (Markwardt-MPFIT-Visualize2009.zip) contains the presentation as well as example codes relevant to the talk (the PDF and Powerpoint presentations are also available separately).

Frequently Asked Questions

There are several files included in the MPFIT package. Not all of them are required, but you will probably wish to download more than one. This chart can help you decide between the choices. I recommend the combination of MPFIT.PRO and MPFITFUN.PRO as being suitable for most 1-dimensional problems.

Oct 02 2012140 kb mpfit.proREQUIRED  
Oct 02 201236 kb mpfitfun.proRecommended (1D)  
Jun 22 201026 kb mpfit2dfun.proRecommended (2D)  
Dec 17 200731 kb mpfitexpr.pro  
Dec 21 20119 kb mpproperr.pro  

MPCURVEFIT.PRO is a drop-in replacement for IDL's CURVEFIT.PRO, but with the additional features of the MPFIT family of functions.

Oct 02 201225 kb mpcurvefit.pro  

You can download the entire MPFIT package as a gzip'ed tar file or zip file.

Aug 14 2013153 kb mpfit.tar.gz  
Aug 14 2013193 kb mpfit.zip  
Jun 22 20104 kb MPREADMEGeneral Documentation  
Dec 06 20031 kb INSTALLInstallation Instructions  
Feb 18 200926 kb cmpfit-1.1.tar.gz  
Feb 18 200929 kb cmpfit-1.1.zip  
Nov 13 201029 kb cmpfit-1.2.tar.gz  
Nov 13 201033 kb cmpfit-1.2.zip  

Statistical Tests - Hypothesis Testing and Confidence Interval Estimation for Chi-square, F, and Normal Distributions

The following functions perform statistical tests and estimate confidence limits. MPCHITEST, MPFTEST and MPNORMTEST are useful for hypothesis testing for variables distributed as the chi-square, F, and normal distributions. The F distribution is used in testing ratios of variances and for addition of parameters in chi square fitting. MPCHILIM and MPNORMLIM estimate confidence limits for chi-square and normal distributions.

These functions are based on the CEPHES library of special functions by Stephen Moshier, available from Netlib, and do not depend on any special function implementations from IDL.

Jun 22 20108 kb mpchitest.proChi-square  
Jun 22 201015 kb mpchilim.proChi-square  
Jun 22 201014 kb mpftest.proF distribution  
Jun 22 20108 kb mpnormtest.proNormal  
Nov 24 20068 kb mpnormlim.proNormal  

Likelihoods - Alternate likelihood functions

When fitting a linear model to data with errors in both X and Y, the standard least-squares likelihood function is not appropriate, since it considers only errors in Y. LINFITEX is an alternate likelihood function for fitting a linear model to data with errors in both X and Y, based on Numerical Recipes by Press et al. You use it as your model function with MPFIT (not MPFITFUN), and specify the data values using the FUNCTARGS keyword. Please see the documentation within the module for more information and examples of how to use it.

Apr 14 20093 kb linfitex.pro  

Peak Fitting - Specialized Peak and Ellipse Fitting Applications

These are a few specialized fitting applications which use the MPFIT library of routines. The functions MPFITPEAK and MPFIT2DPEAK replace the built-in IDL functions GAUSSFIT and GAUSS2DFIT.

The function MPFITELLIPSE is used to fit an elliptical shape to a set of X-Y scatter points. Users should still consult the ODRPack Page which is more general and robust for these types of problems, however MPFITELLIPSE is good for quick and dirty problems where the measurement error is small compared to the ellipse axes.

These functions are distinguished in several ways. First, they use the MPFIT library, and so the fitting should be more robust. That also means you can use the PARINFO keyword to hold parameters constant, etc. Second, I use a different technique to estimate the starting parameter values, which I think will be more robust under more circumstances.

Finally, for the peak fitters, you are not limited to a Gaussian function; the Lorentzian and Moffat peaks are available as well. [ The Moffat function is a modified Lorentzian with variable power law index. (Moffat, A. F. J. 1969, Astronomy & Astrophysics, v. 3, p. 455-461). ] However, you may notice that the fitting process is slower. That is simply the nature of MPFIT -- it is definitely more compute intensive.

Dec 21 201122 kb mpfitpeak.pro1D Gaussian  
Jan 02 200918 kb mpfit2dpeak.pro2D Gaussian  
Oct 02 2012140 kb mpfit.proREQUIRED  
Oct 02 201236 kb mpfitfun.proREQUIRED  
Jun 22 201026 kb mpfit2dfun.proREQUIRED  
Jun 22 201012 kb mpfitellipse.pro  

TNMIN - Non-linear optimization

TNMIN is a general non-linear function minimizer based on a truncated-Newton method by Stephen Nash. TNMIN will minimize any function that can be expressed in IDL. TNMIN can use explicitly-calculated partial derivatives, or estimate them numerically.

TNMIN has all of the enhancements that MPFIT has, including the ability to fix parameters, to place simple bounds on parameters, and to tie one parameter value to other parameter values. Both MPFIT and TNMIN share same PARINFO keyword mechanism to enable this feature.

MPFIT is still recommended for curve fitting applications, but TNMIN will be useful when general minimization is desired.

Jun 22 201070 kb tnmin.pro  


Copyright © 1997-2010 Craig B. Markwardt
Last Modified on 2013-08-14 10:55:25 by Craig Markwardt