27#ifndef SCIMATH_GENERICL2FIT_H
28#define SCIMATH_GENERICL2FIT_H
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/Matrix.h>
33#include <casacore/casa/Arrays/Vector.h>
34#include <casacore/casa/Containers/Block.h>
35#include <casacore/scimath/Fitting/LSQaips.h>
36#include <casacore/scimath/Fitting/LSQTraits.h>
37#include <casacore/scimath/Functionals/Function.h>
38#include <casacore/scimath/Functionals/FunctionTraits.h>
39#include <casacore/scimath/Mathematics/AutoDiff.h>
44template <
class T,
class U>
class Function;
257 function.
ndim() != x.nelements())
return False;
569#ifndef CASACORE_NO_AUTO_TEMPLATES
570#include <casacore/scimath/Fitting/GenericL2Fit.tcc>
AutoDiff< T > DiffType
Default type for differentiation.
T BaseType
Template base type.
virtual uInt ndim() const =0
Returns the number of dimensions of function.
uInt nparameters() const
Returns the number of parameters.
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
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.
const Vector< typename FunctionTraits< T >::BaseType > & errors() const
Get the errors on the solved 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)
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * fittedFunction()
Return a pointer to the function being fitted.
const Double COLLINEARITY
Default collinearity test for SVD.
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 > err_p
Local error area.
Vector< typename FunctionTraits< T >::ArgType > carg_p
uInt aCount_ai
Adjustable.
Vector< typename FunctionTraits< T >::BaseType > fit(const Vector< Bool > *const mask=0)
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.
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 getRank() const
Get the rank of the solution (or zero of no fit() done yet).
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.
GenericL2Fit & operator=(const GenericL2Fit &other)
Assignment (deep copy)
FunctionTraits< T >::BaseType getVal_p(const Array< typename FunctionTraits< T >::BaseType > &x, uInt j, uInt i) const
Function to get evaluated functional value.
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.
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.
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)
uInt fittedNumber() const
Return the number of fitted parameters.
void setFunction(const Function< U, U > &function)
Sets the function to be fitted.
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 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.
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.
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)
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.
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))
const Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * fittedFunction() const
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.
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)
void initfit_p(uInt parcnt)
Initialise the fitter with number of solvable parameters.
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.
Matrix< Double > compuCovariance()
Get covariance matrix.
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * getConstraint(const uInt n)
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.
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...
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.