casacore
Loading...
Searching...
No Matches
LSQFit.h
Go to the documentation of this file.
1//# LSQFit.h: Basic class for least squares fitting
2//# Copyright (C) 1999-2001,2004-2008
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef SCIMATH_LSQFIT_H
27#define SCIMATH_LSQFIT_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Utilities/RecordTransformable.h>
32#include <casacore/scimath/Fitting/LSQMatrix.h>
33#include <casacore/scimath/Fitting/LSQTraits.h>
34#include <complex>
35#include <string>
36#include <utility>
37#include <vector>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41//# Forward Declarations
42
43// <summary> Basic class for the least squares fitting </summary>
44// <reviewed reviewer="Neil Killeen" date="2000/06/01" tests="tLSQFit"
45// demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> Some knowledge of Matrix operations
50// <li> The background information provided in
51// <a href="../notes/224.html">Note 224</a>.
52// <li> <linkto module="Fitting">Fitting module</linkto>
53// </prerequisite>
54//
55// <etymology>
56// From Least SQuares and Fitting
57// </etymology>
58//
59// <synopsis>
60// The LSQFit class contains the basic functions to do all the fitting
61// described in the
62// <a href="../notes/224.html">Note</a>
63// about fitting.
64// It handles real, and complex equations;<br>
65// linear and non-linear (Levenberg-Marquardt) solutions;<br>
66// regular (with optional constraints) or Singular Value Decomposition
67// (<src>SVD</src>).<br>
68// In essence they are a set of routines to generate normal equations
69// (<src>makeNorm()</src>) in triangular form from a set of condition
70// equations;<br>
71// to do a Cholesky-type decomposition of the normal
72// equations (either regular or <src>SVD</src>) and test its rank
73// (<src>invert()</src>);<br>
74// to do a quasi inversion of the decomposed equations (<src>solve()</src>) to
75// obtain the solution and/or the errors.
76//
77// All calculations are done in place.
78// Methods to obtain additional information about the fitting process are
79// available.
80//
81// This class can be used as a stand-alone class outside of the Casacore
82// environment. In that case the aips.h include file
83// can be replaced if necessary by appropriate typedefs for Double, Float and
84// uInt.<br>
85// The interface to the methods have standard data or standard STL iterator
86// arguments only. They can be used with any container having an STL
87// random-access iterator interface. Especially they can be used with
88// <src>carrays</src> (necessary templates provided),
89// Casacore Vectors (necessary templates
90// provided in <src>LSQaips</src>),
91// standard random access STL containers (like <src>std::vector</src>).
92//
93// The normal operation of the class consists of the following steps:
94// <ul>
95// <li> Create an LSQFit object.
96// The information that can be provided in the constructor of the object,
97// either directly, or indirectly using the <src>set()</src> commands, is
98// (see <a href="../notes/224.html">Note 224</a>):
99// <ul>
100// <li> The number of unknowns that have to be solved for (mandatory)
101// <li> The number of constraint equations you want to use explicitly
102// (defaults to 0, but can be changed on-the-fly)
103// </ul>
104// Separately settable are:
105// <ul>
106// <li> A collinearity test factor (defaults to 1e-8)
107// <note role=warning>
108// The collinearity factor is the square of the sine of the angle between
109// a column in the normal equations, and the hyper-plane through
110// all the other columns. In special cases (e.g. fitting a polynomial
111// in a very narrow bandwidth window, it could be advisable to set this
112// factor to zero if you want a solution (whatever the truth of it maybe).
113// </note>
114// <li> A Levenberg-Marquardt adjustment factor (if appropriate,
115// defaults to 1e-3)
116// </ul>
117//
118// <li>Create the normal equations used in solving the set of condition
119// equations of the user, by using the <src>makeNorm()</src> methods.
120// Separate <src>makenorm()</src> methods are provided for sparse condition
121// equations (e.g. if data for 3 antennas are provided, rather than for all 64)
122//
123// <li>If there are user provided constraints, either limiting constraints like
124// the sum of the angles in a triangle is 180 degrees, or constraints to add
125// missing information if e.g. only differences between parameters have been
126// measured, they can be added to the normal
127// equations with the <src>setConstraint()</src> or
128// the <src>addConstraint()</src> methods. Lagrange multipliers will be used to
129// solve the extended normal equations.
130//
131// <li>The normal equations are triangu;arised (using the collinearity factor
132// as a check for solvability) with the <src>invert()</src> method. If the
133// normal equations are non-solvable an error is returned, or a switch to
134// an SVD solution is made if indicated in the <src>invert</src> call.
135//
136// <li>The solutions and adjustment errors are obtained with the
137// <src>solve()</src> method.
138// A non-linear loop in a Levenberg-Marquardt adjustment can be obtained
139// (together with convergence information), with the <src>solveLoop()</src>
140// method (see below) replacing the combination of
141// <src>invert</src> and <src>solve</src>.
142//
143// <li>Non-linear loops are done by looping through the data using
144// <src>makeNorm()</src> calls, and upgrade the solution with the
145// <src>solveLoop()</src> method.
146// The normal equations are upgraded by changing LM factors. Upgrade depends
147// on the 'balanced' factor. The LM factor is either added in some way to all
148// diagonal elements (if balanced) or all diagonal elements are multiplied by
149// <src>(1+factor)</src> After each loop convergence can be tested
150// by the <src>isReady()</src> call; which will return <src>False</src> or
151// a non-zero code indicating the ready reason. Reasons for stopping can be:
152// <ul>
153// <li> SOLINCREMENT: the relative change in the norm of the parameter
154// solutions is less than
155// (a settable, <src>setEpsValue()</src>, default 1e-8) value.
156// <li> DERIVLEVEL: the inf-norm of the known vector of the equations to be
157// solved is less than the settable, <src>setEpsDerivative()</src>, default
158// 1e-8, value.
159// <li> MAXITER: maximum number of iterations reached (only possible if a
160// number is explicitly set)
161// <li> NOREDUCTION: if the Levenberg-Marquardt correction factor goes towards
162// infinity. I.e. if no Chi2 improvement seems possible. Have to redo the
163// solution with a different start condition for the unknowns.
164// <li> SINGULAR: can only happen due to numeric rounding, since the LM
165// equations are always positive-definite. Best solution is to indicate SVD
166// needed in the <src>solveLoop</src> call, which is cost-free
167// </ul>
168//
169// <li>Covariance information in various forms can be obtained with the
170// <src>getCovariance(), getErrors()</src>, <src>getChi()</src>
171// (or <src>getChi2</src>), <src>getSD</src> and <src>getWeightedSD</src>
172// methods after a <src>solve()</src> or after the final loop in a non-linear
173// solution (of course, when necessary only).
174// </ul>
175//
176// An LSQFit object can be re-used by issuing the <src>reset()</src> command,
177// or <src>set()</src> of new
178// values. If an unknown has not been used in the condition equations at all,
179// the <src>doDiagonal()</src> will make sure a proper solution is obtained,
180// with missing unknowns zeroed.
181//
182// Most of the calculations are done in place; however, enough data is saved
183// that it is possible to continue
184// with the same (partial) normal equations after e.g. an interim solution.
185//
186// If the normal equations are produced in separate partial sets (e.g.
187// in a multi-processor environment) a <src>merge()</src> method can combine
188// them.
189// <note role=tip>
190// It is suggested to add any possible constraint equations after the merge.
191// </note>
192//
193// A <src>debugIt()</src> method provides read access to all internal
194// information.
195//
196// The member definitions are split over three files. The second
197// one contains the templated member function definitions, to bypass the
198// problem of duplicate definitions of non-templated members when
199// pre-compiling them. The third contains methods for saving objects as
200// Records or through AipsIO.
201//
202// <note role=warning> No boundary checks on input and output containers
203// is done for faster execution. In general these tests should be done at
204// the higher level routines, like the
205// <linkto class=LinearFit>LinearFit</linkto> and
206// <linkto class=NonLinearFitLM>NonLinearFit</linkto> classes which should be
207// checked for usage of LSQFit.
208// </note>
209//
210// The contents can be saved in a record (<src>toRecord</src>),
211// and an object can be created from a record (<src>fromRecord</src>).
212// The record identifier is 'lfit'.
213// <br>The object can also be saved or restored using AipsIO.
214// </synopsis>
215//
216// <example>
217// See the tLSQFit.cc and tLSQaips.cc program for extensive examples.
218//
219// The following example will first create 2 condition equations for
220// 3 unknowns (the third is degenerate). It will first create normal equations
221// for a 2 unknown solution and solve; then it will create normal equations
222// for a 3 unknown solution, and solve (note that the degenerate will be
223// set to 0. The last one will use SVD and one condition equation.r
224// <srcblock>
225// #include <casacore/casa/aips.h>
226// #include <casacore/scimath/Fitting/LSQFit.h>
227// #include <iostream>
228//
229// int main() {
230// // Condition equations for x+y=2; x-y=4;
231// Double ce[2][3] = {{1, 1, 0}, {1, -1, 0}};
232// Double m[2] = {2, 4};
233// // Solution and error area
234// Double sol[3];
235// Double sd, mu;
236// uInt rank;
237// Bool ok;
238//
239// // LSQ object
240// LSQFit fit(2);
241//
242// // Make normal equation
243// for (uInt i=0; i<2; i++) fit.makeNorm(ce[i], 1.0, m[i]);
244// // Invert(decompose) and show
245// ok = fit.invert(rank);
246// cout << "ok? " << ok << "; rank: " << rank << endl;
247// // Solve and show
248// if (ok) {
249// fit.solve(sol, &sd, &mu);
250// for (uInt i=0; i<2; i++) cout << "Sol" << i << ": " << sol[i] << endl;
251// cout << "sd: "<< sd << "; mu: " << mu << endl;
252// };
253// cout << "----------" << endl;
254//
255// // Retry with 3 unknowns: note auto fill of unmentioned one
256// fit.set(uInt(3));
257// for (uInt i=0; i<2; i++) fit.makeNorm(ce[i], 1.0, m[i]);
258// ok = fit.invert(rank);
259// cout << "ok? " << ok << "; rank: " << rank << endl;
260// if (ok) {
261// fit.solve(sol, &sd, &mu);
262// for (uInt i=0; i<3; i++) cout << "Sol" << i << ": " << sol[i] << endl;
263// cout << "sd: "<< sd << "; mu: " << mu << endl;
264// };
265// cout << "----------" << endl;
266//
267// // Retry with 3 unknowns; but 1 condition equation and use SVD
268// fit.reset();
269// for (uInt i=0; i<1; i++) fit.makeNorm(ce[i], 1.0, m[i]);
270// ok = fit.invert(rank, True);
271// cout << "ok? " << ok << "; rank: " << rank << endl;
272// if (ok) {
273// fit.solve(sol, &sd, &mu);
274// for (uInt i=0; i<3; i++) cout << "Sol" << i << ": " << sol[i] << endl;
275// cout << "sd: "<< sd << "; mu: " << mu << endl;
276// };
277// cout << "----------" << endl;
278//
279// // Without SVD it would be:
280// fit.reset();
281// for (uInt i=0; i<1; i++) fit.makeNorm(ce[i], 1.0, m[i]);
282// ok = fit.invert(rank);
283// cout << "ok? " << ok << "; rank: " << rank << endl;
284// if (ok) {
285// fit.solve(sol, &sd, &mu);
286// for (uInt i=0; i<3; i++) cout << "Sol" << i << ": " << sol[i] << endl;
287// cout << "sd: "<< sd << "; mu: " << mu << endl;
288// };
289// cout << "----------" << endl;
290//
291// exit(0);
292// }
293// </srcblock>
294// Which will produce the output:
295// <srcblock>
296// ok? 1; rank: 2
297// Sol0: 3
298// Sol1: -1
299// sd: 0; mu: 0
300// ----------
301// ok? 1; rank: 3
302// Sol0: 3
303// Sol1: -1
304// Sol2: 0
305// sd: 0; mu: 0
306// ----------
307// ok? 1; rank: 2
308// Sol0: 1
309// Sol1: 1
310// Sol2: 0
311// sd: 0; mu: 0
312// ----------
313// ok? 0; rank: 2
314// ----------
315// </srcblock>
316// </example>
317//
318// <motivation>
319// The class was written to be able to do complex, real standard and SVD
320// solutions in a simple and fast way.
321// </motivation>
322//
323// <todo asof="2006/04/02">
324// <li> a thorough check if all loops are optimal in the makeNorm() methods
325// <li> input of condition equations with cross covariance
326// </todo>
327
328class LSQFit {
329 public:
330 // Simple classes to overload templated memberfunctions
331 struct Real { enum normType { REAL }; };
332 struct Complex { enum normType { COMPLEX }; };
333 struct Separable { enum normType { SEPARABLE }; };
334 struct AsReal { enum normType { ASREAL }; };
335 struct Conjugate { enum normType { CONJUGATE }; };
336 // And values to use
337 static Real REAL;
342
343 //# Public enums
344 // State of the non-linear solution
354 // Offset of fields in error_p data area.
356 // Number of condition equations
358 // Sum weights of condition equations
360 // Sum known terms squared
362 // Calculated chi^2
364 // Number of error fields
366 };
367 //# Constructors
368 // Construct an object with the number of unknowns and
369 // constraints, using the default collinearity factor and the
370 // default Levenberg-Marquardt adjustment factor.
371 // <group>
372 // Assume real
374 // Allow explicit Real specification
376 // Allow explicit Complex specification
378 // </group>
379 // Default constructor (empty, only usable after a <src>set(nUnknowns)</src>)
381 // Copy constructor (deep copy)
382 LSQFit(const LSQFit &other);
383 // Assignment (deep copy)
384 LSQFit &operator=(const LSQFit &other);
385
386 //# Destructor
388
389 //# Operators
390
391 //# General Member Functions
392 // Triangularize the normal equations and determine
393 // the rank <src>nRank</src> of the normal equations and, in the case of
394 // an <src>SVD</src> solution, the constraint
395 // equations. The collinearity factor is used
396 // to determine if the system can be solved (in essence it is the square
397 // of the sine of the angle between a column in the normal equations and
398 // the plane suspended by the other columns: if too
399 // parallel, the equations are degenerate).
400 // If <src>doSVD</src> is given as False, False is returned if rank not
401 // maximal, else an <src>SVD</src> solution is done.
402 Bool invert(uInt &nRank, Bool doSVD=False);
403 // Copy date from beg to end; converting if necessary to complex data
404 // <group>
405 template <class U>
406 void copy(const Double *beg, const Double *end, U &sol, LSQReal);
407 template <class U>
408 void copy(const Double *beg, const Double *end, U &sol, LSQComplex);
409 template <class U>
410 void copy(const Double *beg, const Double *end, U *sol, LSQReal);
411 template <class U>
412 void copy(const Double *beg, const Double *end, U *sol, LSQComplex);
413 template <class U>
414 void uncopy(Double *beg, const Double *end, U &sol, LSQReal);
415 template <class U>
416 void uncopy(Double *beg, const Double *end, U &sol, LSQComplex);
417 template <class U>
418 void uncopy(Double *beg, const Double *end, U *sol, LSQReal);
419 template <class U>
420 void uncopy(Double *beg, const Double *end, U *sol, LSQComplex);
421 template <class U>
423 template <class U>
425 // </group>
426 // Solve normal equations.
427 // The solution will be given in <src>sol</src>.
428 // <group>
429 template <class U>
430 void solve(U *sol);
431 template <class U>
432 void solve(std::complex<U> *sol);
433 template <class U>
434 void solve(U &sol);
435 // </group>
436 // Solve a loop in a non-linear set.
437 // The methods with the <src>fit</src> argument are deprecated. Use
438 // the combination without the 'fit' parameter, and the <src>isReady()</src>
439 // call. The 'fit' parameter returns
440 // for each loop a goodness
441 // of fit indicator. If it is >0; more loops are necessary.
442 // If it is negative,
443 // and has an absolute value of say less than .001, it is probably ok, and
444 // the iterations can be stopped.
445 // Other arguments are as for <src>solve()</src> and <src>invert()</src>.
446 // The <src>sol</src> is used for both input (parameter guess) and output.
447 // <group>
448 template <class U>
450 U *sol,
451 Bool doSVD=False);
452 template <class U>
454 std::complex<U> *sol,
455 Bool doSVD=False);
456 template <class U>
458 U &sol,
459 Bool doSVD=False);
460 template <class U>
461 Bool solveLoop(Double &fit, uInt &nRank,
462 U *sol,
463 Bool doSVD=False);
464 template <class U>
465 Bool solveLoop(Double &fit, uInt &nRank,
466 std::complex<U> *sol,
467 Bool doSVD=False);
468 template <class U>
469 Bool solveLoop(Double &fit, uInt &nRank,
470 U &sol,
471 Bool doSVD=False);
472 // </group>
473 // Make normal equations using the <src>cEq</src> condition equation (cArray)
474 // (with <src>nUnknowns</src> elements) and a weight <src>weight</src>,
475 // given the known observed value <src>obs</src>.
476 //
477 // <src>doNorm</src> and <src>doKnown</src> can be used
478 // to e.g. re-use existing normal equations, i.e. the condition equations,
479 // but make a new known side (i.e. new observations).
480 //
481 // The versions with <src>cEqIndex[]</src> indicate which of the
482 // <src>nUnknowns</src> are actually present in the condition equation
483 // (starting indexing at 0); the other terms are supposed to be zero. E.g.
484 // if a 12-telescope array has an equation only using telescopes 2 and 4,
485 // the lengths of <src>cEqIndex</src> and <src>cEq</src> will be both 2,
486 // and the index will contain 1 and 3 (when telescope numbering starts at 1)
487 // or 2 and 4 (when telescope numbering starts at 0. The index is given
488 // as an iterator (and hence can be a raw pointer)
489 //
490 // The complex versions can have different interpretation of the inputs,
491 // where the complex number can be seen either as a complex number; as two
492 // real numbers, or as coefficients of equations with complex conjugates.
493 // See <a href="../notes/224.html">Note 224</a>)
494 // for the details.
495 //
496 // Versions with <em>pair</em> assume that the pairs are created by the
497 // <em>SparseDiff</em> automatic differentiation class. The pair is an index
498 // and a value. The indices are assumed to be sorted.
499 //
500 // Special (<em>makeNormSorted</em>) indexed versions exist which assume
501 // that the given indices are sorted (which is the case for the
502 // LOFAR BBS environment).
503 //
504 // Some versions exist with two sets of equations (<em>cEq2, obs2</em>).
505 // If two simultaneous equations are created they will be faster.
506 //
507 // Note that the
508 // use of <src>const U &</src> is due to a Float->Double conversion problem
509 // on Solaris. Linux was ok.
510 // <group>
511 template <class U, class V>
512 void makeNorm(const V &cEq, const U &weight, const U &obs,
513 Bool doNorm=True, Bool doKnown=True);
514 template <class U, class V>
515 void makeNorm(const V &cEq, const U &weight, const U &obs,
517 Bool doNorm=True, Bool doKnown=True);
518 template <class U, class V>
519 void makeNorm(const V &cEq, const U &weight,
520 const std::complex<U> &obs,
521 Bool doNorm=True, Bool doKnown=True);
522 template <class U, class V>
523 void makeNorm(const V &cEq, const U &weight,
524 const std::complex<U> &obs,
526 Bool doNorm=True, Bool doKnown=True);
527 template <class U, class V>
528 void makeNorm(const V &cEq, const U &weight,
529 const std::complex<U> &obs,
531 Bool doNorm=True, Bool doKnown=True);
532 template <class U, class V>
533 void makeNorm(const V &cEq, const U &weight,
534 const std::complex<U> &obs,
536 Bool doNorm=True, Bool doKnown=True);
537 template <class U, class V>
538 void makeNorm(const V &cEq, const U &weight,
539 const std::complex<U> &obs,
541 Bool doNorm=True, Bool doKnown=True);
542 //
543 template <class U, class V, class W>
544 void makeNorm(uInt nIndex, const W &cEqIndex,
545 const V &cEq, const U &weight, const U &obs,
546 Bool doNorm=True, Bool doKnown=True);
547 template <class U, class V, class W>
548 void makeNorm(uInt nIndex, const W &cEqIndex,
549 const V &cEq, const V &cEq2,
550 const U &weight, const U &obs, const U &obs2,
551 Bool doNorm=True, Bool doKnown=True);
552 template <class U, class V, class W>
553 void makeNorm(uInt nIndex, const W &cEqIndex,
554 const V &cEq, const U &weight, const U &obs,
556 Bool doNorm=True, Bool doKnown=True);
557 template <class U, class V, class W>
558 void makeNorm(uInt nIndex, const W &cEqIndex,
559 const V &cEq, const U &weight,
560 const std::complex<U> &obs,
561 Bool doNorm=True, Bool doKnown=True);
562 template <class U, class V, class W>
563 void makeNorm(uInt nIndex, const W &cEqIndex,
564 const V &cEq, const U &weight,
565 const std::complex<U> &obs,
567 Bool doNorm=True, Bool doKnown=True);
568 template <class U, class V, class W>
569 void makeNorm(uInt nIndex, const W &cEqIndex,
570 const V &cEq, const U &weight,
571 const std::complex<U> &obs,
573 Bool doNorm=True, Bool doKnown=True);
574 template <class U, class V, class W>
575 void makeNorm(uInt nIndex, const W &cEqIndex,
576 const V &cEq, const U &weight,
577 const std::complex<U> &obs,
579 Bool doNorm=True, Bool doKnown=True);
580 template <class U, class V, class W>
581 void makeNorm(uInt nIndex, const W &cEqIndex,
582 const V &cEq, const U &weight,
583 const std::complex<U> &obs,
585 Bool doNorm=True, Bool doKnown=True);
586 //
587 template <class U, class V>
588 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
589 const U &weight, const U &obs,
590 Bool doNorm=True, Bool doKnown=True);
591 template <class U, class V>
592 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
593 const U &weight, const U &obs,
595 Bool doNorm=True, Bool doKnown=True);
596 template <class U, class V>
597 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
598 const U &weight,
599 const std::complex<U> &obs,
600 Bool doNorm=True, Bool doKnown=True);
601 template <class U, class V>
602 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
603 const U &weight,
604 const std::complex<U> &obs,
606 Bool doNorm=True, Bool doKnown=True);
607 template <class U, class V>
608 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
609 const U &weight,
610 const std::complex<U> &obs,
612 Bool doNorm=True, Bool doKnown=True);
613 template <class U, class V>
614 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
615 const U &weight,
616 const std::complex<U> &obs,
618 Bool doNorm=True, Bool doKnown=True);
619 template <class U, class V>
620 void makeNorm(const std::vector<std::pair<uInt, V> > &cEq,
621 const U &weight,
622 const std::complex<U> &obs,
624 Bool doNorm=True, Bool doKnown=True);
625 //
626 template <class U, class V, class W>
627 void makeNormSorted(uInt nIndex, const W &cEqIndex,
628 const V &cEq, const U &weight,
629 const U &obs,
630 Bool doNorm=True, Bool doKnown=True);
631 template <class U, class V, class W>
632 void makeNormSorted(uInt nIndex, const W &cEqIndex,
633 const V &cEq, const V &cEq2, const U &weight,
634 const U &obs, const U &obs2,
635 Bool doNorm=True, Bool doKnown=True);
636 // </group>
637 // Get the <src>n-th</src> (from 0 to the rank deficiency, or missing rank,
638 // see e.g. <src>getDeficiency()</src>)
639 // constraint equation as determined by <src>invert()</src> in SVD-mode in
640 // <src> cEq[nUnknown]</src>. False returned for illegal n. Note
641 // that nMissing will be equal to the number of unknowns
642 // (<src>nUnknowns</src>, or double that for the complex case) minus the
643 // rank as returned from the <src>invert()</src> method.
644 // <group>
645 template <class U>
646 Bool getConstraint(uInt n, U *cEq) const;
647 template <class U>
648 Bool getConstraint(uInt n, std::complex<U> *cEq) const;
649 template <class U>
650 Bool getConstraint(uInt n, U &cEq) const;
651 // </group>
652 // Add a new constraint equation (updating nConstraints); or set a
653 // numbered constraint equation (0..nConstraints-1). False if illegal
654 // number n. The constraints are equations with <src>nUnknowns</src> terms,
655 // and a constant value. E.g. measuring three angles of a triangle
656 // could lead to equation <src>[1,1,1]</src> with obs as
657 // <src>3.1415</src>. Note that each complex constraint will be
658 // converted into two real constraints (see
659 // <a href="../notes/224.html">Note 224</a>).
660 // <group>
661 template <class U, class V>
662 Bool setConstraint(uInt n, const V &cEq, const U &obs);
663 template <class U, class V>
664 Bool setConstraint(uInt n, const V &cEq,
665 const std::complex<U> &obs);
666 template <class U, class V, class W>
667 Bool setConstraint(uInt n, uInt nIndex, const W &cEqIndex,
668 const V &cEq, const U &obs);
669 template <class U, class V, class W>
670 Bool setConstraint(uInt n, uInt nIndex, const W &cEqIndex,
671 const V &cEq,
672 const std::complex<U> &obs);
673 template <class U, class V>
674 Bool addConstraint(const V &cEq, const U &obs);
675 template <class U, class V>
676 Bool addConstraint(const V &cEq,
677 const std::complex<U> &obs);
678 template <class U, class V, class W>
679 Bool addConstraint(uInt nIndex, const W &cEqIndex,
680 const V &cEq, const U &obs);
681 template <class U, class V, class W>
682 Bool addConstraint(uInt nIndex, const W &cEqIndex,
683 const V &cEq,
684 const std::complex<U> &obs);
685 // </group>
686 // Merge other <src>LSQFit</src> object (i.e. the normal equation and
687 // related information) into <src>this</src>. Both objects must have the
688 // same number of unknowns, and be pure normal equations (i.e. no
689 // <src>invert(), solve(), solveLoop()</src> or statistics calls
690 // should have been made). If merging cannot be done, <src>False</src>
691 // is returned. The index case (the index is an iterator) assumes that
692 // the normal equations to be merged are a sparse subset of the complete
693 // matrix. The index 'vector' specifies which unknowns are present. An index
694 // outside the scope of the final equations will be skipped.
695 // <note role=tip> For highest numerical precision in the case of a larger
696 // number of partial normal equations to be merged, it is best to merge
697 // them in pairs (and repeat).
698 // </note>
699 // <group>
700 Bool merge(const LSQFit &other);
701 Bool merge(const LSQFit &other, uInt nIndex, const uInt *nEqIndex) {
702 return mergeIt(other, nIndex, nEqIndex); }
703 Bool merge(const LSQFit &other, uInt nIndex,
704 const std::vector<uInt> &nEqIndex) {
705 return mergeIt(other, nIndex, &nEqIndex[0]); }
706 template <class W>
707 Bool merge(const LSQFit &other, uInt nIndex, const W &nEqIndex) {
708 std::vector<uInt> ix(nIndex);
709 for (uInt i=0; i<nIndex; ++i) ix[i] = nEqIndex[i];
710 return mergeIt(other, nIndex, &ix[0]); }
711 // </group>
712 // Reset status to empty
713 void reset();
714 // Set new sizes (default is for Real)
715 // <group>
718 set (static_cast<uInt>(nUnknowns), static_cast<uInt>(nConstraints));
719 };
722 };
725 };
728 set (static_cast<uInt>(nUnknowns), LSQComplex(),
729 static_cast<uInt>(nConstraints));
730 };
731 // </group>
732 // Set new factors (collinearity <src>factor</src>, and Levenberg-Marquardt
733 // <src>LMFactor</src>)
734 void set(Double factor=1e-6, Double LMFactor=1e-3);
735 // Set new value solution test
736 void setEpsValue(Double epsval=1e-8) {epsval_p = epsval; };
737 // Set new derivative test
738 void setEpsDerivative(Double epsder=1e-8) {epsder_p = epsder; };
739 // Set maximum number of iterations
740 void setMaxIter(uInt maxiter=0) { maxiter_p = maxiter; };
741 // Get number of iterations done
742 uInt nIterations() const { return (maxiter_p>0 ? maxiter_p-niter_p : 0); };
743 // Set the expected form of the normal equations
744 void setBalanced(Bool balanced=False) { balanced_p = balanced; };
745 // Ask the state of the non-linear solutions
746 // <group>
747 LSQFit::ReadyCode isReady() const { return ready_p; };
748 const std::string &readyText() const;
749 // </group>
750// Get the covariance matrix (of size <src>nUnknowns * nUnknowns</src>)
751 // <group>
752 template <class U>
754 template <class U>
755 Bool getCovariance(std::complex<U> *covar);
756 // </group>
757 // Get main diagonal of covariance function (of size <src>nUnknowns</src>)
758 // <group>
759 template <class U>
761 template <class U>
762 Bool getErrors(std::complex<U> *errors);
763 template <class U>
765 // </group>
766 // Get the number of unknowns
767 uInt nUnknowns() const { return nun_p; };
768 // Get the number of constraints
769 uInt nConstraints() const { return ncon_p; };
770 // Get the rank deficiency <note role=warning>Note that the number is
771 // returned assuming real values. For complex values it has to be halved
772 // </note>
773 uInt getDeficiency() const { return n_p-r_p; };
774 // Get chi^2 (both are identical); the standard deviation (per observation)
775 // and the standard deviation per weight unit.
776 // <group>
777 Double getChi() const;
778 Double getChi2() const { return getChi(); };
779 Double getSD() const;
781 // </group>
782 // Debug:
783 // <ul>
784 // <li> <src>nun = </src> number of unknowns
785 // <li> <src>np = </src> total number of solved unknowns (nun+ncon)
786 // <li> <src>ncon = </src> number of constraint equations
787 // <li> <src>ner = </src> number of elements in chi<sup>2</sup> vector
788 // <li> <src>rank = </src> rank)
789 // <li> <src>nEq = </src> normal equation (nun*nun as triangular matrix)
790 // <li> <src>known = </src> known vector (np)
791 // <li> <src>constr = </src> constraint matrix (ncon*nun)
792 // <li> <src>er = </src> error info vector (ner)
793 // <li> <src>piv = </src> pivot vector (np)
794 // <li> <src>sEq = </src> normal solution equation (np*np triangular)
795 // <li> <src>sol = </src> internal solution vector (np)
796 // <li> <src>prec = </src> collinearity precision
797 // <li> <src>nonlin = </src> current Levenberg factor-1
798 // </ul>
799 // Note that all pointers may be 0.
800 void debugIt(uInt &nun, uInt &np, uInt &ncon, uInt &ner, uInt &rank,
801 Double *&nEq, Double *&known, Double *&constr, Double *&er,
802 uInt *&piv, Double *&sEq, Double *&sol,
803 Double &prec, Double &nonlin) const;
804 //
805 // Create an LSQFit object from a record.
806 // An error message is generated, and False
807 // returned if an invalid record is given. A valid record will return True.
808 // Error messages are postfixed to error.
809 // <group>
811 // </group>
812 // Create a record from an LSQFit object.
813 // The return will be False and an error
814 // message generated only if the object does not contain a valid object.
815 // Error messages are postfixed to error.
816 Bool toRecord(String &error, RecordInterface &out) const;
817 // Get identification of record
818 const String &ident() const;
819 //
820 // Save or restore using AipsIO.
821 // <group>
822 void toAipsIO (AipsIO&) const;
824 // </group>
825 //
826 protected:
827 //# enum
828 // Bits that can be set/referenced
829 enum StateBit {
830 // Inverted matrix present
832 // Triangularised
834 // Non-linear solution
836 // Filler for cxx2html
838 };
839
840 // Record field names
841 // <group>
842 static const String recid;
843 static const String state;
844 static const String nun;
845 static const String ncon;
846 static const String prec;
847 static const String startnon;
848 static const String nonlin;
849 static const String rank;
850 static const String nnc;
851 static const String piv;
852 static const String constr;
853 static const String known;
854 static const String errors;
855 static const String sol;
856 static const String lar;
857 static const String wsol;
858 static const String wcov;
859 static const String nceq;
860 static const String nar;
861 // </group>
862
863 //# Data
864 // Bits set to indicate state
866 // Number of unknowns
868 // Number of constraints
870 // Matrix size (will be n_p = nun_p + ncon_p)
872 // Rank of normal equations (normally n_p)
874 // Collinearity precision
876 // Levenberg start factor
878 // Levenberg current factor
880 // Levenberg step factor
882 // Test value for [incremental] solution in non-linear loop.
883 // The <src>||sol increment||/||sol||</src> is tested
885 // Test value for known vector in non-linear loop.
886 // ||known||<sub>inf</sub> is tested
888 // Indicator for a well balanced normal equation. A balanced equation is
889 // one with similar values in the main diagonal.
891 // Maximum number of iterations for non-linear solution. If a non-zero
892 // maximum number of iterations is set, the value is tested in non-linear
893 // loops
895 // Iteration count for non-linear solution
897 // Indicate the non-linear state. A non-zero code indicates that non-linear
898 // looping is ready.
900
901 // Pivot table (n_p)
903 // Normal equations (triangular nun_p * nun_p)
905 // Current length nceq_p
907 // Normal combined with constraint equations for solutions
908 // (triangular nnc_p*nnc_p)
910 // Known part equations (n_p)
912 // Counts for errors (N_ErrorField)
914 // Constraint equation area (nun_p*ncon_p))
916 // Solution area (n_p)
918 // Save area for non-linear case (size determined internally)
920 // Save area for non-symmetric (i.e. with constraints) (n_p * n_p)
922 // Work areas for interim solutions and covariance
923 // <group>
926 // </group>
927
928 //# Member functions
929 // Get pointer in rectangular array
930 // <group>
931 Double *rowrt(uInt i) const { return &lar_p[n_p*i]; };
932 Double *rowru(uInt i) const { return &lar_p[nun_p*i]; };
933 // </group>
934 // Calculate the real or imag part of <src>x*conj(y)</src>
935 // <group>
936 static Double realMC(const std::complex<Double> &x,
937 const std::complex<Double> &y) {
938 return (x.real()*y.real() + x.imag()*y.imag()); };
939 static Double imagMC(const std::complex<Double> &x,
940 const std::complex<Double> &y) {
941 return (x.imag()*y.real() - x.real()*y.imag()); };
942 static Float realMC(const std::complex<Float> &x,
943 const std::complex<Float> &y) {
944 return (x.real()*y.real() + x.imag()*y.imag()); };
945 static Float imagMC(const std::complex<Float> &x,
946 const std::complex<Float> &y) {
947 return (x.imag()*y.real() - x.real()*y.imag()); };
948 // </group>
949 // Initialise areas
950 void init();
951 // Clear areas
952 void clear();
953 // De-initialise area
954 void deinit();
955 // Solve normal equations
956 void solveIt();
957 // One non-linear LM loop
958 Bool solveItLoop(Double &fit, uInt &nRank, Bool doSVD=False);
959 // Solve missing rank part
960 void solveMR(uInt nin);
961 // Invert rectangular matrix (i.e. when constraints present)
963 // Get the norm of the current solution vector
965 // Get the infinite norm of the known vector
967 // Merge sparse normal equations
968 Bool mergeIt(const LSQFit &other, uInt nIndex, const uInt *nEqIndex);
969 // Save current status (or part)
971 // Restore current status
973 // Copy data. If all False, only the relevant data for non-linear
974 // solution are copied (normal equations, knows and errors).
975 void copy(const LSQFit &other, Bool all=True);
976 // Extend the constraint equation area to the specify number of
977 // equations.
979 // Create the solution equation area nceq_p and fill it.
981 // Get work areas for solutions, covariance
982 // <group>
985 // </group>
986 //
987};
988
989
990} //# NAMESPACE CASACORE - END
991
992#ifndef CASACORE_NO_AUTO_TEMPLATES
993#include <casacore/scimath/Fitting/LSQFit2.tcc>
994#endif //# CASACORE_NO_AUTO_TEMPLATES
995#endif
Type of complex numeric class indicator
Definition LSQTraits.h:69
Double stepfactor_p
Levenberg step factor.
Definition LSQFit.h:881
void solve(U *sol)
Solve normal equations.
Double prec_p
Collinearity precision.
Definition LSQFit.h:875
uInt nUnknowns() const
Get the number of unknowns.
Definition LSQFit.h:767
static const String nceq
Definition LSQFit.h:859
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
void createNCEQ()
Create the solution equation area nceq_p and fill it.
Bool merge(const LSQFit &other)
Merge other LSQFit object (i.e.
void set(Int nUnknowns, Int nConstraints=0)
Definition LSQFit.h:717
Bool invert(uInt &nRank, Bool doSVD=False)
Triangularize the normal equations and determine the rank nRank of the normal equations and,...
void extendConstraints(uInt n)
Extend the constraint equation area to the specify number of equations.
Bool solveLoop(uInt &nRank, U *sol, Bool doSVD=False)
Solve a loop in a non-linear set.
static const String state
Definition LSQFit.h:843
Bool setConstraint(uInt n, const V &cEq, const std::complex< U > &obs)
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
static Separable SEPARABLE
Definition LSQFit.h:339
Double * wsol_p
Work areas for interim solutions and covariance.
Definition LSQFit.h:924
Bool getCovariance(std::complex< U > *covar)
static const String recid
Record field names.
Definition LSQFit.h:842
void uncopy(Double *beg, const Double *end, U &sol, LSQComplex)
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
ReadyCode ready_p
Indicate the non-linear state.
Definition LSQFit.h:899
Bool getErrors(std::complex< U > *errors)
void set(uInt nUnknowns, uInt nConstraints=0)
Set new sizes (default is for Real)
Bool getConstraint(uInt n, U *cEq) const
Get the n-th (from 0 to the rank deficiency, or missing rank, see e.g.
Bool solveLoop(Double &fit, uInt &nRank, U &sol, Bool doSVD=False)
const String & ident() const
Get identification of record.
void save(Bool all=True)
Save current status (or part)
void init()
Initialise areas.
uInt nIterations() const
Get number of iterations done.
Definition LSQFit.h:742
void makeNorm(const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
static const String nonlin
Definition LSQFit.h:848
void set(Double factor=1e-6, Double LMFactor=1e-3)
Set new factors (collinearity factor, and Levenberg-Marquardt LMFactor)
Double startnon_p
Levenberg start factor.
Definition LSQFit.h:877
LSQFit(uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
Allow explicit Complex specification.
Bool invertRect()
Invert rectangular matrix (i.e.
Double normInfKnown(const Double *known) const
Get the infinite norm of the known vector.
uInt r_p
Rank of normal equations (normally n_p)
Definition LSQFit.h:873
static const String constr
Definition LSQFit.h:852
LSQFit * nar_p
Save area for non-linear case (size determined internally)
Definition LSQFit.h:919
Double normSolution(const Double *sol) const
Get the norm of the current solution vector.
Bool solveLoop(Double &fit, uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
void solveIt()
Solve normal equations.
uInt nnc_p
Current length nceq_p.
Definition LSQFit.h:906
uInt state_p
Bits set to indicate state.
Definition LSQFit.h:865
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
Double * rowru(uInt i) const
Definition LSQFit.h:932
Double * rowrt(uInt i) const
Get pointer in rectangular array.
Definition LSQFit.h:931
Double getChi() const
Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation p...
Bool getConstraint(uInt n, U &cEq) const
void makeNorm(const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
uInt nun_p
Number of unknowns.
Definition LSQFit.h:867
Double * constr_p
Constraint equation area (nun_p*ncon_p))
Definition LSQFit.h:915
static AsReal ASREAL
Definition LSQFit.h:340
void toAipsIO(AipsIO &) const
Save or restore using AipsIO.
LSQFit(const LSQFit &other)
Copy constructor (deep copy)
uInt n_p
Matrix size (will be n_p = nun_p + ncon_p)
Definition LSQFit.h:871
static Complex COMPLEX
Definition LSQFit.h:338
Bool getErrors(U &errors)
Bool solveLoop(Double &fit, uInt &nRank, U *sol, Bool doSVD=False)
uInt * piv_p
Pivot table (n_p)
Definition LSQFit.h:902
static const String wsol
Definition LSQFit.h:857
Bool addConstraint(const V &cEq, const U &obs)
void uncopy(Double *beg, const Double *end, U *sol, LSQReal)
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
Double epsval_p
Test value for [incremental] solution in non-linear loop.
Definition LSQFit.h:884
LSQMatrix * nceq_p
Normal combined with constraint equations for solutions (triangular nnc_p*nnc_p)
Definition LSQFit.h:909
Bool addConstraint(const V &cEq, const std::complex< U > &obs)
Double * wcov_p
Definition LSQFit.h:925
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
Bool merge(const LSQFit &other, uInt nIndex, const W &nEqIndex)
Definition LSQFit.h:707
Double * lar_p
Save area for non-symmetric (i.e.
Definition LSQFit.h:921
LSQFit(uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
Allow explicit Real specification.
Bool solveLoop(uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
uInt ncon_p
Number of constraints.
Definition LSQFit.h:869
static Double realMC(const std::complex< Double > &x, const std::complex< Double > &y)
Calculate the real or imag part of x*conj(y)
Definition LSQFit.h:936
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
Bool getConstraint(uInt n, std::complex< U > *cEq) const
Bool addConstraint(uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
Bool getCovariance(U *covar)
Get the covariance matrix (of size nUnknowns * nUnknowns)
void solve(U &sol)
static const String known
Definition LSQFit.h:853
Bool setConstraint(uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
Double getChi2() const
Definition LSQFit.h:778
const std::string & readyText() const
Bool solveItLoop(Double &fit, uInt &nRank, Bool doSVD=False)
One non-linear LM loop.
Bool toRecord(String &error, RecordInterface &out) const
Create a record from an LSQFit object.
Double * error_p
Counts for errors (N_ErrorField)
Definition LSQFit.h:913
void solve(std::complex< U > *sol)
void setMaxIter(uInt maxiter=0)
Set maximum number of iterations.
Definition LSQFit.h:740
Bool getErrors(U *errors)
Get main diagonal of covariance function (of size nUnknowns)
void set(uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
Definition LSQFit.h:720
void makeNormSorted(uInt nIndex, const W &cEqIndex, const V &cEq, const V &cEq2, const U &weight, const U &obs, const U &obs2, Bool doNorm=True, Bool doKnown=True)
static const String errors
Definition LSQFit.h:854
uInt nConstraints() const
Get the number of constraints.
Definition LSQFit.h:769
void copy(const Double *beg, const Double *end, U *sol, LSQComplex)
void makeNorm(const V &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
void clear()
Clear areas.
static const String ncon
Definition LSQFit.h:845
void makeNorm(const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
Make normal equations using the cEq condition equation (cArray) (with nUnknowns elements) and a weigh...
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
void set(Int nUnknowns, const LSQComplex &, Int nConstraints=0)
Definition LSQFit.h:727
void copy(const LSQFit &other, Bool all=True)
Copy data.
static const String rank
Definition LSQFit.h:849
LSQFit()
Default constructor (empty, only usable after a set(nUnknowns))
Double * sol_p
Solution area (n_p)
Definition LSQFit.h:917
Bool setConstraint(uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
static const String nun
Definition LSQFit.h:844
void setEpsValue(Double epsval=1e-8)
Set new value solution test.
Definition LSQFit.h:736
void getWorkSOL()
Get work areas for solutions, covariance.
static Double imagMC(const std::complex< Double > &x, const std::complex< Double > &y)
Definition LSQFit.h:939
static const String wcov
Definition LSQFit.h:858
LSQFit(uInt nUnknowns, uInt nConstraints=0)
Construct an object with the number of unknowns and constraints, using the default collinearity facto...
Bool merge(const LSQFit &other, uInt nIndex, const std::vector< uInt > &nEqIndex)
Definition LSQFit.h:703
uInt niter_p
Iteration count for non-linear solution.
Definition LSQFit.h:896
void makeNorm(const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
LSQFit::ReadyCode isReady() const
Ask the state of the non-linear solutions.
Definition LSQFit.h:747
Bool setConstraint(uInt n, const V &cEq, const U &obs)
Add a new constraint equation (updating nConstraints); or set a numbered constraint equation (0....
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const V &cEq2, const U &weight, const U &obs, const U &obs2, Bool doNorm=True, Bool doKnown=True)
static const String sol
Definition LSQFit.h:855
void makeNorm(const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
uInt maxiter_p
Maximum number of iterations for non-linear solution.
Definition LSQFit.h:894
void setBalanced(Bool balanced=False)
Set the expected form of the normal equations.
Definition LSQFit.h:744
void fromAipsIO(AipsIO &)
Bool balanced_p
Indicator for a well balanced normal equation.
Definition LSQFit.h:890
void set(uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
void restore(Bool all=True)
Restore current status.
StateBit
Bits that can be set/referenced.
Definition LSQFit.h:829
@ NONLIN
Non-linear solution.
Definition LSQFit.h:835
@ TRIANGLE
Triangularised.
Definition LSQFit.h:833
@ N_StateBit
Filler for cxx2html.
Definition LSQFit.h:837
@ INVERTED
Inverted matrix present.
Definition LSQFit.h:831
void uncopy(Double *beg, const Double *end, U &sol, LSQReal)
static const String lar
Definition LSQFit.h:856
ErrorField
Offset of fields in error_p data area.
Definition LSQFit.h:355
@ NC
Number of condition equations.
Definition LSQFit.h:357
@ CHI2
Calculated chi^2.
Definition LSQFit.h:363
@ SUMWEIGHT
Sum weights of condition equations.
Definition LSQFit.h:359
@ N_ErrorField
Number of error fields.
Definition LSQFit.h:365
@ SUMLL
Sum known terms squared.
Definition LSQFit.h:361
Bool merge(const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
Definition LSQFit.h:701
Bool solveLoop(uInt &nRank, U &sol, Bool doSVD=False)
void makeNorm(const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
Double * known_p
Known part equations (n_p)
Definition LSQFit.h:911
void uncopy(Double *beg, const Double *end, U *sol, LSQComplex)
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
Double nonlin_p
Levenberg current factor.
Definition LSQFit.h:879
static Float imagMC(const std::complex< Float > &x, const std::complex< Float > &y)
Definition LSQFit.h:945
static const String startnon
Definition LSQFit.h:847
uInt getDeficiency() const
Get the rank deficiency Warning: Note that the number is returned assuming real values; For complex ...
Definition LSQFit.h:773
void copyDiagonal(U &errors, LSQComplex)
static const String piv
Definition LSQFit.h:851
static Real REAL
And values to use.
Definition LSQFit.h:337
Bool mergeIt(const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
Merge sparse normal equations.
ReadyCode
State of the non-linear solution.
Definition LSQFit.h:345
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
void reset()
Reset status to empty.
static const String nnc
Definition LSQFit.h:850
void copy(const Double *beg, const Double *end, U &sol, LSQReal)
Copy date from beg to end; converting if necessary to complex data.
Double getWeightedSD() const
Bool fromRecord(String &error, const RecordInterface &in)
Create an LSQFit object from a record.
static Conjugate CONJUGATE
Definition LSQFit.h:341
void makeNorm(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
static const String prec
Definition LSQFit.h:846
static Float realMC(const std::complex< Float > &x, const std::complex< Float > &y)
Definition LSQFit.h:942
void setEpsDerivative(Double epsder=1e-8)
Set new derivative test.
Definition LSQFit.h:738
void solveMR(uInt nin)
Solve missing rank part.
void set(Int nUnknowns, const LSQReal &, Int nConstraints=0)
Definition LSQFit.h:723
void debugIt(uInt &nun, uInt &np, uInt &ncon, uInt &ner, uInt &rank, Double *&nEq, Double *&known, Double *&constr, Double *&er, uInt *&piv, Double *&sEq, Double *&sol, Double &prec, Double &nonlin) const
Debug:
void deinit()
De-initialise area.
LSQMatrix * norm_p
Normal equations (triangular nun_p * nun_p)
Definition LSQFit.h:904
LSQFit & operator=(const LSQFit &other)
Assignment (deep copy)
Bool addConstraint(uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
Double getSD() const
void makeNormSorted(uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
void copy(const Double *beg, const Double *end, U *sol, LSQReal)
Double epsder_p
Test value for known vector in non-linear loop.
Definition LSQFit.h:887
void copy(const Double *beg, const Double *end, U &sol, LSQComplex)
void copyDiagonal(U &errors, LSQReal)
static const String nar
Definition LSQFit.h:860
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
LatticeExprNode all(const LatticeExprNode &expr)
Simple classes to overload templated memberfunctions.
Definition LSQFit.h:331