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