Loading...
Searching...
No Matches
casacore::GenericL2Fit< T > Class Template Referenceabstract
scimath package (libcasa_scimath) » Fitting_module

More...

`#include <GenericL2Fit.h>`

## Public Member Functions

| GenericL2Fit ()
| Create a fitter: the normal way to generate a fitter object.
| GenericL2Fit (const GenericL2Fit &other)
| Copy constructor (deep copy).
GenericL2Fit & | operator= (const GenericL2Fit &other)
| Assignment (deep copy).
virtual | ~GenericL2Fit ()
| Destructor.
template<class U>
void | setFunction (const Function< U, U > &function)
| Sets the function to be fitted.
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.
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).
void | asWeight (const Bool aswgt)
| Set sigma values to be interpreted as weight (i.e.
void | asSVD (const Bool svd)
| Set the use of SVD or not (default).
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * | fittedFunction ()
| Return a pointer to the function being fitted.
const Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * | fittedFunction () const
uInt | fittedNumber () const
| Return the number of fitted parameters.
uInt | NConstraints ()
| Return the number of constraints, and pointers to constraint functions.
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().
void | setParameterValues (const Vector< typename FunctionTraits< T >::BaseType > &parms)
| Set the parameter values.
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.
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.
const Vector< typename FunctionTraits< T >::BaseType > & | errors () const
| Get the errors on the solved values.
Bool | errors (Vector< typename FunctionTraits< T >::BaseType > &err) const
Matrix< Double > | compuCovariance ()
| Get covariance matrix.
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.
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.
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).
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.
| LSQaips (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
| Allow explicit complex/real specification.
| LSQaips (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
| LSQaips ()
| Default constructor (empty, real, only usable after a set(nUnknowns)).
| LSQaips (const LSQaips &other)
| Copy constructor (deep copy).
LSQaips & | operator= (const LSQaips &other)
| Assignment (deep copy).
| ~LSQaips ()
template<class U>
void | solve (U *sol)
| Solve normal equations.
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.
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.
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).
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.
| LSQFit (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
| Allow explicit Real specification.
| LSQFit (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
| Allow explicit Complex specification.
| LSQFit ()
| Default constructor (empty, only usable after a set(nUnknowns)).
| LSQFit (const LSQFit &other)
| Copy constructor (deep copy).
LSQFit & | operator= (const LSQFit &other)
| Assignment (deep copy).
| ~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.
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.
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.
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.
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.
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.
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).
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.
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.
void | set (uInt nUnknowns, uInt nConstraints=0)
| Set new sizes (default is for Real).
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).
void | setEpsValue (Double epsval=1e-8)
| Set new value solution test.
void | setEpsDerivative (Double epsder=1e-8)
| Set new derivative test.
void | setMaxIter (uInt maxiter=0)
| Set maximum number of iterations.
uInt | nIterations () const
| Get number of iterations done.
void | setBalanced (Bool balanced=False)
| Set the expected form of the normal equations.
LSQFit::ReadyCode | isReady () const
| Ask the state of the non-linear solutions.
const std::string & | readyText () const
template<class U>
Bool | getCovariance (U *covar)
| Get the covariance matrix (of size nUnknowns * nUnknowns).
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).
template<class U>
Bool | getErrors (std::complex< U > *errors)
template<class U>
Bool | getErrors (U &errors)
uInt | nUnknowns () const
| Get the number of unknowns.
uInt | nConstraints () const
| Get the number of constraints.
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 .
Double | getChi () const
| Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation per weight unit.
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:
Bool | fromRecord (String &error, const RecordInterface &in)
| Create an LSQFit object from a record.
Bool | toRecord (String &error, RecordInterface &out) const
| Create a record from an LSQFit object.
const String & | ident () const
| Get identification of record.
void | toAipsIO (AipsIO &) const
| Save or restore using AipsIO.
void | fromAipsIO (AipsIO &)

## Public Attributes

const Double | COLLINEARITY
| Default collinearity test for SVD.

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

## Protected Attributes

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

## Private Member Functions

void | setFunctionEx ()
| Set function properties.
Bool | setConstraintEx (const uInt n, const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y)
| Set Constraint properties.

## 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...
Static Public Attributes inherited from casacore::LSQFit
static Real | REAL
| And values to use.
static Complex | COMPLEX
static Separable | SEPARABLE
static AsReal | ASREAL
static Conjugate | CONJUGATE
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).
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.
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::GenericL2Fit< T >

Generic base class for least-squares fit.

### Review Status

Reviewed By:
  wbrouw
Date Reviewed:
  2004/06/14
Test programs:
  tLinearFitSVD

### Prerequisite

- Function
- Fitting

### Etymology

A set of data point is fit with some functional equation. The class acts as a generic base class for L2 type fits.

### Synopsis

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

The class acts as a base class for L2-type (least-squares) fitting. Actual classes (se e.g. LinearFit and NonLinearFit.

The following is a brief summary of the 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 M specified functions, f(j)(x) j = 0,...,M-1, we form a linear combination of the functions:

z(i) = a(0)f(0)(x(i)) + a(1)f(1)(x(i)) +... + a(M-1)f(M-1)(x(i)),

where a(j) j = 0,...,M-1 are a set of parameters to be determined. The linear least-squares fit tries to minimize

chi-square = [(y(0)-z(0))/sigma(0)]^2 + [(y(1)-z(1))/sigma(1)]^2 +..\.
+ [(y(N-1)-z(N-1))/sigma(N-1)]^2.
casacore::square
TableExprNode square(const TableExprNode &node)
Definition ExprNode.h:1350

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

For complex numbers, `[(y(i)-z(i))/sigma(i)]^2` in chi-square is replaced by `[(y(i)-z(i))/sigma(i)]*conjugate([(y(i)-z(i))/sigma(i)])`

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

f(j)(x(i)) = f(j)(x(i,0), x(i,1), x(i,2),...)

Normally, it is necessary that N > M for the solutions to be valid, since there must be more data points than model parameters to be solved.

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 also be assigned to each measurement if the standard deviation is not available. sigma can be calculated from

sigma = 1/ sqrt(weight)
casacore::sqrt
LatticeExprNode sqrt(const LatticeExprNode &expr)

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:

- Create a functional description of the parameters
- Create a fitter: GenericL2Fit<T> fitter();
- Set the functional representation: fitter.setFunction()
- Do the fit to the data: fitter.fit(x, data, sigma) (or do a number of calls to buildNormalMatrix(x, data, sigma) and finish of with fitter.fit() or fitter.sol())
- if needed the covariance; residuals; chiSquared, parameter errors can all be obtained

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)

- The following data types can be used to instantiate the GenericL2Fit templated class: Known classes for FunctionTraits. I.e simple numerical like Float, Double, Complex, DComplex; and the AutoDiff<> versions.

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 the asSVD() (which will also set the default collinearity to 1e-8).

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

### Motivation

The creation of this class was driven by the need to write code to perform baseline fitting or continuum subtraction.

### Example

In the following a polynomial is fitted through the first 20 prime numbers. The data is given in the x vector (1 to 20) and in the primesTable (2, 3,..., 71) (see tLinearFitSVD test program). In the following all four methods to calculate a polynomial through the data is used

// The list of coordinate x-values
Vector<Double> x(nPrimes);
indgen(x, 1.0); // 1, 2,..\.
Vector<Double> primesTable(nPrimes);
for (uInt i=1; i < nPrimes; i++) {
primesTable(i) =
Primes::nextLargerPrimeThan(Int(primesTable(i-1)+0.01));
}
Vector<Double> sigma(nPrimes);
sigma = 1.0;
// The fitter
LinearFit<Double> fitter;
// Linear combination of functions describing 1 + x + x*x
combination.setCoefficient(0, 1.0); // 1
combination.setCoefficient(1, 1.0); // x
combination.setCoefficient(2, 1.0); // x^2
// Get the solution
fitter.setFunction(combination);
Vector<Double> solution = fitter.fit(x, primesTable, sigma);
// Try with a function with automatic derivatives (note that default
// polynomial has zero first guess)
LinearFit<AutoDiffA<Double> > fitad;
Polynomial<AutoDiffA<Double> > sqre(2);
fitad.setFunction(sqre);
solution = fitad.fit(x, primesTable, sigma);
casacore::GenericL2Fit::setFunction
void setFunction(const Function< U, U > &function)
Sets the function to be fitted.
Definition GenericL2Fit.h:238
casacore::GenericL2Fit::fit
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.
casacore::LinearFit
Definition LinearFit.h:206
casacore::Primes::nextLargerPrimeThan
static uInt nextLargerPrimeThan(uInt number)
This function finds the next largest prime than number, returns that value and stores it in the table...
casacore::Vector
Definition Vector.h:82
casacore::Polynomial
Polynomial()
Definition Polynomial.h:94
casacore::indgen
void indgen(TableVector< T > &tv, T start, T inc)
Definition TabVecMath.h:398
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Int
int Int
Definition aipstype.h:48

In the test program examples are given on how to get the other information, and other examples.

Definition at line 211 of file GenericL2Fit.h.

## Constructor & Destructor Documentation

## GenericL2Fit() [1/2]

template<class T>

casacore::GenericL2Fit< T >::GenericL2Fit | ( |  | ) |

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

Necessary data will be deduced from the Functional provided with setFunction()

Referenced by casacore::LinearFit< T >::fitIt(), casacore::NonLinearFit< T >::fitIt(), GenericL2Fit(), and operator=().

## GenericL2Fit() [2/2]

template<class T>

casacore::GenericL2Fit< T >::GenericL2Fit | ( | const GenericL2Fit< T > & | other | ) |

Copy constructor (deep copy).

References GenericL2Fit().

## ~GenericL2Fit()

template<class T>

virtual casacore::GenericL2Fit< T >::~GenericL2Fit | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## addConstraint() [1/3]

template<class T>

Bool casacore::GenericL2Fit< T >::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) )

## addConstraint() [2/3]

template<class T>

Bool casacore::GenericL2Fit< T >::addConstraint | ( | const typename FunctionTraits< T >::BaseType | y = typename FunctionTraits< T >::BaseType(0) | ) |

## addConstraint() [3/3]

template<class T>

Bool casacore::GenericL2Fit< T >::addConstraint | ( | const Vector< typename FunctionTraits< T >::BaseType > & | x,
|  | const typename FunctionTraits< T >::BaseType | y = typename FunctionTraits< T >::BaseType(0) )

## asSVD()

template<class T>

void casacore::GenericL2Fit< T >::asSVD | ( | const Bool | svd | ) |

Set the use of SVD or not (default).

When set the default collinearity is set as well.

## asWeight()

template<class T>

void casacore::GenericL2Fit< T >::asWeight | ( | const Bool | aswgt | ) |

inline

Set sigma values to be interpreted as weight (i.e.

1/sigma/sigma). A value of zero or -1 will be skipped. The switch will stay in effect until set False again explicitly. Default is False.

Definition at line 286 of file GenericL2Fit.h.

References asweight_p.

## buildConstraint()

template<class T>

void casacore::GenericL2Fit< T >::buildConstraint | ( |  | ) |

protected

Build the constraint equations.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## buildMatrix()

template<class T>

void casacore::GenericL2Fit< T >::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 )

protected

Build the normal matrix.

References casacore::mask().

## buildNormalMatrix() [1/4]

template<class T>

void casacore::GenericL2Fit< T >::buildNormalMatrix | ( | const Matrix< typename FunctionTraits< T >::BaseType > & | x,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | y,
|  | const Vector< Bool > *const | mask = 0 )

References casacore::mask().

## buildNormalMatrix() [2/4]

template<class T>

void casacore::GenericL2Fit< T >::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 )

References casacore::mask().

## buildNormalMatrix() [3/4]

template<class T>

void casacore::GenericL2Fit< T >::buildNormalMatrix | ( | const Vector< typename FunctionTraits< T >::BaseType > & | x,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | y,
|  | const Vector< Bool > *const | mask = 0 )

References casacore::mask().

## buildNormalMatrix() [4/4]

template<class T>

void casacore::GenericL2Fit< T >::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.

The arguments are the same as for the fit(arguments) function. A False is returned if the Array sizes are unmatched.

References casacore::mask().

## buildResidual()

template<class T>

Bool casacore::GenericL2Fit< T >::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 )

protected

Calculate residuals.

References casacore::False, and casacore::LSQFit::sol.

## chiSquare()

template<class T>

Double casacore::GenericL2Fit< T >::chiSquare | ( |  | ) | const

inline

Obtain the chi squared.

It has already been calculated during the fitting process.

Definition at line 386 of file GenericL2Fit.h.

References casacore::LSQFit::getChi().

## compuCovariance() [1/2]

template<class T>

Matrix< Double > casacore::GenericL2Fit< T >::compuCovariance | ( |  | ) |

Get covariance matrix.

## compuCovariance() [2/2]

template<class T>

void casacore::GenericL2Fit< T >::compuCovariance | ( | Matrix< Double > & | cov | ) |

## errors() [1/2]

template<class T>

const Vector< typename FunctionTraits< T >::BaseType > & casacore::GenericL2Fit< T >::errors | ( |  | ) | const

Get the errors on the solved values.

### Thrown Exceptions

- AipsError if none present (or Bool returned)

## errors() [2/2]

template<class T>

Bool casacore::GenericL2Fit< T >::errors | ( | Vector< typename FunctionTraits< T >::BaseType > & | err | ) | const

## fillSVDConstraints()

template<class T>

void casacore::GenericL2Fit< T >::fillSVDConstraints | ( |  | ) |

protected

Get the SVD constraints.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## fit() [1/10]

template<class T>

Vector< typename FunctionTraits< T >::BaseType > casacore::GenericL2Fit< T >::fit | ( | const Matrix< typename FunctionTraits< T >::BaseType > & | x,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | y,
|  | const Vector< Bool > *const | mask = 0 )

References casacore::mask().

## fit() [2/10]

template<class T>

Vector< typename FunctionTraits< T >::BaseType > casacore::GenericL2Fit< T >::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 )

References casacore::mask().

## fit() [3/10]

template<class T>

Vector< typename FunctionTraits< T >::BaseType > casacore::GenericL2Fit< T >::fit | ( | const Vector< Bool > *const | mask = 0 | ) |

References casacore::mask().

## fit() [4/10]

template<class T>

Vector< typename FunctionTraits< T >::BaseType > casacore::GenericL2Fit< T >::fit | ( | const Vector< typename FunctionTraits< T >::BaseType > & | x,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | y,
|  | const Vector< Bool > *const | mask = 0 )

References casacore::mask().

## fit() [5/10]

template<class T>

Vector< typename FunctionTraits< T >::BaseType > casacore::GenericL2Fit< T >::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.

If no sigma provided, all ones assumed. In the case of no x,y,sigma the fitting equations are supposed to be generated by previous calls to buildNormalMatrix. Note that the ones with a scalar sigma will assume sigma=1 (overloading problem). The mask assumes that if present, points with False will be skipped.

### Thrown Exceptions

- AipsError if unmatched array sizes given
- AipsError if equations cannot be inverted (not in SVD case and in the case of the Bool versions.)

References casacore::mask().

## fit() [6/10]

template<class T>

Bool casacore::GenericL2Fit< T >::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 )

References casacore::mask(), and casacore::LSQFit::sol.

## fit() [7/10]

template<class T>

Bool casacore::GenericL2Fit< T >::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 )

References casacore::mask(), and casacore::LSQFit::sol.

## fit() [8/10]

template<class T>

Bool casacore::GenericL2Fit< T >::fit | ( | Vector< typename FunctionTraits< T >::BaseType > & | sol,
|  | const Vector< Bool > *const | mask = 0 )

References casacore::mask(), and casacore::LSQFit::sol.

## fit() [9/10]

template<class T>

Bool casacore::GenericL2Fit< T >::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 )

References casacore::mask(), and casacore::LSQFit::sol.

## fit() [10/10]

template<class T>

Bool casacore::GenericL2Fit< T >::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 )

References casacore::mask(), and casacore::LSQFit::sol.

## fitIt()

template<class T>

virtual Bool casacore::GenericL2Fit< 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.

Implemented in casacore::LinearFit< T >, casacore::NonLinearFit< T >, casacore::NonLinearFit< Double >, casacore::NonLinearFitLM< T >, and casacore::NonLinearFitLM< Double >.

References casacore::mask(), and casacore::LSQFit::sol.

## fittedFunction() [1/2]

template<class T>

Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * casacore::GenericL2Fit< T >::fittedFunction | ( |  | ) |

inline

Return a pointer to the function being fitted.

Should never delete this pointer.

Definition at line 296 of file GenericL2Fit.h.

References ptr_derive_p.

## fittedFunction() [2/2]

template<class T>

const Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * casacore::GenericL2Fit< T >::fittedFunction | ( |  | ) | const

inline

Definition at line 300 of file GenericL2Fit.h.

References ptr_derive_p.

## fittedNumber()

template<class T>

uInt casacore::GenericL2Fit< T >::fittedNumber | ( |  | ) | const

inline

Return the number of fitted parameters.

Definition at line 303 of file GenericL2Fit.h.

References aCount_ai.

## getConstraint()

template<class T>

Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * casacore::GenericL2Fit< T >::getConstraint | ( | const uInt | n | ) |

inline

Definition at line 311 of file GenericL2Fit.h.

## getRank()

template<class T>

uInt casacore::GenericL2Fit< T >::getRank | ( |  | ) | const

inline

Get the rank of the solution (or zero of no fit() done yet).

A valid solution will have the same rank as the number of unknowns (or double that number in the complex case). For SVD solutions the rank could be less.

Definition at line 452 of file GenericL2Fit.h.

References casacore::LSQFit::getDeficiency(), casacore::LSQFit::nUnknowns(), and solved_p.

## getSVDConstraint()

template<class T>

Vector< typename LSQTraits< typename FunctionTraits< T >::BaseType >::base > casacore::GenericL2Fit< T >::getSVDConstraint | ( | uInt | n | ) |

Return the nth constraint equation derived from SVD Note that the number present will be given by getDeficiency().

## getVal_p()

template<class T>

FunctionTraits< T >::BaseType casacore::GenericL2Fit< T >::getVal_p | ( | const Array< typename FunctionTraits< T >::BaseType > & | x,
|  | uInt | j,
|  | uInt | i ) const

protected

Function to get evaluated functional value.

## initfit_p()

template<class T>

void casacore::GenericL2Fit< T >::initfit_p | ( | uInt | parcnt | ) |

protected

Initialise the fitter with number of solvable parameters.

## NConstraints()

template<class T>

uInt casacore::GenericL2Fit< T >::NConstraints | ( |  | ) |

inline

Return the number of constraints, and pointers to constraint functions.

A 0-pointer will be returned if no such constraint present. This pointer should never be destroyed.

Definition at line 309 of file GenericL2Fit.h.

## operator=()

template<class T>

GenericL2Fit & casacore::GenericL2Fit< T >::operator= | ( | const GenericL2Fit< T > & | other | ) |

Assignment (deep copy).

References GenericL2Fit().

## resetFunction()

template<class T>

void casacore::GenericL2Fit< T >::resetFunction | ( |  | ) |

protected

Reset all the input.

Referenced by setFunction().

## residual() [1/2]

template<class T>

Bool casacore::GenericL2Fit< T >::residual | ( | Vector< typename FunctionTraits< T >::BaseType > & | y,
|  | const Array< typename FunctionTraits< T >::BaseType > & | x,
|  | const Bool | model = False )

References casacore::False.

## residual() [2/2]

template<class T>

Bool casacore::GenericL2Fit< T >::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.

x can be a vector (if 1D function) or a matrix (ND functional), as in the fit() methods. If sol is given, it is the solution derived from a fit and its value will be used; otherwise only the parameters in the fitted functional will be used. If model is given as True, the model, rather the residual <data>-<model> will be returned in y. False is returned if residuals cannot be calculated.

### Thrown Exceptions

- Aipserror if illegal array sizes

References casacore::False, and casacore::LSQFit::sol.

## setCollinearity()

template<class T>

void casacore::GenericL2Fit< T >::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).

## setConstraint() [1/3]

template<class T>
template<class U>

Bool casacore::GenericL2Fit< T >::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) )

inline

Set the possible constraint functions.

The addConstraint will add one; the setConstraint will [re-]set the nth constraint. If unsucessful, False returned.
Constraint functional can only be set when the function to be fitted has been set. It should have the same number of parameters as the function to be fitted. The x should have the correct dimension.

Definition at line 249 of file GenericL2Fit.h.

References casacore::Function< T, U >::cloneAD(), casacore::False, casacore::Function< T, U >::ndim(), casacore::Function< T, U >::nparameters(), ptr_derive_p, and setConstraintEx().

## setConstraint() [2/3]

template<class T>

Bool casacore::GenericL2Fit< T >::setConstraint | ( | const uInt | n,
|  | const typename FunctionTraits< T >::BaseType | y = typename FunctionTraits< T >::BaseType(0) )

## setConstraint() [3/3]

template<class T>

Bool casacore::GenericL2Fit< T >::setConstraint | ( | const uInt | n,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | x,
|  | const typename FunctionTraits< T >::BaseType | y = typename FunctionTraits< T >::BaseType(0) )

## setConstraintEx()

template<class T>

Bool casacore::GenericL2Fit< T >::setConstraintEx | ( | const uInt | n,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | x,
|  | const typename FunctionTraits< T >::BaseType | y )

private

Set Constraint properties.

Referenced by setConstraint().

## setFunction()

template<class T>
template<class U>

void casacore::GenericL2Fit< T >::setFunction | ( | const Function< U, U > & | function | ) |

inline

Sets the function to be fitted.

Upon entry, the argument function object is cloned. The cloned copy is used in the later fitting process. A valid function should be an instance of the Function class, so that derivatives with respect to the adjustable parameters can be calculated. The current values of the "available" parameters of the function are taken as the initial guess for the non-linear fitting.

Definition at line 238 of file GenericL2Fit.h.

References casacore::Function< T, U >::cloneAD(), ptr_derive_p, resetFunction(), and setFunctionEx().

## setFunctionEx()

template<class T>

void casacore::GenericL2Fit< T >::setFunctionEx | ( |  | ) |

private

Set function properties.

Referenced by setFunction().

## setMaskedParameterValues()

template<class T>

void casacore::GenericL2Fit< T >::setMaskedParameterValues | ( | const Vector< typename FunctionTraits< T >::BaseType > & | parms | ) |

## setParameterValues()

template<class T>

void casacore::GenericL2Fit< T >::setParameterValues | ( | const Vector< typename FunctionTraits< T >::BaseType > & | parms | ) |

Set the parameter values.

The input is a vector of parameters; all or only the masked ones' values will be set, using the input values

## testInput_p()

template<class T>

uInt casacore::GenericL2Fit< T >::testInput_p | ( | const Array< typename FunctionTraits< T >::BaseType > & | x,
|  | const Vector< typename FunctionTraits< T >::BaseType > & | y,
|  | const Vector< typename FunctionTraits< T >::BaseType > *const | sigma )

protected

Return number of condition equations and check sizes x, y, sigma.

### Thrown Exceptions

- Aipserror if size inconsistencies

## Member Data Documentation

## aCount_ai

template<class T>

uInt casacore::GenericL2Fit< T >::aCount_ai

protected

Adjustable.

Definition at line 458 of file GenericL2Fit.h.

Referenced by fittedNumber().

## arg_p

template<class T>

Vector<typename FunctionTraits<T>::ArgType> casacore::GenericL2Fit< T >::arg_p

mutable protected

Contiguous argument areas.

Definition at line 498 of file GenericL2Fit.h.

Referenced by casacore::NonLinearFit< T >::fitIt().

## asweight_p

template<class T>

Bool casacore::GenericL2Fit< T >::asweight_p

protected

Interpret as weights rather than as sigma the given values.

Definition at line 489 of file GenericL2Fit.h.

Referenced by asWeight().

## carg_p

template<class T>

Vector<typename FunctionTraits<T>::ArgType> casacore::GenericL2Fit< T >::carg_p

mutable protected

Definition at line 499 of file GenericL2Fit.h.

## COLLINEARITY

template<class T>

const Double casacore::GenericL2Fit< T >::COLLINEARITY

Default collinearity test for SVD.

Definition at line 215 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::LinearFitSVD< T >::~LinearFitSVD().

## condEq_p

template<class T>

Vector<typename FunctionTraits<T>::BaseType> casacore::GenericL2Fit< T >::condEq_p

mutable protected

Condition equation parameters (for number of adjustable parameters).

Definition at line 493 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## constrArg_p

template<class T>

PtrBlock<Vector<typename FunctionTraits<T>::BaseType>*> casacore::GenericL2Fit< T >::constrArg_p

protected

List of functions describing the possible constraint equations e.g.

The sum of 3 angles w`could be described by a HyperPlane(3) function with [1,1,1] as parameters; giving [1,1,1] as argument vector and 3.1415 as value. */ PtrBlock<Function<typename FunctionTraits<T>::DiffType, typename FunctionTraits<T>::DiffType>*> constrFun_p; /** List of vectors describing the constraint equations' arguments

Definition at line 473 of file GenericL2Fit.h.

## constrVal_p

template<class T>

PtrBlock<typename FunctionTraits<T>::BaseType *> casacore::GenericL2Fit< T >::constrVal_p

protected

List of values describing the constraint equations' value.

Definition at line 475 of file GenericL2Fit.h.

## consvd_p

template<class T>

Vector<Vector<typename LSQTraits<typename FunctionTraits<T>:: BaseType>::base> > casacore::GenericL2Fit< T >::consvd_p

mutable protected

Local SVD constraints.

Definition at line 515 of file GenericL2Fit.h.

## err_p

template<class T>

Vector<typename FunctionTraits<T>::BaseType> casacore::GenericL2Fit< T >::err_p

mutable protected

Local error area.

Definition at line 508 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## errors_p

template<class T>

Bool casacore::GenericL2Fit< T >::errors_p

protected

Have errors.

Definition at line 486 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## ferr_p

template<class T>

Vector<typename FunctionTraits<T>::BaseType> casacore::GenericL2Fit< T >::ferr_p

mutable protected

Definition at line 509 of file GenericL2Fit.h.

Referenced by casacore::NonLinearFit< T >::fitIt().

## ferrors_p

template<class T>

Bool casacore::GenericL2Fit< T >::ferrors_p

mutable protected

Definition at line 487 of file GenericL2Fit.h.

## fsol_p

template<class T>

Vector<typename FunctionTraits<T>::BaseType> casacore::GenericL2Fit< T >::fsol_p

mutable protected

Definition at line 504 of file GenericL2Fit.h.

Referenced by casacore::NonLinearFit< T >::fitIt().

## fullEq_p

template<class T>

Vector<typename FunctionTraits<T>::BaseType> casacore::GenericL2Fit< T >::fullEq_p

mutable protected

Equation for all available parameters.

Definition at line 495 of file GenericL2Fit.h.

Referenced by casacore::NonLinearFit< T >::fitIt().

## ndim_p

template<class T>

uInt casacore::GenericL2Fit< T >::ndim_p

protected

Number of dimensions of input data.

Definition at line 480 of file GenericL2Fit.h.

## needInit_p

template<class T>

Bool casacore::GenericL2Fit< T >::needInit_p

protected

No normal equations yet.

Definition at line 482 of file GenericL2Fit.h.

## nr_p

template<class T>

uInt casacore::GenericL2Fit< T >::nr_p

protected

The rank of the solution.

Definition at line 491 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## pCount_p

template<class T>

uInt casacore::GenericL2Fit< T >::pCount_p

protected

Number of available parameters.

Definition at line 478 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## ptr_derive_p

template<class T>

Function<typename FunctionTraits<T>::DiffType, typename FunctionTraits<T>::DiffType>* casacore::GenericL2Fit< T >::ptr_derive_p

protected

Function to use in evaluating condition equation.

Definition at line 463 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), casacore::NonLinearFit< T >::fitIt(), fittedFunction(), fittedFunction(), setConstraint(), and setFunction().

## sol_p

template<class T>

Vector<typename FunctionTraits<T>::BaseType> casacore::GenericL2Fit< T >::sol_p

mutable protected

Local solution area.

Definition at line 503 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), and casacore::NonLinearFit< T >::fitIt().

## solved_p

template<class T>

Bool casacore::GenericL2Fit< T >::solved_p

protected

Have solution.

Definition at line 484 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), casacore::NonLinearFit< T >::fitIt(), and getRank().

## svd_p

template<class T>

Bool casacore::GenericL2Fit< T >::svd_p

protected

SVD indicator.

Definition at line 460 of file GenericL2Fit.h.

Referenced by casacore::LinearFit< T >::fitIt(), casacore::NonLinearFit< T >::fitIt(), and casacore::LinearFitSVD< T >::~LinearFitSVD().

## valder_p

template<class T>

FunctionTraits<T>::DiffType casacore::GenericL2Fit< T >::valder_p

mutable protected

Local value and derivatives.

Definition at line 512 of file GenericL2Fit.h.

Referenced by casacore::NonLinearFit< T >::fitIt().

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

- scimath/Fitting/FittingProxy.h
- scimath/Fitting/GenericL2Fit.h