casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
casacore::NonLinearFit< T > Class Template Referenceabstract

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

#include <NonLinearFit.h>

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

Public Member Functions

 NonLinearFit (Bool svd=False)
 Create a fitter: the normal way to generate a fitter object. More...
 
 NonLinearFit (const NonLinearFit &other)
 Copy constructor (deep copy) More...
 
NonLinearFitoperator= (const NonLinearFit &other)
 Assignment (deep copy) More...
 
virtual ~NonLinearFit ()
 Destructor. More...
 
void setMaxIter (uInt maxIter=MAXITER)
 setMaxIter() sets the maximum number of iterations to do before stopping. More...
 
uInt getMaxIter () const
 getMaxIter() queries what the maximum number of iterations currently is More...
 
uInt currentIteration () const
 currentIteration() queries what the current iteration is More...
 
void setCriteria (const Double criteria=CRITERIUM)
 setCriteria() sets the convergence criteria. More...
 
Double getCriteria () const
 getCriteria() queries the current criteria More...
 
Bool converged () const
 Check to see if the fit has converged. More...
 
- Public Member Functions inherited from casacore::GenericL2Fit< T >
 GenericL2Fit ()
 Create a fitter: the normal way to generate a fitter object. More...
 
 GenericL2Fit (const GenericL2Fit &other)
 Copy constructor (deep copy) More...
 
GenericL2Fitoperator= (const GenericL2Fit &other)
 Assignment (deep copy) More...
 
virtual ~GenericL2Fit ()
 Destructor. More...
 
template<class U >
void setFunction (const Function< U, U > &function)
 Sets the function to be fitted. More...
 
template<class U >
Bool setConstraint (const uInt n, const Function< U, U > &function, const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y=typename FunctionTraits< T >::BaseType(0))
 Set the possible constraint functions. More...
 
Bool setConstraint (const uInt n, const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y=typename FunctionTraits< T >::BaseType(0))
 
Bool setConstraint (const uInt n, const typename FunctionTraits< T >::BaseType y=typename FunctionTraits< T >::BaseType(0))
 
Bool addConstraint (const Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > &function, const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y=typename FunctionTraits< T >::BaseType(0))
 
Bool addConstraint (const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y=typename FunctionTraits< T >::BaseType(0))
 
Bool addConstraint (const typename FunctionTraits< T >::BaseType y=typename FunctionTraits< T >::BaseType(0))
 
void setCollinearity (const Double cln)
 Set the collinearity factor as the square of the sine of the minimum angle allowed between input vectors (default zero for non-SVD, 1e-8 for SVD) More...
 
void asWeight (const Bool aswgt)
 Set sigma values to be interpreted as weight (i.e. More...
 
void asSVD (const Bool svd)
 Set the use of SVD or not (default). More...
 
Function< typename
FunctionTraits< T >::DiffType,
typename FunctionTraits< T >
::DiffType > * 
fittedFunction ()
 Return a pointer to the function being fitted. More...
 
const Function< typename
FunctionTraits< T >::DiffType,
typename FunctionTraits< T >
::DiffType > * 
fittedFunction () const
 
uInt fittedNumber () const
 Return the number of fitted parameters. More...
 
uInt NConstraints ()
 Return the number of constraints, and pointers to constraint functions. More...
 
Function< typename
FunctionTraits< T >::DiffType,
typename FunctionTraits< T >
::DiffType > * 
getConstraint (const uInt n)
 
Vector< typename LSQTraits
< typename FunctionTraits< T >
::BaseType >::base > 
getSVDConstraint (uInt n)
 Return the nth constraint equation derived from SVD Note that the number present will be given by getDeficiency() More...
 
void setParameterValues (const Vector< typename FunctionTraits< T >::BaseType > &parms)
 Set the parameter values. More...
 
void setMaskedParameterValues (const Vector< typename FunctionTraits< T >::BaseType > &parms)
 
Vector< typename
FunctionTraits< T >::BaseType > 
fit (const Vector< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > &sigma, const Vector< Bool > *const mask=0)
 Fit the function to the data. More...
 
Vector< typename
FunctionTraits< T >::BaseType > 
fit (const Matrix< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > &sigma, const Vector< Bool > *const mask=0)
 
Vector< typename
FunctionTraits< T >::BaseType > 
fit (const Vector< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< Bool > *const mask=0)
 
Vector< typename
FunctionTraits< T >::BaseType > 
fit (const Matrix< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< Bool > *const mask=0)
 
Vector< typename
FunctionTraits< T >::BaseType > 
fit (const Vector< Bool > *const mask=0)
 
Bool fit (Vector< typename FunctionTraits< T >::BaseType > &sol, const Vector< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > &sigma, const Vector< Bool > *const mask=0)
 
Bool fit (Vector< typename FunctionTraits< T >::BaseType > &sol, const Matrix< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > &sigma, const Vector< Bool > *const mask=0)
 
Bool fit (Vector< typename FunctionTraits< T >::BaseType > &sol, const Vector< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const typename FunctionTraits< T >::BaseType &sigma, const Vector< Bool > *const mask=0)
 
Bool fit (Vector< typename FunctionTraits< T >::BaseType > &sol, const Matrix< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const typename FunctionTraits< T >::BaseType &sigma, const Vector< Bool > *const mask=0)
 
Bool fit (Vector< typename FunctionTraits< T >::BaseType > &sol, const Vector< Bool > *const mask=0)
 
Double chiSquare () const
 Obtain the chi squared. More...
 
const Vector< typename
FunctionTraits< T >::BaseType > & 
errors () const
 Get the errors on the solved values. More...
 
Bool errors (Vector< typename FunctionTraits< T >::BaseType > &err) const
 
Matrix< DoublecompuCovariance ()
 Get covariance matrix. More...
 
void compuCovariance (Matrix< Double > &cov)
 
void buildNormalMatrix (const Vector< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > &sigma, const Vector< Bool > *const mask=0)
 Generate the normal equations by one or more calls to the buildNormalMatrix(), before calling a fit() without arguments. More...
 
void buildNormalMatrix (const Matrix< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > &sigma, const Vector< Bool > *const mask=0)
 
void buildNormalMatrix (const Vector< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< Bool > *const mask=0)
 
void buildNormalMatrix (const Matrix< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< Bool > *const mask=0)
 
Bool residual (Vector< typename FunctionTraits< T >::BaseType > &y, const Array< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &sol, const Bool model=False)
 Return the residual after a fit in y. More...
 
Bool residual (Vector< typename FunctionTraits< T >::BaseType > &y, const Array< typename FunctionTraits< T >::BaseType > &x, const Bool model=False)
 
uInt getRank () const
 Get the rank of the solution (or zero of no fit() done yet). More...
 
- Public Member Functions inherited from casacore::LSQaips
 LSQaips (uInt nUnknowns, uInt nConstraints=0)
 Construct an object with the number of unknown, knowns and constraints, and type, using the default collinearity factor and the default Levenberg-Marquardt adjustment factor. More...
 
 LSQaips (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
 Allow explicit complex/real specification. More...
 
 LSQaips (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
 
 LSQaips ()
 Default constructor (empty, real, only usable after a set(nUnknowns)) More...
 
 LSQaips (const LSQaips &other)
 Copy constructor (deep copy) More...
 
LSQaipsoperator= (const LSQaips &other)
 Assignment (deep copy) More...
 
 ~LSQaips ()
 
template<class U >
void solve (U *sol)
 Solve normal equations. More...
 
template<class U >
void solve (std::complex< U > *sol)
 
template<class U >
void solve (U &sol)
 
template<class U >
void solve (Vector< U > &sol)
 
template<class U >
Bool solveLoop (uInt &nRank, U *sol, Bool doSVD=False)
 Solve a Levenberg-Marquardt loop. More...
 
template<class U >
Bool solveLoop (uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (uInt &nRank, U &sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (uInt &nRank, Vector< U > &sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, U *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, U &sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, Vector< U > &sol, Bool doSVD=False)
 
template<class U >
Bool getCovariance (U *covar)
 Get the covariance matrix. More...
 
template<class U >
Bool getCovariance (std::complex< U > *covar)
 
template<class U >
Bool getCovariance (Array< U > &covar)
 
template<class U >
Bool getErrors (U *errors)
 Get main diagonal of covariance function (of size nUnknowns) More...
 
template<class U >
Bool getErrors (std::complex< U > *errors)
 
template<class U >
Bool getErrors (U &errors)
 
template<class U >
Bool getErrors (Vector< U > &errors)
 
- Public Member Functions inherited from casacore::LSQFit
 LSQFit (uInt nUnknowns, uInt nConstraints=0)
 Construct an object with the number of unknowns and constraints, using the default collinearity factor and the default Levenberg-Marquardt adjustment factor. More...
 
 LSQFit (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
 Allow explicit Real specification. More...
 
 LSQFit (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
 Allow explicit Complex specification. More...
 
 LSQFit ()
 Default constructor (empty, only usable after a set(nUnknowns)) More...
 
 LSQFit (const LSQFit &other)
 Copy constructor (deep copy) More...
 
LSQFitoperator= (const LSQFit &other)
 Assignment (deep copy) More...
 
 ~LSQFit ()
 
Bool invert (uInt &nRank, Bool doSVD=False)
 Triangularize the normal equations and determine the rank nRank of the normal equations and, in the case of an SVD solution, the constraint equations. More...
 
template<class U >
void copy (const Double *beg, const Double *end, U &sol, LSQReal)
 Copy date from beg to end; converting if necessary to complex data. More...
 
template<class U >
void copy (const Double *beg, const Double *end, U &sol, LSQComplex)
 
template<class U >
void copy (const Double *beg, const Double *end, U *sol, LSQReal)
 
template<class U >
void copy (const Double *beg, const Double *end, U *sol, LSQComplex)
 
template<class U >
void uncopy (Double *beg, const Double *end, U &sol, LSQReal)
 
template<class U >
void uncopy (Double *beg, const Double *end, U &sol, LSQComplex)
 
template<class U >
void uncopy (Double *beg, const Double *end, U *sol, LSQReal)
 
template<class U >
void uncopy (Double *beg, const Double *end, U *sol, LSQComplex)
 
template<class U >
void copyDiagonal (U &errors, LSQReal)
 
template<class U >
void copyDiagonal (U &errors, LSQComplex)
 
template<class U >
void solve (U *sol)
 Solve normal equations. More...
 
template<class U >
void solve (std::complex< U > *sol)
 
template<class U >
void solve (U &sol)
 
template<class U >
Bool solveLoop (uInt &nRank, U *sol, Bool doSVD=False)
 Solve a loop in a non-linear set. More...
 
template<class U >
Bool solveLoop (uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (uInt &nRank, U &sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, U *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, U &sol, Bool doSVD=False)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 Make normal equations using the cEq condition equation (cArray) (with nUnknowns elements) and a weight weight, given the known observed value obs. More...
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const V &cEq2, const U &weight, const U &obs, const U &obs2, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNormSorted (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNormSorted (uInt nIndex, const W &cEqIndex, const V &cEq, const V &cEq2, const U &weight, const U &obs, const U &obs2, Bool doNorm=True, Bool doKnown=True)
 
template<class U >
Bool getConstraint (uInt n, U *cEq) const
 Get the n-th (from 0 to the rank deficiency, or missing rank, see e.g. More...
 
template<class U >
Bool getConstraint (uInt n, std::complex< U > *cEq) const
 
template<class U >
Bool getConstraint (uInt n, U &cEq) const
 
template<class U , class V >
Bool setConstraint (uInt n, const V &cEq, const U &obs)
 Add a new constraint equation (updating nConstraints); or set a numbered constraint equation (0..nConstraints-1). More...
 
template<class U , class V >
Bool setConstraint (uInt n, const V &cEq, const std::complex< U > &obs)
 
template<class U , class V , class W >
Bool setConstraint (uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
 
template<class U , class V , class W >
Bool setConstraint (uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
 
template<class U , class V >
Bool addConstraint (const V &cEq, const U &obs)
 
template<class U , class V >
Bool addConstraint (const V &cEq, const std::complex< U > &obs)
 
template<class U , class V , class W >
Bool addConstraint (uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
 
template<class U , class V , class W >
Bool addConstraint (uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
 
Bool merge (const LSQFit &other)
 Merge other LSQFit object (i.e. More...
 
Bool merge (const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
 
Bool merge (const LSQFit &other, uInt nIndex, const std::vector< uInt > &nEqIndex)
 
template<class W >
Bool merge (const LSQFit &other, uInt nIndex, const W &nEqIndex)
 
void reset ()
 Reset status to empty. More...
 
void set (uInt nUnknowns, uInt nConstraints=0)
 Set new sizes (default is for Real) More...
 
void set (Int nUnknowns, Int nConstraints=0)
 
void set (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
 
void set (Int nUnknowns, const LSQReal &, Int nConstraints=0)
 
void set (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
 
void set (Int nUnknowns, const LSQComplex &, Int nConstraints=0)
 
void set (Double factor=1e-6, Double LMFactor=1e-3)
 Set new factors (collinearity factor, and Levenberg-Marquardt LMFactor) More...
 
void setEpsValue (Double epsval=1e-8)
 Set new value solution test. More...
 
void setEpsDerivative (Double epsder=1e-8)
 Set new derivative test. More...
 
void setMaxIter (uInt maxiter=0)
 Set maximum number of iterations. More...
 
uInt nIterations () const
 Get number of iterations done. More...
 
void setBalanced (Bool balanced=False)
 Set the expected form of the normal equations. More...
 
LSQFit::ReadyCode isReady () const
 Ask the state of the non-linear solutions. More...
 
const std::string & readyText () const
 
template<class U >
Bool getCovariance (U *covar)
 Get the covariance matrix (of size nUnknowns * nUnknowns) More...
 
template<class U >
Bool getCovariance (std::complex< U > *covar)
 
template<class U >
Bool getErrors (U *errors)
 Get main diagonal of covariance function (of size nUnknowns) More...
 
template<class U >
Bool getErrors (std::complex< U > *errors)
 
template<class U >
Bool getErrors (U &errors)
 
uInt nUnknowns () const
 Get the number of unknowns. More...
 
uInt nConstraints () const
 Get the number of constraints. More...
 
uInt getDeficiency () const
 Get the rank deficiency
Warning: Note that the number is returned assuming real values; For complex values it has to be halved
More...
 
Double getChi () const
 Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation per weight unit. More...
 
Double getChi2 () const
 
Double getSD () const
 
Double getWeightedSD () const
 
void debugIt (uInt &nun, uInt &np, uInt &ncon, uInt &ner, uInt &rank, Double *&nEq, Double *&known, Double *&constr, Double *&er, uInt *&piv, Double *&sEq, Double *&sol, Double &prec, Double &nonlin) const
 Debug: More...
 
Bool fromRecord (String &error, const RecordInterface &in)
 Create an LSQFit object from a record. More...
 
Bool toRecord (String &error, RecordInterface &out) const
 Create a record from an LSQFit object. More...
 
const Stringident () const
 Get identification of record. More...
 
void toAipsIO (AipsIO &) const
 Save or restore using AipsIO. More...
 
void fromAipsIO (AipsIO &)
 

Static Public Attributes

static const uInt MAXITER
 Default maximum number of iterations (30) More...
 
static const Double CRITERIUM
 Default convergence criterium (0.001) More...
 
- Static Public Attributes inherited from casacore::LSQFit
static Real REAL
 And values to use. More...
 
static Complex COMPLEX
 
static Separable SEPARABLE
 
static AsReal ASREAL
 
static Conjugate CONJUGATE
 

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. More...
 
- Protected Member Functions inherited from casacore::GenericL2Fit< T >
void buildMatrix (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)
 Build the normal matrix. More...
 
void buildConstraint ()
 Build the constraint equations. More...
 
void fillSVDConstraints ()
 Get the SVD constraints. More...
 
Bool buildResidual (Vector< typename FunctionTraits< T >::BaseType > &y, const Array< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > *const sol, const Bool model=False)
 Calculate residuals. More...
 
FunctionTraits< T >::BaseType getVal_p (const Array< typename FunctionTraits< T >::BaseType > &x, uInt j, uInt i) const
 Function to get evaluated functional value. More...
 
void initfit_p (uInt parcnt)
 Initialise the fitter with number of solvable parameters. More...
 
uInt testInput_p (const Array< typename FunctionTraits< T >::BaseType > &x, const Vector< typename FunctionTraits< T >::BaseType > &y, const Vector< typename FunctionTraits< T >::BaseType > *const sigma)
 Return number of condition equations and check sizes x, y, sigma. More...
 
void resetFunction ()
 Reset all the input. More...
 
- Protected Member Functions inherited from casacore::LSQFit
Doublerowrt (uInt i) const
 Get pointer in rectangular array. More...
 
Doublerowru (uInt i) const
 
void init ()
 Initialise areas. More...
 
void clear ()
 Clear areas. More...
 
void deinit ()
 De-initialise area. More...
 
void solveIt ()
 Solve normal equations. More...
 
Bool solveItLoop (Double &fit, uInt &nRank, Bool doSVD=False)
 One non-linear LM loop. More...
 
void solveMR (uInt nin)
 Solve missing rank part. More...
 
Bool invertRect ()
 Invert rectangular matrix (i.e. More...
 
Double normSolution (const Double *sol) const
 Get the norm of the current solution vector. More...
 
Double normInfKnown (const Double *known) const
 Get the infinite norm of the known vector. More...
 
Bool mergeIt (const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
 Merge sparse normal equations. More...
 
void save (Bool all=True)
 Save current status (or part) More...
 
void restore (Bool all=True)
 Restore current status. More...
 
void copy (const LSQFit &other, Bool all=True)
 Copy data. More...
 
void extendConstraints (uInt n)
 Extend the constraint equation area to the specify number of equations. More...
 
void createNCEQ ()
 Create the solution equation area nceq_p and fill it. More...
 
void getWorkSOL ()
 Get work areas for solutions, covariance. More...
 
void getWorkCOV ()
 

Protected Attributes

uInt maxiter_p
 Maximum number of iterations. More...
 
uInt curiter_p
 Current iteration number. More...
 
Double criterium_p
 Convergence criteria. More...
 
Bool converge_p
 Has fit converged. More...
 
- Protected Attributes inherited from casacore::GenericL2Fit< T >
uInt aCount_ai
 Adjustable. More...
 
Bool svd_p
 SVD indicator. More...
 
Function< typename
FunctionTraits< T >::DiffType,
typename FunctionTraits< T >
::DiffType > * 
ptr_derive_p
 Function to use in evaluating condition equation. More...
 
PtrBlock< Function< typename
FunctionTraits< T >::DiffType,
typename FunctionTraits< T >
::DiffType > * > 
constrFun_p
 List of functions describing the possible constraint equations e.g. More...
 
PtrBlock< Vector< typename
FunctionTraits< T >::BaseType > * > 
constrArg_p
 List of vectors describing the constraint equations' arguments. More...
 
PtrBlock< typename
FunctionTraits< T >::BaseType * > 
constrVal_p
 List of values describing the constraint equations' value. More...
 
uInt pCount_p
 Number of available parameters. More...
 
uInt ndim_p
 Number of dimensions of input data. More...
 
Bool needInit_p
 No normal equations yet. More...
 
Bool solved_p
 Have solution. More...
 
Bool errors_p
 Have errors. More...
 
Bool ferrors_p
 
Bool asweight_p
 Interpret as weights rather than as sigma the given values. More...
 
uInt nr_p
 The rank of the solution. More...
 
Vector< typename
FunctionTraits< T >::BaseType > 
condEq_p
 Condition equation parameters (for number of adjustable parameters) More...
 
Vector< typename
FunctionTraits< T >::BaseType > 
fullEq_p
 Equation for all available parameters. More...
 
Vector< typename
FunctionTraits< T >::ArgType > 
arg_p
 Contiguous argument areas. More...
 
Vector< typename
FunctionTraits< T >::ArgType > 
carg_p
 
Vector< typename
FunctionTraits< T >::BaseType > 
sol_p
 Local solution area. More...
 
Vector< typename
FunctionTraits< T >::BaseType > 
fsol_p
 
Vector< typename
FunctionTraits< T >::BaseType > 
err_p
 Local error area. More...
 
Vector< typename
FunctionTraits< T >::BaseType > 
ferr_p
 
FunctionTraits< T >::DiffType valder_p
 Local value and derivatives. More...
 
Vector< Vector< typename
LSQTraits< typename
FunctionTraits< T >::BaseType >
::base > > 
consvd_p
 Local SVD constraints. More...
 
- Protected Attributes inherited from casacore::LSQFit
uInt state_p
 Bits set to indicate state. More...
 
uInt nun_p
 Number of unknowns. More...
 
uInt ncon_p
 Number of constraints. More...
 
uInt n_p
 Matrix size (will be n_p = nun_p + ncon_p) More...
 
uInt r_p
 Rank of normal equations (normally n_p) More...
 
Double prec_p
 Collinearity precision. More...
 
Double startnon_p
 Levenberg start factor. More...
 
Double nonlin_p
 Levenberg current factor. More...
 
Double stepfactor_p
 Levenberg step factor. More...
 
Double epsval_p
 Test value for [incremental] solution in non-linear loop. More...
 
Double epsder_p
 Test value for known vector in non-linear loop. More...
 
Bool balanced_p
 Indicator for a well balanced normal equation. More...
 
uInt maxiter_p
 Maximum number of iterations for non-linear solution. More...
 
uInt niter_p
 Iteration count for non-linear solution. More...
 
ReadyCode ready_p
 Indicate the non-linear state. More...
 
uIntpiv_p
 Pivot table (n_p) More...
 
LSQMatrixnorm_p
 Normal equations (triangular nun_p * nun_p) More...
 
uInt nnc_p
 Current length nceq_p. More...
 
LSQMatrixnceq_p
 Normal combined with constraint equations for solutions (triangular nnc_p*nnc_p) More...
 
Doubleknown_p
 Known part equations (n_p) More...
 
Doubleerror_p
 Counts for errors (N_ErrorField) More...
 
Doubleconstr_p
 Constraint equation area (nun_p*ncon_p)) More...
 
Doublesol_p
 Solution area (n_p) More...
 
LSQFitnar_p
 Save area for non-linear case (size determined internally) More...
 
Doublelar_p
 Save area for non-symmetric (i.e. More...
 
Doublewsol_p
 Work areas for interim solutions and covariance. More...
 
Doublewcov_p
 

Additional Inherited Members

- Public Types inherited from casacore::LSQFit
enum  ReadyCode {
  NONREADY,
  SOLINCREMENT,
  DERIVLEVEL,
  MAXITER,
  NOREDUCTION,
  SINGULAR,
  N_ReadyCode
}
 State of the non-linear solution. More...
 
enum  ErrorField {
  NC,
  SUMWEIGHT,
  SUMLL,
  CHI2,
  N_ErrorField
}
 Offset of fields in error_p data area. More...
 
- Public Attributes inherited from casacore::GenericL2Fit< T >
const Double COLLINEARITY
 Default collinearity test for SVD. More...
 
- Protected Types inherited from casacore::LSQFit
enum  StateBit {
  INVERTED,
  TRIANGLE,
  NONLIN,
  N_StateBit
}
 Bits that can be set/referenced. More...
 
- Static Protected Member Functions inherited from casacore::LSQFit
static Double realMC (const std::complex< Double > &x, const std::complex< Double > &y)
 Calculate the real or imag part of x*conj(y) More...
 
static Double imagMC (const std::complex< Double > &x, const std::complex< Double > &y)
 
static Float realMC (const std::complex< Float > &x, const std::complex< Float > &y)
 
static Float imagMC (const std::complex< Float > &x, const std::complex< Float > &y)
 
- Static Protected Attributes inherited from casacore::LSQFit
static const String recid
 Record field names. More...
 
static const String state
 
static const String nun
 
static const String ncon
 
static const String prec
 
static const String startnon
 
static const String nonlin
 
static const String rank
 
static const String nnc
 
static const String piv
 
static const String constr
 
static const String known
 
static const String errors
 
static const String sol
 
static const String lar
 
static const String wsol
 
static const String wcov
 
static const String nceq
 
static const String nar
 

Detailed Description

template<class T>
class casacore::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>
casacore::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>
casacore::NonLinearFit< T >::NonLinearFit ( const NonLinearFit< T > &  other)

Copy constructor (deep copy)

template<class T>
virtual casacore::NonLinearFit< T >::~NonLinearFit ( )
virtual

Destructor.

Member Function Documentation

template<class T>
Bool casacore::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 casacore::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 casacore::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 
)
protectedpure virtual
template<class T>
Double casacore::NonLinearFit< T >::getCriteria ( ) const
inline

getCriteria() queries the current criteria

Definition at line 192 of file NonLinearFit.h.

template<class T>
uInt casacore::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& casacore::NonLinearFit< T >::operator= ( const NonLinearFit< T > &  other)

Assignment (deep copy)

template<class T>
void casacore::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 casacore::NonLinearFit< T >::setMaxIter ( uInt  maxIter = MAXITER)

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

Default value is 30.

Member Data Documentation

template<class T>
Bool casacore::NonLinearFit< T >::converge_p
protected

Has fit converged.

Definition at line 206 of file NonLinearFit.h.

template<class T>
const Double casacore::NonLinearFit< T >::CRITERIUM
static

Default convergence criterium (0.001)

Definition at line 160 of file NonLinearFit.h.

template<class T>
Double casacore::NonLinearFit< T >::criterium_p
protected

Convergence criteria.

Definition at line 204 of file NonLinearFit.h.

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

template<class T>
uInt casacore::NonLinearFit< T >::curiter_p
protected

Current iteration number.

Definition at line 202 of file NonLinearFit.h.

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

template<class T>
const uInt casacore::NonLinearFit< T >::MAXITER
static

Default maximum number of iterations (30)

Definition at line 158 of file NonLinearFit.h.

template<class T>
uInt casacore::NonLinearFit< T >::maxiter_p
protected

Maximum number of iterations.

Definition at line 195 of file NonLinearFit.h.

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


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