casacore
Loading...
Searching...
No Matches
GenericL2Fit.h
Go to the documentation of this file.
1// # GenericL2Fit.h: Generic base class for least-squares fit.
2// #
3// # Copyright (C) 2001,2002,2004,2005
4// # Associated Universities, Inc. Washington DC, USA.
5// #
6// # This library is free software; you can redistribute it and/or modify it
7// # under the terms of the GNU Library General Public License as published by
8// # the Free Software Foundation; either version 2 of the License, or (at your
9// # option) any later version.
10// #
11// # This library is distributed in the hope that it will be useful, but WITHOUT
12// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14// # License for more details.
15// #
16// # You should have received a copy of the GNU Library General Public License
17// # along with this library; if not, write to the Free Software Foundation,
18// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19// #
20// # Correspondence concerning AIPS++ should be addressed as follows:
21// # Internet email: casa-feedback@nrao.edu.
22// # Postal address: AIPS++ Project Office
23// # National Radio Astronomy Observatory
24// # 520 Edgemont Road
25// # Charlottesville, VA 22903-2475 USA
26
27#ifndef SCIMATH_GENERICL2FIT_H
28#define SCIMATH_GENERICL2FIT_H
29
30// # Includes
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>
40
41namespace casacore { // begin namespace casa
42
43// # Forward declarations
44template <class T, class U>
45class Function;
46
47// <summary> Generic base class for least-squares fit.
48// </summary>
49//
50// <reviewed reviewer="wbrouw" date="2004/06/14" tests="tLinearFitSVD.cc"
51// demos="">
52// </reviewed>
53//
54// <prerequisite>
55// <li> <linkto class="Function">Function</linkto>
56// <li> <linkto module="Fitting">Fitting</linkto>
57// </prerequisite>
58//
59// <etymology>
60// A set of data point is fit with some functional equation.
61// The class acts as a generic base class for <src>L2</src> type
62// fits.
63// </etymology>
64//
65// <synopsis>
66// NOTE: Constraints added. Documentation out of date at moment, check
67// the tLinearFitSVD and tNonLinearFitLM programs for examples.
68//
69// The class acts as a base class for L2-type (least-squares) fitting.
70// Actual classes (se e.g. <linkto class=LinearFit>LinearFit</linkto> and
71// <linkto class=NonLinearFit>NonLinearFit</linkto>.
72//
73// The following is a brief summary of the linear least-squares fit problem.
74// See module header, <linkto module="Fitting">Fitting</linkto>,
75// for a more complete description.
76//
77// Given a set of N data points (measurements), (x(i), y(i)) i = 0,...,N-1,
78// along with a set of standard deviations, sigma(i), for the data points,
79// and M specified functions, f(j)(x) j = 0,...,M-1, we form a linear
80// combination of the functions:
81// <srcblock>
82// z(i) = a(0)f(0)(x(i)) + a(1)f(1)(x(i)) + ... + a(M-1)f(M-1)(x(i)),
83// </srcblock>
84// where a(j) j = 0,...,M-1 are a set of parameters to be determined.
85// The linear least-squares fit tries to minimize
86// <srcblock>
87// chi-square = [(y(0)-z(0))/sigma(0)]^2 + [(y(1)-z(1))/sigma(1)]^2 + ...
88// + [(y(N-1)-z(N-1))/sigma(N-1)]^2.
89// </srcblock>
90// by adjusting {a(j)} in the equation.
91//
92// For complex numbers, <code>[(y(i)-z(i))/sigma(i)]^2</code> in chi-square
93// is replaced by
94// <code>[(y(i)-z(i))/sigma(i)]*conjugate([(y(i)-z(i))/sigma(i)])</code>
95//
96// For multidimensional functions, x(i) is a vector, and
97// <srcblock>
98// f(j)(x(i)) = f(j)(x(i,0), x(i,1), x(i,2), ...)
99// </srcblock>
100//
101// Normally, it is necessary that N > M for the solutions to be valid, since
102// there must be more data points than model parameters to be solved.
103//
104// If the measurement errors (standard deviation sigma) are not known
105// at all, they can all be set to one initially. In this case, we assume all
106// measurements have the same standard deviation, after minimizing
107// chi-square, we recompute
108// <srcblock>
109// sigma^2 = {(y(0)-z(0))^2 + (y(1)-z(1))^2 + ...
110// + (y(N-1)-z(N-1))^2}/(N-M) = chi-square/(N-M).
111// </srcblock>
112//
113// A statistic weight can also be assigned to each measurement if the
114// standard deviation is not available. sigma can be calculated from
115// <srcblock>
116// sigma = 1/ sqrt(weight)
117// </srcblock>
118// Alternatively a 'weight' switch can be set with <src>asWeight()</src>.
119// For best arithmetic performance, weight should be normalized to a maximum
120// value of one. Having a large weight value can sometimes lead to overflow
121// problems.
122//
123// The function to be fitted to the data can be given as an instance of the
124// <linkto class="Function">Function</linkto> class.
125// One can also form a sum of functions using the
126// <linkto class="CompoundFunction">CompoundFunction</linkto>.
127//
128// For small datasets the usage of the calls is:
129// <ul>
130// <li> Create a functional description of the parameters
131// <li> Create a fitter: GenericL2Fit<T> fitter();
132// <li> Set the functional representation: fitter.setFunction()
133// <li> Do the fit to the data: fitter.fit(x, data, sigma)
134// (or do a number of calls to buildNormalMatrix(x, data, sigma)
135// and finish of with fitter.fit() or fitter.sol())
136// <li> if needed the covariance; residuals; chiSquared, parameter errors
137// can all be obtained
138// </ul>
139// Note that the fitter is reusable. An example is given in the following.
140//
141// The solution of a fit always produces the total number of parameters given
142// to the fitter. I.e. including any parameters that were fixed. In the
143// latter case the solution returned will be the fixed value.
144//
145// <templating arg=T>
146// <li> The following data types can be used to instantiate the GenericL2Fit
147// templated class:
148// Known classes for FunctionTraits. I.e simple numerical like
149// <src>Float</src>, <src>Double</src>, <src>Complex</src>,
150// <src>DComplex</src>; and the <src>AutoDiff<></src> versions.
151// </templating>
152//
153// If there are a large number of unknowns or a large number of data points
154// machine memory limits (or timing reasons) may not allow a complete
155// in-core fitting to be performed. In this case one can incrementally
156// build the normal equation (see buildNormalMatrix()).
157//
158// The normal operation of the class tests for real inversion problems
159// only. If tests are needed for almost collinear columns in the
160// solution matrix, the collinearity can be set as the square of the sine of
161// the minimum angle allowed.
162//
163// Singular Value Decomposition is supported by the
164// <em> asSVD()</em> (which will also set the
165// default collinearity to 1e-8).
166//
167// Other information (see a.o. <linkto class=LSQFit>LSQFit</linkto>) can
168// be set and obtained as well.
169// </synopsis>
170//
171// <motivation>
172// The creation of this class was driven by the need to write code
173// to perform baseline fitting or continuum subtraction.
174// </motivation>
175
176// <example>
177// In the following a polynomial is fitted through the first 20 prime numbers.
178// The data is given in the x vector (1 to 20) and in the primesTable
179// (2, 3, ..., 71) (see tLinearFitSVD test program). In the following
180// all four methods to calculate a polynomial through the data is used
181// <srcblock>
182// // The list of coordinate x-values
183// Vector<Double> x(nPrimes);
184// indgen(x, 1.0); // 1, 2, ...
185// Vector<Double> primesTable(nPrimes);
186// for (uInt i=1; i < nPrimes; i++) {
187// primesTable(i) =
188// Primes::nextLargerPrimeThan(Int(primesTable(i-1)+0.01));
189// }
190// Vector<Double> sigma(nPrimes);
191// sigma = 1.0;
192// // The fitter
193// LinearFit<Double> fitter;
194// // Linear combination of functions describing 1 + x + x*x
195// combination.setCoefficient(0, 1.0); // 1
196// combination.setCoefficient(1, 1.0); // x
197// combination.setCoefficient(2, 1.0); // x^2
198// // Get the solution
199// fitter.setFunction(combination);
200// Vector<Double> solution = fitter.fit(x, primesTable, sigma);
201// // Try with a function with automatic derivatives (note that default
202// // polynomial has zero first guess)
203// LinearFit<AutoDiffA<Double> > fitad;
204// Polynomial<AutoDiffA<Double> > sqre(2);
205// fitad.setFunction(sqre);
206// solution = fitad.fit(x, primesTable, sigma);
207// </srcblock>
208// In the test program examples are given on how to get the other
209// information, and other examples.
210// </example>
211
212template <class T>
213class GenericL2Fit : public LSQaips {
214 public:
215 // # Constants
216 // Default collinearity test for SVD
218
219 // # Constructors
220 // Create a fitter: the normal way to generate a fitter object. Necessary
221 // data will be deduced from the Functional provided with
222 // <src>setFunction()</src>
224 // Copy constructor (deep copy)
226 // Assignment (deep copy)
228
229 // Destructor
230 virtual ~GenericL2Fit();
231
232 // Sets the function to be fitted. Upon entry, the argument function object
233 // is cloned. The cloned copy is used in the later fitting process.
234 // A valid function should be an instance of the
235 // <linkto class="Function">Function</linkto> class,
236 // so that derivatives with respect to the adjustable parameters
237 // can be calculated. The current values of the "available" parameters
238 // of the function are taken as the initial guess for the non-linear fitting.
239 template <class U>
240 void setFunction(const Function<U, U> &function) {
242 ptr_derive_p = function.cloneAD();
244 }
245
246 // Set the possible constraint functions. The <src>addConstraint</src>
247 // will add one; the <src>setConstraint</src> will [re-]set the
248 // <src>n</src>th constraint. If unsucessful, False returned.<br>
249 // Constraint functional can only be set when the function to be fitted
250 // has been set. It should have the same number of parameters as the function
251 // to be fitted. The <src>x</src> should have the correct dimension.
252 // <group>
253 template <class U>
255 const uInt n, const Function<U, U> &function,
256 const Vector<typename FunctionTraits<T>::BaseType> &x,
257 const typename FunctionTraits<T>::BaseType y = typename FunctionTraits<T>::BaseType(0)) {
258 if (n >= constrFun_p.nelements() || !ptr_derive_p ||
259 ptr_derive_p->nparameters() != function.nparameters() || function.ndim() != x.nelements())
260 return False;
261 delete constrFun_p[n];
262 constrFun_p[n] = 0;
263 constrFun_p[n] = function.cloneAD();
264 return setConstraintEx(n, x, y);
265 }
267 const uInt n, const Vector<typename FunctionTraits<T>::BaseType> &x,
268 const typename FunctionTraits<T>::BaseType y = typename FunctionTraits<T>::BaseType(0));
270 typename FunctionTraits<T>::BaseType(0));
273 &function,
274 const Vector<typename FunctionTraits<T>::BaseType> &x,
275 const typename FunctionTraits<T>::BaseType y = typename FunctionTraits<T>::BaseType(0));
277 const Vector<typename FunctionTraits<T>::BaseType> &x,
278 const typename FunctionTraits<T>::BaseType y = typename FunctionTraits<T>::BaseType(0));
280 const typename FunctionTraits<T>::BaseType y = typename FunctionTraits<T>::BaseType(0));
281 // </group>
282 // Set the collinearity factor as the square of the sine of the
283 // minimum angle allowed between input vectors (default zero for non-SVD,
284 // 1e-8 for SVD)
285 void setCollinearity(const Double cln);
286
287 // Set sigma values to be interpreted as weight (i.e. 1/sigma/sigma).
288 // A value of zero or -1 will be skipped. The switch will stay in effect
289 // until set False again explicitly. Default is False.
290 void asWeight(const Bool aswgt) { asweight_p = aswgt; }
291
292 // Set the use of SVD or not (default). When set the default collinearity
293 // is set as well.
294 void asSVD(const Bool svd);
295
296 // Return a pointer to the function being fitted. Should
297 // never delete this pointer.
298 // <group>
301 return ptr_derive_p;
302 }
305 return ptr_derive_p;
306 }
307 // </group>
308 // Return the number of fitted parameters
309 uInt fittedNumber() const { return aCount_ai; }
310
311 // Return the number of constraints, and pointers to constraint functions.
312 // A <src>0-pointer</src> will be returned if no such constraint present.
313 // This pointer should never be destroyed.
314 // <group>
315 uInt NConstraints() { return constrFun_p.nelements(); }
318 return (n >= constrFun_p.nelements() ? 0 : constrFun_p[n]);
319 }
320 // </group>
321
322 // Return the nth constraint equation derived from SVD
323 // Note that the number present will be given by <src>getDeficiency()</src>
325 // Set the parameter values. The input is a vector of parameters; all
326 // or only the masked ones' values will be set, using the input values
327 // <group>
330 // </group>
331
332 // Fit the function to the data. If no sigma provided, all ones assumed.
333 // In the case of no x,y,sigma the fitting equations are supposed to be
334 // generated by previous calls to buildNormalMatrix. Note that the ones
335 // with a scalar sigma will assume sigma=1 (overloading problem). The mask
336 // assumes that if present, points with False will be skipped.
337 // <thrown>
338 // <li> AipsError if unmatched array sizes given
339 // <li> AipsError if equations cannot be inverted (not in SVD case and in
340 // the case of the Bool versions.)
341 // </thrown>
342 // <group>
344 const Vector<typename FunctionTraits<T>::BaseType> &x,
345 const Vector<typename FunctionTraits<T>::BaseType> &y,
346 const Vector<typename FunctionTraits<T>::BaseType> &sigma,
347 const Vector<Bool> *const mask = 0);
349 const Matrix<typename FunctionTraits<T>::BaseType> &x,
350 const Vector<typename FunctionTraits<T>::BaseType> &y,
351 const Vector<typename FunctionTraits<T>::BaseType> &sigma,
352 const Vector<Bool> *const mask = 0);
354 const Vector<typename FunctionTraits<T>::BaseType> &x,
355 const Vector<typename FunctionTraits<T>::BaseType> &y, const Vector<Bool> *const mask = 0);
357 const Matrix<typename FunctionTraits<T>::BaseType> &x,
358 const Vector<typename FunctionTraits<T>::BaseType> &y, const Vector<Bool> *const mask = 0);
361 const Vector<typename FunctionTraits<T>::BaseType> &x,
362 const Vector<typename FunctionTraits<T>::BaseType> &y,
363 const Vector<typename FunctionTraits<T>::BaseType> &sigma,
364 const Vector<Bool> *const mask = 0);
366 const Matrix<typename FunctionTraits<T>::BaseType> &x,
367 const Vector<typename FunctionTraits<T>::BaseType> &y,
368 const Vector<typename FunctionTraits<T>::BaseType> &sigma,
369 const Vector<Bool> *const mask = 0);
371 const Vector<typename FunctionTraits<T>::BaseType> &x,
372 const Vector<typename FunctionTraits<T>::BaseType> &y,
373 const typename FunctionTraits<T>::BaseType &sigma, const Vector<Bool> *const mask = 0);
375 const Matrix<typename FunctionTraits<T>::BaseType> &x,
376 const Vector<typename FunctionTraits<T>::BaseType> &y,
377 const typename FunctionTraits<T>::BaseType &sigma, const Vector<Bool> *const mask = 0);
379 // </group>
380
381 // Obtain the chi squared. It has already been calculated during the
382 // fitting process.
383 // <group>
384 Double chiSquare() const { return getChi(); }
385 // </group>
386
387 // Get the errors on the solved values
388 // <thrown>
389 // <li> AipsError if none present (or Bool returned)
390 // </thrown>
391 // <group>
394 // </group>
395
396 // Get covariance matrix
397 // <group>
400 // </group>
401
402 // Generate the normal equations by one or more calls to the
403 // buildNormalMatrix(), before calling a fit() without arguments.
404 // The arguments are the same as for the fit(arguments) function.
405 // A False is returned if the Array sizes are unmatched.
406 // <group>
408 const Vector<typename FunctionTraits<T>::BaseType> &y,
409 const Vector<typename FunctionTraits<T>::BaseType> &sigma,
410 const Vector<Bool> *const mask = 0);
412 const Vector<typename FunctionTraits<T>::BaseType> &y,
413 const Vector<typename FunctionTraits<T>::BaseType> &sigma,
414 const Vector<Bool> *const mask = 0);
416 const Vector<typename FunctionTraits<T>::BaseType> &y,
417 const Vector<Bool> *const mask = 0);
419 const Vector<typename FunctionTraits<T>::BaseType> &y,
420 const Vector<Bool> *const mask = 0);
421 // </group>
422 // Return the residual after a fit in y. x can
423 // be a vector (if 1D function) or a matrix (ND functional), as in the
424 // fit() methods. If sol is given, it is the solution derived from
425 // a fit and its value will be used; otherwise only the parameters
426 // in the fitted functional will be used.
427 // If <src>model</src> is given as <src>True</src>, the model, rather
428 // the residual <src><data>-<model></src> will be returned in <src>y</src>.
429 // False is returned if residuals cannot be calculated.
430 // <thrown>
431 // <li> Aipserror if illegal array sizes
432 // </thrown>
433 // <group>
435 const Array<typename FunctionTraits<T>::BaseType> &x,
436 const Vector<typename FunctionTraits<T>::BaseType> &sol, const Bool model = False);
438 const Array<typename FunctionTraits<T>::BaseType> &x, const Bool model = False);
439 // </group>
440 // Get the rank of the solution (or zero of no fit() done yet). A
441 // valid solution will have the same rank as the number of unknowns (or
442 // double that number in the complex case). For SVD solutions the
443 // rank could be less.
444 uInt getRank() const { return (solved_p ? nUnknowns() - getDeficiency() : 0); }
445
446 protected:
447 // #Data
448 // Adjustable
450 // SVD indicator
452 // Function to use in evaluating condition equation
455 // List of functions describing the possible constraint equations
456 // e.g. The sum of 3 angles w`could be described by a
457 // <src>HyperPlane(3)</src> function with <src>[1,1,1]</src>
458 // as parameters; giving <src>[1,1,1]</src> as argument vector and
459 // <src>3.1415</src> as value.
460 // <group>
462 constrFun_p;
463 // List of vectors describing the constraint equations' arguments
465 // List of values describing the constraint equations' value
467 // </group>
468 // Number of available parameters
470 // Number of dimensions of input data
472 // No normal equations yet.
474 // Have solution
476 // Have errors
479 // Interpret as weights rather than as sigma the given values.
481 // The rank of the solution
483 // Condition equation parameters (for number of adjustable parameters)
485 // Equation for all available parameters
487 // Contiguous argument areas
488 // <group>
491 // </group>
492 // Local solution area
493 // <group>
496 // </group>
497 // Local error area
498 // <group>
501 // </group>
502 // Local value and derivatives
504 // Local SVD constraints
506 // # Member functions
507 // Generalised fitter
509 const Array<typename FunctionTraits<T>::BaseType> &x,
510 const Vector<typename FunctionTraits<T>::BaseType> &y,
511 const Vector<typename FunctionTraits<T>::BaseType> *const sigma,
512 const Vector<Bool> *const mask = 0) = 0;
513 // Build the normal matrix
515 const Vector<typename FunctionTraits<T>::BaseType> &y,
516 const Vector<typename FunctionTraits<T>::BaseType> *const sigma,
517 const Vector<Bool> *const mask = 0);
518 // Build the constraint equations
520 // Get the SVD constraints
522 // Calculate residuals
524 const Array<typename FunctionTraits<T>::BaseType> &x,
525 const Vector<typename FunctionTraits<T>::BaseType> *const sol,
526 const Bool model = False);
527 // Function to get evaluated functional value
529 const Array<typename FunctionTraits<T>::BaseType> &x, uInt j, uInt i) const;
530 // Initialise the fitter with number of solvable parameters
531 void initfit_p(uInt parcnt);
532 // Return number of condition equations and check sizes x, y, sigma
533 // <thrown>
534 // <li> Aipserror if size inconsistencies
535 // </thrown>
537 const Vector<typename FunctionTraits<T>::BaseType> &y,
538 const Vector<typename FunctionTraits<T>::BaseType> *const sigma);
539 // Reset all the input
541
542 private:
543 // # Data
544
545 // # Member functions
546 // Set function properties
548 // Set Constraint properties
550 const typename FunctionTraits<T>::BaseType y);
551};
552
553} // namespace casacore
554#ifndef CASACORE_NO_AUTO_TEMPLATES
555#include <casacore/scimath/Fitting/GenericL2Fit.tcc>
556#endif // # CASACORE_NO_AUTO_TEMPLATES
557#endif
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.
Definition Function.h:226
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
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).
Block< Vector< typename FunctionTraits< T >::BaseType > * > constrArg_p
List of functions describing the possible constraint equations e.g.
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
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).
Vector< Vector< typename LSQTraits< typename FunctionTraits< T >::BaseType >::base > > consvd_p
Local SVD constraints.
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)
Block< typename FunctionTraits< T >::BaseType * > constrVal_p
List of values describing the constraint equations' value.
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.
Bool svd_p
SVD indicator.
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.
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.
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...
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.
void setMaskedParameterValues(const Vector< typename FunctionTraits< T >::BaseType > &parms)
uInt nUnknowns() const
Get the number of unknowns.
Definition LSQFit.h:715
Double getChi() const
Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation p...
static const String sol
Definition LSQFit.h:802
uInt getDeficiency() const
Get the rank deficiency Warning: Note that the number is returned assuming real values; For complex ...
Definition LSQFit.h:721
LSQaips(uInt nUnknowns, uInt nConstraints=0)
Construct an object with the number of unknown, knowns and constraints, and type, using the default c...
Definition LSQaips.h:89
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53