Go to the documentation of this file.
29 #ifndef SCIMATH_GENERICL2FIT_H
30 #define SCIMATH_GENERICL2FIT_H
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Arrays/Matrix.h>
35 #include <casacore/casa/Arrays/Vector.h>
36 #include <casacore/casa/Containers/Block.h>
37 #include <casacore/scimath/Fitting/LSQaips.h>
38 #include <casacore/scimath/Fitting/LSQTraits.h>
39 #include <casacore/scimath/Functionals/Function.h>
40 #include <casacore/scimath/Functionals/FunctionTraits.h>
41 #include <casacore/scimath/Mathematics/AutoDiff.h>
46 template <
class T>
class Array;
259 ptr_derive_p->nparameters() !=
function.nparameters() ||
260 function.ndim() != x.nelements())
return False;
572 #ifndef CASACORE_NO_AUTO_TEMPLATES
573 #include <casacore/scimath/Fitting/GenericL2Fit.tcc>
574 #endif //# CASACORE_NO_AUTO_TEMPLATES
const Double COLLINEARITY
Default collinearity test for SVD.
A 2-D Specialization of the Array class.
Class that computes partial derivatives by automatic differentiation.
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.
uInt nUnknowns() const
Get the number of unknowns.
void buildConstraint()
Build the constraint equations.
uInt NConstraints()
Return the number of constraints, and pointers to constraint functions.
uInt ndim_p
Number of dimensions of input data.
A drop-in replacement for Block<T*>.
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.
uInt pCount_p
Number of available parameters.
Bool needInit_p
No normal equations yet.
void resetFunction()
Reset all the input.
void asWeight(const Bool aswgt)
Set sigma values to be interpreted as weight (i.e.
Vector< typename FunctionTraits< T >::ArgType > arg_p
Contiguous argument areas.
uInt getRank() const
Get the rank of the solution (or zero of no fit() done yet).
FunctionTraits< T >::BaseType getVal_p(const Array< typename FunctionTraits< T >::BaseType > &x, uInt j, uInt i) const
Function to get evaluated functional value.
GenericL2Fit & operator=(const GenericL2Fit &other)
Assignment (deep copy)
void setCollinearity(const Double cln)
Set the collinearity factor as the square of the sine of the minimum angle allowed between input vect...
void setFunctionEx()
Set function properties.
Double getChi() const
Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation p...
Vector< typename FunctionTraits< T >::BaseType > err_p
Local error area.
Vector< typename FunctionTraits< T >::BaseType > fullEq_p
Equation for all available parameters.
Vector< typename FunctionTraits< T >::BaseType > condEq_p
Condition equation parameters (for number of adjustable parameters)
uInt aCount_ai
Adjustable.
uInt nr_p
The rank of the solution.
Vector< typename FunctionTraits< T >::BaseType > ferr_p
const Vector< typename FunctionTraits< T >::BaseType > & errors() const
Get the errors on the solved values.
Double chiSquare() const
Obtain the chi squared.
Bool setConstraintEx(const uInt n, const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y)
Set Constraint properties.
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.
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 get...
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * getConstraint(const uInt n)
void setMaskedParameterValues(const Vector< typename FunctionTraits< T >::BaseType > &parms)
void setParameterValues(const Vector< typename FunctionTraits< T >::BaseType > &parms)
Set the parameter values.
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))
Generic base class for least-squares fit.
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.
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.
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()...
void fillSVDConstraints()
Get the SVD constraints.
Bool solved_p
Have solution.
virtual ~GenericL2Fit()
Destructor.
uInt getDeficiency() const
Get the rank deficiency Warning: Note that the number is returned assuming real values; For complex ...
void initfit_p(uInt parcnt)
Initialise the fitter with number of solvable parameters.
this file contains all the compiler specific defines
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.
void setFunction(const Function< U, U > &function)
Sets the function to be fitted.
const Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * fittedFunction() const
GenericL2Fit()
Create a fitter: the normal way to generate a fitter object.
Numerical functional interface class.
uInt fittedNumber() const
Return the number of fitted parameters.
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.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
Bool asweight_p
Interpret as weights rather than as sigma the given values.
Interface for Casacore Vectors in least squares fitting.
template <class T, class U> class vector;
Vector< Vector< typename LSQTraits< typename FunctionTraits< T >::BaseType >::base > > consvd_p
Local SVD constraints.
FunctionTraits< T >::DiffType valder_p
Local value and derivatives.
bool Bool
Define the standard types used by Casacore.
PtrBlock< Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * > constrFun_p
List of functions describing the possible constraint equations e.g.
Matrix< Double > compuCovariance()
Get covariance matrix.
A 1-D Specialization of the Array class.
Vector< typename FunctionTraits< T >::BaseType > sol_p
Local solution area.
Bool errors_p
Have errors.
T BaseType
Template base type.
PtrBlock< typename FunctionTraits< T >::BaseType * > constrVal_p
List of values describing the constraint equations' value.
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * ptr_derive_p
Function to use in evaluating condition equation.
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 >::ArgType > carg_p
Vector< typename FunctionTraits< T >::BaseType > fsol_p
PtrBlock< Vector< typename FunctionTraits< T >::BaseType > * > constrArg_p
List of vectors describing the constraint equations' arguments.