casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
casa::NonLinearFit< T > Class Template Reference

Class for non-linear least-squares fit. More...

#include <NonLinearFit.h>

Inheritance diagram for casa::NonLinearFit< T >:
casa::GenericL2Fit< T > casa::LSQaips casa::LSQFit casa::NonLinearFitLM< T >

List of all members.

Public Member Functions

 NonLinearFit (Bool svd=False)
 Create a fitter: the normal way to generate a fitter object.
 NonLinearFit (const NonLinearFit &other)
 Copy constructor (deep copy)
NonLinearFitoperator= (const NonLinearFit &other)
 Assignment (deep copy)
virtual ~NonLinearFit ()
 Destructor.
void setMaxIter (uInt maxIter=MAXITER)
 setMaxIter() sets the maximum number of iterations to do before stopping.
uInt getMaxIter () const
 getMaxIter() queries what the maximum number of iterations currently is
uInt currentIteration () const
 currentIteration() queries what the current iteration is
void setCriteria (const Double criteria=CRITERIUM)
 setCriteria() sets the convergence criteria.
Double getCriteria () const
 getCriteria() queries the current criteria
Bool converged () const
 Check to see if the fit has converged.

Static Public Attributes

static const uInt MAXITER
 Default maximum number of iterations (30)
static const Double CRITERIUM
 Default convergence criterium (0.001)

Protected Member Functions

virtual Bool fitIt (Vector< typename FunctionTraits< T >::BaseType > &sol, const Array< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > *const sigma, const Vector< Bool > *const mask=0)=0
 Generalised fitter.

Protected Attributes

uInt maxiter_p
 Maximum number of iterations.
uInt curiter_p
 Current iteration number.
Double criterium_p
 Convergence criteria.
Bool converge_p
 Has fit converged.

Detailed Description

template<class T>
class casa::NonLinearFit< T >

Class for non-linear least-squares fit.

Review Status

Reviewed By:
wbrouw
Date Reviewed:
2006/06/15
Test programs:
tNonLinearFitLM

Prerequisite

Etymology

A nonlinear function is used to fit a set of data points.

Synopsis

NOTE: Constraints added. Documentation out of date at moment, check the tLinearFitSVD and tNonLinearFirLM programs for examples.

The following is a brief summary of the non-linear least-squares fit problem. See module header, Fitting , for a more complete description.

Given a set of N data points (measurements), (x(i), y(i)) i = 0,...,N-1, along with a set of standard deviations, sigma(i), for the data points, and a specified non-linear function, f(x;a) where a = a(j) j = 0,...,M-1 are a set of parameters to be determined, the non-linear least-squares fit tries to minimize

    chi-square = [(y(0)-f(x(0);a)/sigma(0)]^2 + [(y(1)-f(x(1);a)/sigma(1)]^2 + 
                 ... + [(y(N-1)-f(x(N-1);a))/sigma(N-1)]^2.

by adjusting {a(j)} in the equation.

For multidimensional functions, x(i) is a vector, and

    f(x(i);a) = f(x(i,0), x(i,1), x(i,2), ...;a)

If the measurement errors (standard deviation sigma) are not known at all, they can all be set to one initially. In this case, we assume all measurements have the same standard deviation, after minimizing chi-square, we recompute

    sigma^2 = {(y(0)-z(0))^2 + (y(1)-z(1))^2 + ..\.
              + (y(N-1)-z(N-1))^2}/(N-M) = chi-square/(N-M).

A statistic weight can be also be assigned to each measurement if the standard deviation is not available. sigma can be calculated from

    sigma = 1/ sqrt(weight)

Alternatively a 'weight' switch can be set with asWeight(). For best arithmetic performance, weight should be normalized to a maximum value of one. Having a large weight value can sometimes lead to overflow problems.

The function to be fitted to the data can be given as an instance of the Function class. One can also form a sum of functions using the CompoundFunction .

For small datasets the usage of the calls is:

Note that the fitter is reusable. An example is given in the following.

The solution of a fit always produces the total number of parameters given to the fitter. I.e. including any parameters that were fixed. In the latter case the solution returned will be the fixed value.

Template Type Argument Requirements (T)

If there are a large number of unknowns or a large number of data points machine memory limits (or timing reasons) may not allow a complete in-core fitting to be performed. In this case one can incrementally build the normal equation (see buildNormalMatrix()).

The normal operation of the class tests for real inversion problems only. If tests are needed for almost collinear columns in the solution matrix, the collinearity can be set as the square of the sine of the minimum angle allowed.

Singular Value Decomposition is supported by setting the 'svd' switch, which has a behaviour completely identical to, apart from a default collinearity check of 1e-8.

Other information (see a.o. LSQaips ) can be set and obtained as well.

Motivation

The creation of the class module was driven by the need to write code to fit Gaussian functions to data points.

Example

Definition at line 153 of file NonLinearFit.h.


Constructor & Destructor Documentation

template<class T>
casa::NonLinearFit< T >::NonLinearFit ( Bool  svd = False) [explicit]

Create a fitter: the normal way to generate a fitter object.

Necessary data will be deduced from the Functional provided with setFunction(). Create optionally a fitter with SVD behaviour specified.

template<class T>
casa::NonLinearFit< T >::NonLinearFit ( const NonLinearFit< T > &  other)

Copy constructor (deep copy)

template<class T>
virtual casa::NonLinearFit< T >::~NonLinearFit ( ) [virtual]

Destructor.


Member Function Documentation

template<class T>
Bool casa::NonLinearFit< T >::converged ( ) const [inline]

Check to see if the fit has converged.

Definition at line 195 of file NonLinearFit.h.

template<class T>
uInt casa::NonLinearFit< T >::currentIteration ( ) const [inline]

currentIteration() queries what the current iteration is

Definition at line 184 of file NonLinearFit.h.

template<class T>
virtual Bool casa::NonLinearFit< T >::fitIt ( Vector< typename FunctionTraits< T >::BaseType > &  sol,
const Array< typename FunctionTraits< T >::BaseType > &  x,
const Vector< typename FunctionTraits< T >::BaseType > &  y,
const Vector< typename FunctionTraits< T >::BaseType > *const  sigma,
const Vector< Bool > *const  mask = 0 
) [protected, pure virtual]

Generalised fitter.

Implements casa::GenericL2Fit< T >.

Implemented in casa::NonLinearFitLM< T >, and casa::NonLinearFitLM< Double >.

template<class T>
Double casa::NonLinearFit< T >::getCriteria ( ) const [inline]

getCriteria() queries the current criteria

Definition at line 192 of file NonLinearFit.h.

template<class T>
uInt casa::NonLinearFit< T >::getMaxIter ( ) const [inline]

getMaxIter() queries what the maximum number of iterations currently is

Definition at line 181 of file NonLinearFit.h.

template<class T>
NonLinearFit& casa::NonLinearFit< T >::operator= ( const NonLinearFit< T > &  other)

Assignment (deep copy)

template<class T>
void casa::NonLinearFit< T >::setCriteria ( const Double  criteria = CRITERIUM) [inline]

setCriteria() sets the convergence criteria.

The actual value and its interpretation depends on the derived class used to do the actual iteration. Default value is 0.001.

Definition at line 189 of file NonLinearFit.h.

template<class T>
void casa::NonLinearFit< T >::setMaxIter ( uInt  maxIter = MAXITER)

setMaxIter() sets the maximum number of iterations to do before stopping.

Default value is 30.

Reimplemented from casa::LSQFit.


Member Data Documentation

template<class T>
Bool casa::NonLinearFit< T >::converge_p [protected]

Has fit converged.

Definition at line 206 of file NonLinearFit.h.

template<class T>
const Double casa::NonLinearFit< T >::CRITERIUM [static]

Default convergence criterium (0.001)

Definition at line 160 of file NonLinearFit.h.

template<class T>
Double casa::NonLinearFit< T >::criterium_p [protected]

Convergence criteria.

Definition at line 204 of file NonLinearFit.h.

Referenced by casa::NonLinearFit< Double >::getCriteria(), and casa::NonLinearFit< Double >::setCriteria().

template<class T>
uInt casa::NonLinearFit< T >::curiter_p [protected]

Current iteration number.

Definition at line 202 of file NonLinearFit.h.

Referenced by casa::NonLinearFit< Double >::currentIteration().

template<class T>
const uInt casa::NonLinearFit< T >::MAXITER [static]

Default maximum number of iterations (30)

Reimplemented from casa::LSQFit.

Definition at line 158 of file NonLinearFit.h.

template<class T>
uInt casa::NonLinearFit< T >::maxiter_p [protected]

Maximum number of iterations.

Reimplemented from casa::LSQFit.

Definition at line 195 of file NonLinearFit.h.

Referenced by casa::NonLinearFit< Double >::currentIteration(), and casa::NonLinearFit< Double >::getMaxIter().


The documentation for this class was generated from the following file: