casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
28 
29 #ifndef SCIMATH_GENERICL2FIT_H
30 #define SCIMATH_GENERICL2FIT_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
42 
43 namespace casacore { // begin namespace casa
44 
45 //# Forward declarations
46 template <class T> class Array;
47 template <class T, class U> class Function;
48 
49 // <summary> Generic base class for least-squares fit.
50 // </summary>
51 //
52 // <reviewed reviewer="wbrouw" date="2004/06/14" tests="tLinearFitSVD.cc"
53 // demos="">
54 // </reviewed>
55 //
56 // <prerequisite>
57 // <li> <linkto class="Function">Function</linkto>
58 // <li> <linkto module="Fitting">Fitting</linkto>
59 // </prerequisite>
60 //
61 // <etymology>
62 // A set of data point is fit with some functional equation.
63 // The class acts as a generic base class for <src>L2</src> type
64 // fits.
65 // </etymology>
66 //
67 // <synopsis>
68 // NOTE: Constraints added. Documentation out of date at moment, check
69 // the tLinearFitSVD and tNonLinearFitLM programs for examples.
70 //
71 // The class acts as a base class for L2-type (least-squares) fitting.
72 // Actual classes (se e.g. <linkto class=LinearFit>LinearFit</linkto> and
73 // <linkto class=NonLinearFit>NonLinearFit</linkto>.
74 //
75 // The following is a brief summary of the linear least-squares fit problem.
76 // See module header, <linkto module="Fitting">Fitting</linkto>,
77 // for a more complete description.
78 //
79 // Given a set of N data points (measurements), (x(i), y(i)) i = 0,...,N-1,
80 // along with a set of standard deviations, sigma(i), for the data points,
81 // and M specified functions, f(j)(x) j = 0,...,M-1, we form a linear
82 // combination of the functions:
83 // <srcblock>
84 // z(i) = a(0)f(0)(x(i)) + a(1)f(1)(x(i)) + ... + a(M-1)f(M-1)(x(i)),
85 // </srcblock>
86 // where a(j) j = 0,...,M-1 are a set of parameters to be determined.
87 // The linear least-squares fit tries to minimize
88 // <srcblock>
89 // chi-square = [(y(0)-z(0))/sigma(0)]^2 + [(y(1)-z(1))/sigma(1)]^2 + ...
90 // + [(y(N-1)-z(N-1))/sigma(N-1)]^2.
91 // </srcblock>
92 // by adjusting {a(j)} in the equation.
93 //
94 // For complex numbers, <code>[(y(i)-z(i))/sigma(i)]^2</code> in chi-square
95 // is replaced by
96 // <code>[(y(i)-z(i))/sigma(i)]*conjugate([(y(i)-z(i))/sigma(i)])</code>
97 //
98 // For multidimensional functions, x(i) is a vector, and
99 // <srcblock>
100 // f(j)(x(i)) = f(j)(x(i,0), x(i,1), x(i,2), ...)
101 // </srcblock>
102 //
103 // Normally, it is necessary that N > M for the solutions to be valid, since
104 // there must be more data points than model parameters to be solved.
105 //
106 // If the measurement errors (standard deviation sigma) are not known
107 // at all, they can all be set to one initially. In this case, we assume all
108 // measurements have the same standard deviation, after minimizing
109 // chi-square, we recompute
110 // <srcblock>
111 // sigma^2 = {(y(0)-z(0))^2 + (y(1)-z(1))^2 + ...
112 // + (y(N-1)-z(N-1))^2}/(N-M) = chi-square/(N-M).
113 // </srcblock>
114 //
115 // A statistic weight can also be assigned to each measurement if the
116 // standard deviation is not available. sigma can be calculated from
117 // <srcblock>
118 // sigma = 1/ sqrt(weight)
119 // </srcblock>
120 // Alternatively a 'weight' switch can be set with <src>asWeight()</src>.
121 // For best arithmetic performance, weight should be normalized to a maximum
122 // value of one. Having a large weight value can sometimes lead to overflow
123 // problems.
124 //
125 // The function to be fitted to the data can be given as an instance of the
126 // <linkto class="Function">Function</linkto> class.
127 // One can also form a sum of functions using the
128 // <linkto class="CompoundFunction">CompoundFunction</linkto>.
129 //
130 // For small datasets the usage of the calls is:
131 // <ul>
132 // <li> Create a functional description of the parameters
133 // <li> Create a fitter: GenericL2Fit<T> fitter();
134 // <li> Set the functional representation: fitter.setFunction()
135 // <li> Do the fit to the data: fitter.fit(x, data, sigma)
136 // (or do a number of calls to buildNormalMatrix(x, data, sigma)
137 // and finish of with fitter.fit() or fitter.sol())
138 // <li> if needed the covariance; residuals; chiSquared, parameter errors
139 // can all be obtained
140 // </ul>
141 // Note that the fitter is reusable. An example is given in the following.
142 //
143 // The solution of a fit always produces the total number of parameters given
144 // to the fitter. I.e. including any parameters that were fixed. In the
145 // latter case the solution returned will be the fixed value.
146 //
147 // <templating arg=T>
148 // <li> The following data types can be used to instantiate the GenericL2Fit
149 // templated class:
150 // Known classes for FunctionTraits. I.e simple numerical like
151 // <src>Float</src>, <src>Double</src>, <src>Complex</src>,
152 // <src>DComplex</src>; and the <src>AutoDiff<></src> versions.
153 // </templating>
154 //
155 // If there are a large number of unknowns or a large number of data points
156 // machine memory limits (or timing reasons) may not allow a complete
157 // in-core fitting to be performed. In this case one can incrementally
158 // build the normal equation (see buildNormalMatrix()).
159 //
160 // The normal operation of the class tests for real inversion problems
161 // only. If tests are needed for almost collinear columns in the
162 // solution matrix, the collinearity can be set as the square of the sine of
163 // the minimum angle allowed.
164 //
165 // Singular Value Decomposition is supported by the
166 // <em> asSVD()</em> (which will also set the
167 // default collinearity to 1e-8).
168 //
169 // Other information (see a.o. <linkto class=LSQFit>LSQFit</linkto>) can
170 // be set and obtained as well.
171 // </synopsis>
172 //
173 // <motivation>
174 // The creation of this class was driven by the need to write code
175 // to perform baseline fitting or continuum subtraction.
176 // </motivation>
177 
178 // <example>
179 // In the following a polynomial is fitted through the first 20 prime numbers.
180 // The data is given in the x vector (1 to 20) and in the primesTable
181 // (2, 3, ..., 71) (see tLinearFitSVD test program). In the following
182 // all four methods to calculate a polynomial through the data is used
183 // <srcblock>
184 // // The list of coordinate x-values
185 // Vector<Double> x(nPrimes);
186 // indgen(x, 1.0); // 1, 2, ...
187 // Vector<Double> primesTable(nPrimes);
188 // for (uInt i=1; i < nPrimes; i++) {
189 // primesTable(i) =
190 // Primes::nextLargerPrimeThan(Int(primesTable(i-1)+0.01));
191 // }
192 // Vector<Double> sigma(nPrimes);
193 // sigma = 1.0;
194 // // The fitter
195 // LinearFit<Double> fitter;
196 // // Linear combination of functions describing 1 + x + x*x
197 // combination.setCoefficient(0, 1.0); // 1
198 // combination.setCoefficient(1, 1.0); // x
199 // combination.setCoefficient(2, 1.0); // x^2
200 // // Get the solution
201 // fitter.setFunction(combination);
202 // Vector<Double> solution = fitter.fit(x, primesTable, sigma);
203 // // Try with a function with automatic derivatives (note that default
204 // // polynomial has zero first guess)
205 // LinearFit<AutoDiffA<Double> > fitad;
206 // Polynomial<AutoDiffA<Double> > sqre(2);
207 // fitad.setFunction(sqre);
208 // solution = fitad.fit(x, primesTable, sigma);
209 // </srcblock>
210 // In the test program examples are given on how to get the other
211 // information, and other examples.
212 // </example>
213 
214 template<class T> class GenericL2Fit : public LSQaips {
215  public:
216  //# Constants
217  // Default collinearity test for SVD
219 
220  //# Constructors
221  // Create a fitter: the normal way to generate a fitter object. Necessary
222  // data will be deduced from the Functional provided with
223  // <src>setFunction()</src>
224  GenericL2Fit();
225  // Copy constructor (deep copy)
226  GenericL2Fit(const GenericL2Fit &other);
227  // Assignment (deep copy)
228  GenericL2Fit &operator=(const GenericL2Fit &other);
229 
230  // Destructor
231  virtual ~GenericL2Fit();
232 
233  // Sets the function to be fitted. Upon entry, the argument function object
234  // is cloned. The cloned copy is used in the later fitting process.
235  // A valid function should be an instance of the
236  // <linkto class="Function">Function</linkto> class,
237  // so that derivatives with respect to the adjustable parameters
238  // can be calculated. The current values of the "available" parameters
239  // of the function are taken as the initial guess for the non-linear fitting.
240  template <class U>
241  void setFunction(const Function<U,U> &function) { resetFunction();
242  ptr_derive_p = function.cloneAD(); setFunctionEx(); }
243 
244  // Set the possible constraint functions. The <src>addConstraint</src>
245  // will add one; the <src>setConstraint</src> will [re-]set the
246  // <src>n</src>th constraint. If unsucessful, False returned.<br>
247  // Constraint functional can only be set when the function to be fitted
248  // has been set. It should have the same number of parameters as the function
249  // to be fitted. The <src>x</src> should have the correct dimension.
250  // <group>
251  template <class U>
253  const Function<U,U> &function,
254  const Vector<typename FunctionTraits<T>::BaseType> &x,
255  const typename FunctionTraits<T>::BaseType y=
256  typename FunctionTraits<T>::BaseType(0)) {
257  if (n >= constrFun_p.nelements() ||
258  !ptr_derive_p ||
259  ptr_derive_p->nparameters() != function.nparameters() ||
260  function.ndim() != x.nelements()) return False;
261  delete constrFun_p[n]; constrFun_p[n] = 0;
262  constrFun_p[n] = function.cloneAD(); return setConstraintEx(n, x, y); }
263  Bool setConstraint(const uInt n,
264  const Vector<typename FunctionTraits<T>::BaseType> &x,
265  const typename FunctionTraits<T>::BaseType y=
266  typename FunctionTraits<T>::BaseType(0));
267  Bool setConstraint(const uInt n,
268  const typename FunctionTraits<T>::BaseType y=
269  typename FunctionTraits<T>::BaseType(0));
271  typename FunctionTraits<T>::DiffType> &function,
272  const Vector<typename FunctionTraits<T>::BaseType> &x,
273  const typename FunctionTraits<T>::BaseType y=
274  typename FunctionTraits<T>::BaseType(0));
276  const typename FunctionTraits<T>::BaseType y=
277  typename FunctionTraits<T>::BaseType(0));
279  typename FunctionTraits<T>::BaseType(0));
280  // </group>
281  // Set the collinearity factor as the square of the sine of the
282  // minimum angle allowed between input vectors (default zero for non-SVD,
283  // 1e-8 for SVD)
284  void setCollinearity(const Double cln);
285 
286  // Set sigma values to be interpreted as weight (i.e. 1/sigma/sigma).
287  // A value of zero or -1 will be skipped. The switch will stay in effect
288  // until set False again explicitly. Default is False.
289  void asWeight(const Bool aswgt) { asweight_p = aswgt; }
290 
291  // Set the use of SVD or not (default). When set the default collinearity
292  // is set as well.
293  void asSVD(const Bool svd);
294 
295  // Return a pointer to the function being fitted. Should
296  // never delete this pointer.
297  // <group>
300  return ptr_derive_p; }
302  typename FunctionTraits<T>::DiffType>*
303  fittedFunction() const { return ptr_derive_p; }
304  // </group>
305  // Return the number of fitted parameters
306  uInt fittedNumber() const { return aCount_ai; }
307 
308  // Return the number of constraints, and pointers to constraint functions.
309  // A <src>0-pointer</src> will be returned if no such constraint present.
310  // This pointer should never be destroyed.
311  // <group>
312  uInt NConstraints() { return constrFun_p.nelements(); }
315  return (n >= constrFun_p.nelements() ? 0 : constrFun_p[n]); }
316  // </group>
317 
318  // Return the nth constraint equation derived from SVD
319  // Note that the number present will be given by <src>getDeficiency()</src>
321  BaseType>::base> getSVDConstraint(uInt n);
322  // Set the parameter values. The input is a vector of parameters; all
323  // or only the masked ones' values will be set, using the input values
324  // <group>
325  void setParameterValues
326  (const Vector<typename FunctionTraits<T>::BaseType> &parms);
328  (const Vector<typename FunctionTraits<T>::BaseType> &parms);
329  // </group>
330 
331  // Fit the function to the data. If no sigma provided, all ones assumed.
332  // In the case of no x,y,sigma the fitting equations are supposed to be
333  // generated by previous calls to buildNormalMatrix. Note that the ones
334  // with a scalar sigma will assume sigma=1 (overloading problem). The mask
335  // assumes that if present, points with False will be skipped.
336  // <thrown>
337  // <li> AipsError if unmatched array sizes given
338  // <li> AipsError if equations cannot be inverted (not in SVD case and in
339  // the case of the Bool versions.)
340  // </thrown>
341  // <group>
343  fit(const Vector<typename FunctionTraits<T>::BaseType> &x,
344  const Vector<typename FunctionTraits<T>::BaseType> &y,
345  const Vector<typename FunctionTraits<T>::BaseType> &sigma,
346  const Vector<Bool> *const mask=0);
348  fit(const Matrix<typename FunctionTraits<T>::BaseType> &x,
349  const Vector<typename FunctionTraits<T>::BaseType> &y,
350  const Vector<typename FunctionTraits<T>::BaseType> &sigma,
351  const Vector<Bool> *const mask=0);
353  fit(const Vector<typename FunctionTraits<T>::BaseType> &x,
354  const Vector<typename FunctionTraits<T>::BaseType> &y,
355  const Vector<Bool> *const mask=0);
357  fit(const Matrix<typename FunctionTraits<T>::BaseType> &x,
358  const Vector<typename FunctionTraits<T>::BaseType> &y,
359  const Vector<Bool> *const mask=0);
361  fit(const Vector<Bool> *const mask=0);
363  const Vector<typename FunctionTraits<T>::BaseType> &x,
364  const Vector<typename FunctionTraits<T>::BaseType> &y,
365  const Vector<typename FunctionTraits<T>::BaseType> &sigma,
366  const Vector<Bool> *const mask=0);
368  const Matrix<typename FunctionTraits<T>::BaseType> &x,
369  const Vector<typename FunctionTraits<T>::BaseType> &y,
370  const Vector<typename FunctionTraits<T>::BaseType> &sigma,
371  const Vector<Bool> *const mask=0);
373  const Vector<typename FunctionTraits<T>::BaseType> &x,
374  const Vector<typename FunctionTraits<T>::BaseType> &y,
375  const typename FunctionTraits<T>::BaseType &sigma,
376  const Vector<Bool> *const mask=0);
378  const Matrix<typename FunctionTraits<T>::BaseType> &x,
379  const Vector<typename FunctionTraits<T>::BaseType> &y,
380  const typename FunctionTraits<T>::BaseType &sigma,
381  const Vector<Bool> *const mask=0);
383  const Vector<Bool> *const mask=0);
384  // </group>
385 
386  // Obtain the chi squared. It has already been calculated during the
387  // fitting process.
388  // <group>
389  Double chiSquare() const { return getChi(); }
390  // </group>
391 
392  // Get the errors on the solved values
393  // <thrown>
394  // <li> AipsError if none present (or Bool returned)
395  // </thrown>
396  // <group>
398  Bool errors(Vector<typename FunctionTraits<T>::BaseType> &err) const;
399  // </group>
400 
401  // Get covariance matrix
402  // <group>
404  void compuCovariance(Matrix<Double> &cov);
405  // </group>
406 
407  // Generate the normal equations by one or more calls to the
408  // buildNormalMatrix(), before calling a fit() without arguments.
409  // The arguments are the same as for the fit(arguments) function.
410  // A False is returned if the Array sizes are unmatched.
411  // <group>
412  void buildNormalMatrix
413  (const Vector<typename FunctionTraits<T>::BaseType> &x,
414  const Vector<typename FunctionTraits<T>::BaseType> &y,
415  const Vector<typename FunctionTraits<T>::BaseType> &sigma,
416  const Vector<Bool> *const mask=0);
417  void buildNormalMatrix
418  (const Matrix<typename FunctionTraits<T>::BaseType> &x,
419  const Vector<typename FunctionTraits<T>::BaseType> &y,
420  const Vector<typename FunctionTraits<T>::BaseType> &sigma,
421  const Vector<Bool> *const mask=0);
422  void buildNormalMatrix
423  (const Vector<typename FunctionTraits<T>::BaseType> &x,
424  const Vector<typename FunctionTraits<T>::BaseType> &y,
425  const Vector<Bool> *const mask=0);
426  void buildNormalMatrix
427  (const Matrix<typename FunctionTraits<T>::BaseType> &x,
428  const Vector<typename FunctionTraits<T>::BaseType> &y,
429  const Vector<Bool> *const mask=0);
430  // </group>
431  // Return the residual after a fit in y. x can
432  // be a vector (if 1D function) or a matrix (ND functional), as in the
433  // fit() methods. If sol is given, it is the solution derived from
434  // a fit and its value will be used; otherwise only the parameters
435  // in the fitted functional will be used.
436  // If <src>model</src> is given as <src>True</src>, the model, rather
437  // the residual <src><data>-<model></src> will be returned in <src>y</src>.
438  // False is returned if residuals cannot be calculated.
439  // <thrown>
440  // <li> Aipserror if illegal array sizes
441  // </thrown>
442  // <group>
444  const Array<typename FunctionTraits<T>::BaseType> &x,
445  const Vector<typename FunctionTraits<T>::BaseType> &sol,
446  const Bool model=False);
448  const Array<typename FunctionTraits<T>::BaseType> &x,
449  const Bool model=False);
450  // </group>
451  // Get the rank of the solution (or zero of no fit() done yet). A
452  // valid solution will have the same rank as the number of unknowns (or
453  // double that number in the complex case). For SVD solutions the
454  // rank could be less.
455  uInt getRank() const {
456  return (solved_p ? nUnknowns()-getDeficiency() : 0); }
457 
458  protected:
459  //#Data
460  // Adjustable
462  // SVD indicator
464  // Function to use in evaluating condition equation
467  // List of functions describing the possible constraint equations
468  // e.g. The sum of 3 angles w`could be described by a
469  // <src>HyperPlane(3)</src> function with <src>[1,1,1]</src>
470  // as parameters; giving <src>[1,1,1]</src> as argument vector and
471  // <src>3.1415</src> as value.
472  // <group>
475  // List of vectors describing the constraint equations' arguments
477  // List of values describing the constraint equations' value
479  // </group>
480  // Number of available parameters
482  // Number of dimensions of input data
484  // No normal equations yet.
486  // Have solution
488  // Have errors
490  mutable Bool ferrors_p;
491  // Interpret as weights rather than as sigma the given values.
493  // The rank of the solution
495  // Condition equation parameters (for number of adjustable parameters)
497  // Equation for all available parameters
499  // Contiguous argument areas
500  // <group>
503  // </group>
504  // Local solution area
505  // <group>
508  // </group>
509  // Local error area
510  // <group>
513  // </group>
514  // Local value and derivatives
516  // Local SVD constraints
518  BaseType>::base> > consvd_p;
519  //# Member functions
520  // Generalised fitter
521  virtual Bool fitIt
523  const Array<typename FunctionTraits<T>::BaseType> &x,
524  const Vector<typename FunctionTraits<T>::BaseType> &y,
525  const Vector<typename FunctionTraits<T>::BaseType> *const sigma,
526  const Vector<Bool> *const mask=0) = 0;
527  // Build the normal matrix
528  void buildMatrix(const Array<typename FunctionTraits<T>::BaseType> &x,
529  const Vector<typename FunctionTraits<T>::BaseType> &y,
530  const Vector<typename FunctionTraits<T>::BaseType>
531  *const sigma,
532  const Vector<Bool> *const mask=0);
533  // Build the constraint equations
534  void buildConstraint();
535  // Get the SVD constraints
536  void fillSVDConstraints();
537  // Calculate residuals
539  const Array<typename FunctionTraits<T>::BaseType> &x,
540  const Vector<typename FunctionTraits<T>::BaseType>
541  *const sol, const Bool model=False);
542  // Function to get evaluated functional value
544  getVal_p(const Array<typename FunctionTraits<T>::BaseType> &x,
545  uInt j, uInt i) const;
546  // Initialise the fitter with number of solvable parameters
547  void initfit_p(uInt parcnt);
548  // Return number of condition equations and check sizes x, y, sigma
549  // <thrown>
550  // <li> Aipserror if size inconsistencies
551  // </thrown>
553  (const Array<typename FunctionTraits<T>::BaseType> &x,
554  const Vector<typename FunctionTraits<T>::BaseType> &y,
555  const Vector<typename FunctionTraits<T>::BaseType> *const sigma);
556  // Reset all the input
557  void resetFunction();
558 
559  private:
560  //# Data
561 
562  //# Member functions
563  // Set function properties
564  void setFunctionEx();
565  // Set Constraint properties
566  Bool setConstraintEx(const uInt n,
567  const Vector<typename FunctionTraits<T>::BaseType> &x,
568  const typename FunctionTraits<T>::BaseType y);
569 };
570 
571 } //# End namespace casacore
572 #ifndef CASACORE_NO_AUTO_TEMPLATES
573 #include <casacore/scimath/Fitting/GenericL2Fit.tcc>
574 #endif //# CASACORE_NO_AUTO_TEMPLATES
575 #endif
void setMaskedParameterValues(const Vector< typename FunctionTraits< T >::BaseType > &parms)
GenericL2Fit & operator=(const GenericL2Fit &other)
Assignment (deep copy)
FunctionTraits< T >::DiffType valder_p
Local value and derivatives.
Definition: GenericL2Fit.h:515
A 1-D Specialization of the Array class.
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.
Vector< typename FunctionTraits< T >::BaseType > err_p
Local error area.
Definition: GenericL2Fit.h:511
void setParameterValues(const Vector< typename FunctionTraits< T >::BaseType > &parms)
Set the parameter values.
virtual ~GenericL2Fit()
Destructor.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
GenericL2Fit()
Create a fitter: the normal way to generate a fitter object.
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 aCount_ai
Adjustable.
Definition: GenericL2Fit.h:461
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 > fsol_p
Definition: GenericL2Fit.h:507
Bool asweight_p
Interpret as weights rather than as sigma the given values.
Definition: GenericL2Fit.h:492
PtrBlock< Vector< typename FunctionTraits< T >::BaseType > * > constrArg_p
List of vectors describing the constraint equations&#39; arguments.
Definition: GenericL2Fit.h:476
T BaseType
Template base type.
Vector< typename FunctionTraits< T >::BaseType > ferr_p
Definition: GenericL2Fit.h:512
uInt NConstraints()
Return the number of constraints, and pointers to constraint functions.
Definition: GenericL2Fit.h:312
uInt nUnknowns() const
Get the number of unknowns.
Definition: LSQFit.h:769
Bool svd_p
SVD indicator.
Definition: GenericL2Fit.h:463
uInt pCount_p
Number of available parameters.
Definition: GenericL2Fit.h:481
FunctionTraits< T >::BaseType getVal_p(const Array< typename FunctionTraits< T >::BaseType > &x, uInt j, uInt i) const
Function to get evaluated functional value.
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.
A 2-D Specialization of the Array class.
void resetFunction()
Reset all the input.
Vector< typename FunctionTraits< T >::BaseType > sol_p
Local solution area.
Definition: GenericL2Fit.h:506
PtrBlock< typename FunctionTraits< T >::BaseType * > constrVal_p
List of values describing the constraint equations&#39; value.
Definition: GenericL2Fit.h:478
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 solved_p
Have solution.
Definition: GenericL2Fit.h:487
Matrix< Double > compuCovariance()
Get covariance matrix.
Double chiSquare() const
Obtain the chi squared.
Definition: GenericL2Fit.h:389
Vector< typename FunctionTraits< T >::BaseType > fullEq_p
Equation for all available parameters.
Definition: GenericL2Fit.h:498
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * ptr_derive_p
Function to use in evaluating condition equation.
Definition: GenericL2Fit.h:466
Vector< typename FunctionTraits< T >::ArgType > carg_p
Definition: GenericL2Fit.h:502
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.
Numerical functional interface class.
const Double COLLINEARITY
Default collinearity test for SVD.
Definition: GenericL2Fit.h:218
double Double
Definition: aipstype.h:55
uInt ndim_p
Number of dimensions of input data.
Definition: GenericL2Fit.h:483
Vector< typename FunctionTraits< T >::BaseType > condEq_p
Condition equation parameters (for number of adjustable parameters)
Definition: GenericL2Fit.h:496
uInt fittedNumber() const
Return the number of fitted parameters.
Definition: GenericL2Fit.h:306
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.
Generic base class for least-squares fit.
Definition: FittingProxy.h:39
Bool needInit_p
No normal equations yet.
Definition: GenericL2Fit.h:485
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 Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * fittedFunction()
Return a pointer to the function being fitted.
Definition: GenericL2Fit.h:299
PtrBlock< Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * > constrFun_p
List of functions describing the possible constraint equations e.g.
Definition: GenericL2Fit.h:474
const Bool False
Definition: aipstype.h:44
A drop-in replacement for Block&lt;T*&gt;.
Definition: WProjectFT.h:54
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
Bool errors_p
Have errors.
Definition: GenericL2Fit.h:489
void asWeight(const Bool aswgt)
Set sigma values to be interpreted as weight (i.e.
Definition: GenericL2Fit.h:289
const Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * fittedFunction() const
Definition: GenericL2Fit.h:303
static const String sol
Definition: LSQFit.h:857
uInt getRank() const
Get the rank of the solution (or zero of no fit() done yet).
Definition: GenericL2Fit.h:455
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 >::ArgType > arg_p
Contiguous argument areas.
Definition: GenericL2Fit.h:501
Double getChi() const
Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation p...
void initfit_p(uInt parcnt)
Initialise the fitter with number of solvable parameters.
const Vector< typename FunctionTraits< T >::BaseType > & errors() const
Get the errors on the solved values.
uInt getDeficiency() const
Get the rank deficiency Warning: Note that the number is returned assuming real values; For complex ...
Definition: LSQFit.h:775
void setFunction(const Function< U, U > &function)
Sets the function to be fitted.
Definition: GenericL2Fit.h:241
void asSVD(const Bool svd)
Set the use of SVD or not (default).
uInt nr_p
The rank of the solution.
Definition: GenericL2Fit.h:494
void buildConstraint()
Build the constraint equations.
Bool setConstraintEx(const uInt n, const Vector< typename FunctionTraits< T >::BaseType > &x, const typename FunctionTraits< T >::BaseType y)
Set Constraint properties.
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.
Function< typename FunctionTraits< T >::DiffType, typename FunctionTraits< T >::DiffType > * getConstraint(const uInt n)
Definition: GenericL2Fit.h:314
unsigned int uInt
Definition: aipstype.h:51
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.
Definition: GenericL2Fit.h:252
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
Vector< Vector< typename LSQTraits< typename FunctionTraits< T >::BaseType >::base > > consvd_p
Local SVD constraints.
Definition: GenericL2Fit.h:518