Module Fitting

Changes made in the current development cycle can be found in the changelog.

Description (classes)

Module for various forms of mathematical fitting.

Prerequisite

Review Status

Reviewed By:
Neil Killeen
Date Reviewed:
2000/06/01
Programs:
Demos:

Synopsis

The Fitting module holds various classes and functions related to fitting models to data. Currently only least-squares fits are handled.

Least-Squares Fits

We are given N data points, which we will fit to a function with M adjustable parameters. N should normally be greater than M, and at least M non-dependent relations between the parameters should be given. In cases where there are less than M independent points, Singular-Value-Deconvolution methods are available. Each condition equation can be given an (estimated) standard deviation, which is comparable to the statistical weight, which is often used in place of the standard deviation.

The best fit is assumed to be the one which minimises the 'chi-squared'.

In the (rather common) case that individual errors are not known for the individual data points, one can assume that the individual errors are unity, calculate the best fit function, and then estimate the errors (assuming they are all identical) by inverting the normal equations. Of course, in this case we do not have an independent estimate of chi2.

The methods used in the Fitting module are described in aips++ Note 224. The methods (both standard and SVD) are based on a Cholesky decomposition of the normal equations.

General background can also be found in Numerical Recipes by Press et al..

Linear Least-Squares Fits

The linear least squares solution assumes that the fit function is a linear combination of M basis functions. It is important to note that linear refers to the dependence on the parameters; the basis functions themselves may be very non-linear.

The linear least squares problem is solved by explicitly forming and inverting the normal equations. If the normal equations are close to singular, the singular value decomposition (SVD) method may be used. Numerical Recipes suggests the SVD be always used, however this advice is not universally accepted.

Linear Least-Squares Fits with Known Linear Constraints

Sometimes there are not enough independent observations, i.e., the number of data points N is less than the number of adjustable parameters M. In this case the least-squares problem cannot be solved unless additional ``constraints'' on the adjustable parameters can be introduced. Under other circumstances, we may want to introduce constraints on the adjustable parameters to add additional information, e.g., the sum of angles of a triangle. In more complex cases, the forms of the constraints are unknown. Here we confine ourselves to least-squares fit problems in which the forms of constraints are known.

If the forms of constraint equations are known, the least-squares problem can be solved. (In the case where not enough independent observations are available, a minimum number of sufficient constraint equations have to be provided. The singular value decomposition method can be used to calculate the minimum number of orthogonal constraints needed).

Nonlinear Least-Squares Fits

We now consider the situation where the fitted function depends nonlinearly on the set of M adjustable parameters. But with nonlinear dependences the minimisation of chi2 cannot proceed as in the linear case. However, we can linearise the problem, find an approximate solution, and then iteratively seek the minimising solution. The iteration stops when e.g. the adjusted parameters do not change anymore. In general it is very difficult to find a general solution that finds a global minimum, and the solution has to be matched with the problem. The Levenberg-Marquardt algorithm is a general non-linear fitting method which can produce correct results in many cases. It has been included, but always be aware of possible problems with non-linear solutions.

What Is Available?

The basic classes are LSQBase, LSQ, and FitLSQ. They provide the basic framework for normal equations generation, solving and iterating in the case of non-linear equations.

The classes LSQBase and LSQ use a native C++ interface. They handle real data (LSQBase), and real and complex (LSQ). There is an additional class, FitLSQ which offers the functionality of LSQ, but with an additional aips++ Array interface.
Note that LSQBase and LSQ will be merged into a single class (LSQ) once aips++ uses the standard library complex classes.

The inheritance tree is FitLSQ : LSQ : LSQBase

Functionality is

  1. Fit a linear combination of functions to data points, and, optionally, use supplied constraint conditions on the adjustable parameters.
  2. Fit a nonlinear function to data points. The adjustable parameters are parameters inside the function.
  3. Repetitively perform a linear fit for every line of pixels parallel to any axis in a Lattice.
  4. Solve (as opposed to fit to a set of data), a set of equations

In addition to the basic Least Squares routines in the LSQ and FitLSQ classes, this module contains also a set of direct data fitters:

Furthermore class LatticeFit can do fitting on lattices.

Note that the basic functions have LSQ in their title; the one-step fitting functions Fit, and the solution with more freedom Solve (none available yet).

The above fitting problems can usually be solved by directly calling the fit() member function provided by one of the Fit classes above, or by gradually building the normal equation matrix and solving the normal equations (solve()).

A Distributed Object interface to the classes is available (DOfitting) for use in the Glish dfit object, available through the fitting.g script.

Motivation

This module was motivated by baseline subtraction/continuum fitting in the first instance.

To Do


Classes

Fit2D -- Fit 2-D objects to 2-D Lattices or Arrays (full description)
FitGaussian -- Multidimensional fitter class for Gaussians. (full description)
FitLSQ -- Interface for aips++ least squares fitting (full description)
GenericL2Fit -- Generic base lass for least-squares fit. (full description)
LSQ -- Basic routines for complex least squares solutions (full description)
LSQBase -- Basic class for the least squares fitting (full description)
LSQComplex -- Type of complex numeric class indicator (full description)
LSQFit -- Basic class for the least squares fitting (full description)
LSQMatrix -- Support class for the LSQ package (full description)
LSQNull -- Non relevant class indicator (full description)
LSQReal -- Typing support classes for LSQ classes (full description)
LSQTraits -- Traits for numeric classes used (full description)
LSQTraits_CD -- LSQTraits specialization for DComplex (full description)
LSQTraits_CF -- LSQTraits specialization for Complex (full description)
LSQTraits_D -- LSQTraits specialization for Double (full description)
LSQTraits_F -- LSQTraits specialization for Float (full description)
LSQType -- Determine if pointer type (full description)
LSQaips -- Interface for aips++ Vectors in least squares fitting (full description)
LatticeFit -- Fit every line of pixels parallel to any axis in a Lattice. (full description)
LinearFit -- Class for linear least-squares fit. (full description)
LinearFitConstraint -- Linear least-squares fit with known linear constraints. (full description)
LinearFitConstraintLU -- Solve Linear fit with constraints with LU factorization method (full description)
LinearFitSVD -- Linear least-squares fit using Singular Value Decomposition method. (full description)
NonLinearFit -- Class for non-linear least-squares fit. (full description)
NonLinearFitLM -- Solve non-linear fit with Levenberg-Marquardt method. (full description)
fitting -- This class gives Glish to Fitting connection (full description)