casacore
Loading...
Searching...
No Matches
casacore::LSQFit Class Reference

More...

#include <LSQFit.h>

Classes

struct  AsReal
 
struct  Complex
 
struct  Conjugate
 
struct  Real
 Simple classes to overload templated memberfunctions. More...
 
struct  Separable
 

Public Types

enum  ReadyCode {
  NONREADY ,
  SOLINCREMENT ,
  DERIVLEVEL ,
  MAXITER ,
  NOREDUCTION ,
  SINGULAR ,
  N_ReadyCode
}
 State of the non-linear solution. More...
 
enum  ErrorField {
  NC ,
  SUMWEIGHT ,
  SUMLL ,
  CHI2 ,
  N_ErrorField
}
 Offset of fields in error_p data area. More...
 

Public Member Functions

 LSQFit (uInt nUnknowns, uInt nConstraints=0)
 Construct an object with the number of unknowns and constraints, using the default collinearity factor and the default Levenberg-Marquardt adjustment factor.
 
 LSQFit (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
 Allow explicit Real specification.
 
 LSQFit (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
 Allow explicit Complex specification.
 
 LSQFit ()
 Default constructor (empty, only usable after a set(nUnknowns))
 
 LSQFit (const LSQFit &other)
 Copy constructor (deep copy)
 
LSQFitoperator= (const LSQFit &other)
 Assignment (deep copy)
 
 ~LSQFit ()
 
Bool invert (uInt &nRank, Bool doSVD=False)
 Triangularize the normal equations and determine the rank nRank of the normal equations and, in the case of an SVD solution, the constraint equations.
 
template<class U >
void copy (const Double *beg, const Double *end, U &sol, LSQReal)
 Copy date from beg to end; converting if necessary to complex data.
 
template<class U >
void copy (const Double *beg, const Double *end, U &sol, LSQComplex)
 
template<class U >
void copy (const Double *beg, const Double *end, U *sol, LSQReal)
 
template<class U >
void copy (const Double *beg, const Double *end, U *sol, LSQComplex)
 
template<class U >
void uncopy (Double *beg, const Double *end, U &sol, LSQReal)
 
template<class U >
void uncopy (Double *beg, const Double *end, U &sol, LSQComplex)
 
template<class U >
void uncopy (Double *beg, const Double *end, U *sol, LSQReal)
 
template<class U >
void uncopy (Double *beg, const Double *end, U *sol, LSQComplex)
 
template<class U >
void copyDiagonal (U &errors, LSQReal)
 
template<class U >
void copyDiagonal (U &errors, LSQComplex)
 
template<class U >
void solve (U *sol)
 Solve normal equations.
 
template<class U >
void solve (std::complex< U > *sol)
 
template<class U >
void solve (U &sol)
 
template<class U >
Bool solveLoop (uInt &nRank, U *sol, Bool doSVD=False)
 Solve a loop in a non-linear set.
 
template<class U >
Bool solveLoop (uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (uInt &nRank, U &sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, U *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, std::complex< U > *sol, Bool doSVD=False)
 
template<class U >
Bool solveLoop (Double &fit, uInt &nRank, U &sol, Bool doSVD=False)
 
template<class U , class V >
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 weight weight, given the known observed value obs.
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Complex, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Separable, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::AsReal, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const V &cEq, const U &weight, const std::complex< U > &obs, LSQFit::Conjugate, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
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)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
void makeNorm (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
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)
 
template<class U , class V , class W >
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)
 
template<class U , class V , class W >
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)
 
template<class U , class V , class W >
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)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const U &obs, LSQFit::Real, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
void makeNorm (const std::vector< std::pair< uInt, V > > &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V >
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)
 
template<class U , class V >
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)
 
template<class U , class V >
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)
 
template<class U , class V >
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)
 
template<class U , class V , class W >
void makeNormSorted (uInt nIndex, const W &cEqIndex, const V &cEq, const U &weight, const U &obs, Bool doNorm=True, Bool doKnown=True)
 
template<class U , class V , class W >
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)
 
template<class U >
Bool getConstraint (uInt n, U *cEq) const
 Get the n-th (from 0 to the rank deficiency, or missing rank, see e.g.
 
template<class U >
Bool getConstraint (uInt n, std::complex< U > *cEq) const
 
template<class U >
Bool getConstraint (uInt n, U &cEq) const
 
template<class U , class V >
Bool setConstraint (uInt n, const V &cEq, const U &obs)
 Add a new constraint equation (updating nConstraints); or set a numbered constraint equation (0..nConstraints-1).
 
template<class U , class V >
Bool setConstraint (uInt n, const V &cEq, const std::complex< U > &obs)
 
template<class U , class V , class W >
Bool setConstraint (uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
 
template<class U , class V , class W >
Bool setConstraint (uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
 
template<class U , class V >
Bool addConstraint (const V &cEq, const U &obs)
 
template<class U , class V >
Bool addConstraint (const V &cEq, const std::complex< U > &obs)
 
template<class U , class V , class W >
Bool addConstraint (uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
 
template<class U , class V , class W >
Bool addConstraint (uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
 
Bool merge (const LSQFit &other)
 Merge other LSQFit object (i.e.
 
Bool merge (const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
 
Bool merge (const LSQFit &other, uInt nIndex, const std::vector< uInt > &nEqIndex)
 
template<class W >
Bool merge (const LSQFit &other, uInt nIndex, const W &nEqIndex)
 
void reset ()
 Reset status to empty.
 
void set (uInt nUnknowns, uInt nConstraints=0)
 Set new sizes (default is for Real)
 
void set (Int nUnknowns, Int nConstraints=0)
 
void set (uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
 
void set (Int nUnknowns, const LSQReal &, Int nConstraints=0)
 
void set (uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
 
void set (Int nUnknowns, const LSQComplex &, Int nConstraints=0)
 
void set (Double factor=1e-6, Double LMFactor=1e-3)
 Set new factors (collinearity factor, and Levenberg-Marquardt LMFactor)
 
void setEpsValue (Double epsval=1e-8)
 Set new value solution test.
 
void setEpsDerivative (Double epsder=1e-8)
 Set new derivative test.
 
void setMaxIter (uInt maxiter=0)
 Set maximum number of iterations.
 
uInt nIterations () const
 Get number of iterations done.
 
void setBalanced (Bool balanced=False)
 Set the expected form of the normal equations.
 
LSQFit::ReadyCode isReady () const
 Ask the state of the non-linear solutions.
 
const std::string & readyText () const
 
template<class U >
Bool getCovariance (U *covar)
 Get the covariance matrix (of size nUnknowns * nUnknowns)
 
template<class U >
Bool getCovariance (std::complex< U > *covar)
 
template<class U >
Bool getErrors (U *errors)
 Get main diagonal of covariance function (of size nUnknowns)
 
template<class U >
Bool getErrors (std::complex< U > *errors)
 
template<class U >
Bool getErrors (U &errors)
 
uInt nUnknowns () const
 Get the number of unknowns.
 
uInt nConstraints () const
 Get the number of constraints.
 
uInt getDeficiency () const
 Get the rank deficiency
Warning: Note that the number is returned assuming real values; For complex values it has to be halved

 
Double getChi () const
 Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation per weight unit.
 
Double getChi2 () const
 
Double getSD () const
 
Double getWeightedSD () const
 
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:
 
Bool fromRecord (String &error, const RecordInterface &in)
 Create an LSQFit object from a record.
 
Bool toRecord (String &error, RecordInterface &out) const
 Create a record from an LSQFit object.
 
const Stringident () const
 Get identification of record.
 
void toAipsIO (AipsIO &) const
 Save or restore using AipsIO.
 
void fromAipsIO (AipsIO &)
 

Static Public Attributes

static Real REAL
 And values to use.
 
static Complex COMPLEX
 
static Separable SEPARABLE
 
static AsReal ASREAL
 
static Conjugate CONJUGATE
 

Protected Types

enum  StateBit {
  INVERTED ,
  TRIANGLE ,
  NONLIN ,
  N_StateBit
}
 Bits that can be set/referenced. More...
 

Protected Member Functions

Doublerowrt (uInt i) const
 Get pointer in rectangular array.
 
Doublerowru (uInt i) const
 
void init ()
 Initialise areas.
 
void clear ()
 Clear areas.
 
void deinit ()
 De-initialise area.
 
void solveIt ()
 Solve normal equations.
 
Bool solveItLoop (Double &fit, uInt &nRank, Bool doSVD=False)
 One non-linear LM loop.
 
void solveMR (uInt nin)
 Solve missing rank part.
 
Bool invertRect ()
 Invert rectangular matrix (i.e.
 
Double normSolution (const Double *sol) const
 Get the norm of the current solution vector.
 
Double normInfKnown (const Double *known) const
 Get the infinite norm of the known vector.
 
Bool mergeIt (const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
 Merge sparse normal equations.
 
void save (Bool all=True)
 Save current status (or part)
 
void restore (Bool all=True)
 Restore current status.
 
void copy (const LSQFit &other, Bool all=True)
 Copy data.
 
void extendConstraints (uInt n)
 Extend the constraint equation area to the specify number of equations.
 
void createNCEQ ()
 Create the solution equation area nceq_p and fill it.
 
void getWorkSOL ()
 Get work areas for solutions, covariance.
 
void getWorkCOV ()
 

Static Protected Member Functions

static Double realMC (const std::complex< Double > &x, const std::complex< Double > &y)
 Calculate the real or imag part of x*conj(y)
 
static Double imagMC (const std::complex< Double > &x, const std::complex< Double > &y)
 
static Float realMC (const std::complex< Float > &x, const std::complex< Float > &y)
 
static Float imagMC (const std::complex< Float > &x, const std::complex< Float > &y)
 

Protected Attributes

uInt state_p
 Bits set to indicate state.
 
uInt nun_p
 Number of unknowns.
 
uInt ncon_p
 Number of constraints.
 
uInt n_p
 Matrix size (will be n_p = nun_p + ncon_p)
 
uInt r_p
 Rank of normal equations (normally n_p)
 
Double prec_p
 Collinearity precision.
 
Double startnon_p
 Levenberg start factor.
 
Double nonlin_p
 Levenberg current factor.
 
Double stepfactor_p
 Levenberg step factor.
 
Double epsval_p
 Test value for [incremental] solution in non-linear loop.
 
Double epsder_p
 Test value for known vector in non-linear loop.
 
Bool balanced_p
 Indicator for a well balanced normal equation.
 
uInt maxiter_p
 Maximum number of iterations for non-linear solution.
 
uInt niter_p
 Iteration count for non-linear solution.
 
ReadyCode ready_p
 Indicate the non-linear state.
 
uIntpiv_p
 Pivot table (n_p)
 
LSQMatrixnorm_p
 Normal equations (triangular nun_p * nun_p)
 
uInt nnc_p
 Current length nceq_p.
 
LSQMatrixnceq_p
 Normal combined with constraint equations for solutions (triangular nnc_p*nnc_p)
 
Doubleknown_p
 Known part equations (n_p)
 
Doubleerror_p
 Counts for errors (N_ErrorField)
 
Doubleconstr_p
 Constraint equation area (nun_p*ncon_p))
 
Doublesol_p
 Solution area (n_p)
 
LSQFitnar_p
 Save area for non-linear case (size determined internally)
 
Doublelar_p
 Save area for non-symmetric (i.e.
 
Doublewsol_p
 Work areas for interim solutions and covariance.
 
Doublewcov_p
 

Static Protected Attributes

static const String recid
 Record field names.
 
static const String state
 
static const String nun
 
static const String ncon
 
static const String prec
 
static const String startnon
 
static const String nonlin
 
static const String rank
 
static const String nnc
 
static const String piv
 
static const String constr
 
static const String known
 
static const String errors
 
static const String sol
 
static const String lar
 
static const String wsol
 
static const String wcov
 
static const String nceq
 
static const String nar
 

Detailed Description

Basic class for the least squares fitting

Review Status

Reviewed By:
Neil Killeen
Date Reviewed:
2000/06/01
Test programs:
tLSQFit

Prerequisite

Etymology

From Least SQuares and Fitting

Synopsis

The LSQFit class contains the basic functions to do all the fitting described in the Note about fitting. It handles real, and complex equations;
linear and non-linear (Levenberg-Marquardt) solutions;
regular (with optional constraints) or Singular Value Decomposition (SVD).
In essence they are a set of routines to generate normal equations (makeNorm()) in triangular form from a set of condition equations;
to do a Cholesky-type decomposition of the normal equations (either regular or SVD) and test its rank (invert());
to do a quasi inversion of the decomposed equations (solve()) to obtain the solution and/or the errors.

All calculations are done in place. Methods to obtain additional information about the fitting process are available.

This class can be used as a stand-alone class outside of the Casacore environment. In that case the aips.h include file can be replaced if necessary by appropriate typedefs for Double, Float and uInt.
The interface to the methods have standard data or standard STL iterator arguments only. They can be used with any container having an STL random-access iterator interface. Especially they can be used with carrays (necessary templates provided), Casacore Vectors (necessary templates provided in LSQaips), standard random access STL containers (like std::vector).

The normal operation of the class consists of the following steps:

  • Create an LSQFit object. The information that can be provided in the constructor of the object, either directly, or indirectly using the set() commands, is (see Note 224):

    • The number of unknowns that have to be solved for (mandatory)
    • The number of constraint equations you want to use explicitly (defaults to 0, but can be changed on-the-fly)

    Separately settable are:

    • A collinearity test factor (defaults to 1e-8)
      Warning: The collinearity factor is the square of the sine of the angle between a column in the normal equations, and the hyper-plane through all the other columns; In special cases (e;g; fitting a polynomial in a very narrow bandwidth window, it could be advisable to set this factor to zero if you want a solution (whatever the truth of it maybe);
    • A Levenberg-Marquardt adjustment factor (if appropriate, defaults to 1e-3)

  • Create the normal equations used in solving the set of condition equations of the user, by using the makeNorm() methods. Separate makenorm() methods are provided for sparse condition equations (e.g. if data for 3 antennas are provided, rather than for all 64)

  • If there are user provided constraints, either limiting constraints like the sum of the angles in a triangle is 180 degrees, or constraints to add missing information if e.g. only differences between parameters have been measured, they can be added to the normal equations with the setConstraint() or the addConstraint() methods. Lagrange multipliers will be used to solve the extended normal equations.

  • The normal equations are triangu;arised (using the collinearity factor as a check for solvability) with the invert() method. If the normal equations are non-solvable an error is returned, or a switch to an SVD solution is made if indicated in the invert call.

  • The solutions and adjustment errors are obtained with the solve() method. A non-linear loop in a Levenberg-Marquardt adjustment can be obtained (together with convergence information), with the solveLoop() method (see below) replacing the combination of invert and solve.

  • Non-linear loops are done by looping through the data using makeNorm() calls, and upgrade the solution with the solveLoop() method. The normal equations are upgraded by changing LM factors. Upgrade depends on the 'balanced' factor. The LM factor is either added in some way to all diagonal elements (if balanced) or all diagonal elements are multiplied by (1+factor) After each loop convergence can be tested by the isReady() call; which will return False or a non-zero code indicating the ready reason. Reasons for stopping can be:

    • SOLINCREMENT: the relative change in the norm of the parameter solutions is less than (a settable, setEpsValue(), default 1e-8) value.
    • DERIVLEVEL: the inf-norm of the known vector of the equations to be solved is less than the settable, setEpsDerivative(), default 1e-8, value.
    • MAXITER: maximum number of iterations reached (only possible if a number is explicitly set)
    • NOREDUCTION: if the Levenberg-Marquardt correction factor goes towards infinity. I.e. if no Chi2 improvement seems possible. Have to redo the solution with a different start condition for the unknowns.
    • SINGULAR: can only happen due to numeric rounding, since the LM equations are always positive-definite. Best solution is to indicate SVD needed in the solveLoop call, which is cost-free

  • Covariance information in various forms can be obtained with the getCovariance(), getErrors(), getChi() (or getChi2), getSD and getWeightedSD methods after a solve() or after the final loop in a non-linear solution (of course, when necessary only).

An LSQFit object can be re-used by issuing the reset() command, or set() of new values. If an unknown has not been used in the condition equations at all, the doDiagonal() will make sure a proper solution is obtained, with missing unknowns zeroed.

Most of the calculations are done in place; however, enough data is saved that it is possible to continue with the same (partial) normal equations after e.g. an interim solution.

If the normal equations are produced in separate partial sets (e.g. in a multi-processor environment) a merge() method can combine them.
Tip: It is suggested to add any possible constraint equations after the merge;

A debugIt() method provides read access to all internal information.

The member definitions are split over three files. The second one contains the templated member function definitions, to bypass the problem of duplicate definitions of non-templated members when pre-compiling them. The third contains methods for saving objects as Records or through AipsIO.


Warning: No boundary checks on input and output containers is done for faster execution; In general these tests should be done at the higher level routines, like the LinearFit and NonLinearFit classes which should be checked for usage of LSQFit;

The contents can be saved in a record (toRecord), and an object can be created from a record (fromRecord). The record identifier is 'lfit'.
The object can also be saved or restored using AipsIO.

Example

See the tLSQFit.cc and tLSQaips.cc program for extensive examples.

The following example will first create 2 condition equations for 3 unknowns (the third is degenerate). It will first create normal equations for a 2 unknown solution and solve; then it will create normal equations for a 3 unknown solution, and solve (note that the degenerate will be set to 0. The last one will use SVD and one condition equation.r

#include <casacore/casa/aips.h>
#include <casacore/scimath/Fitting/LSQFit.h>
#include <iostream>
int main() {
// Condition equations for x+y=2; x-y=4;
Double ce[2][3] = {{1, 1, 0}, {1, -1, 0}};
Double m[2] = {2, 4};
// Solution and error area
Double sd, mu;
Bool ok;
// LSQ object
LSQFit fit(2);
// Make normal equation
for (uInt i=0; i<2; i++) fit.makeNorm(ce[i], 1.0, m[i]);
// Invert(decompose) and show
ok = fit.invert(rank);
cout << "ok? " << ok << "; rank: " << rank << endl;
// Solve and show
if (ok) {
fit.solve(sol, &sd, &mu);
for (uInt i=0; i<2; i++) cout << "Sol" << i << ": " << sol[i] << endl;
cout << "sd: "<< sd << "; mu: " << mu << endl;
};
cout << "----------" << endl;
// Retry with 3 unknowns: note auto fill of unmentioned one
fit.set(uInt(3));
for (uInt i=0; i<2; i++) fit.makeNorm(ce[i], 1.0, m[i]);
ok = fit.invert(rank);
cout << "ok? " << ok << "; rank: " << rank << endl;
if (ok) {
fit.solve(sol, &sd, &mu);
for (uInt i=0; i<3; i++) cout << "Sol" << i << ": " << sol[i] << endl;
cout << "sd: "<< sd << "; mu: " << mu << endl;
};
cout << "----------" << endl;
// Retry with 3 unknowns; but 1 condition equation and use SVD
fit.reset();
for (uInt i=0; i<1; i++) fit.makeNorm(ce[i], 1.0, m[i]);
ok = fit.invert(rank, True);
cout << "ok? " << ok << "; rank: " << rank << endl;
if (ok) {
fit.solve(sol, &sd, &mu);
for (uInt i=0; i<3; i++) cout << "Sol" << i << ": " << sol[i] << endl;
cout << "sd: "<< sd << "; mu: " << mu << endl;
};
cout << "----------" << endl;
// Without SVD it would be:
fit.reset();
for (uInt i=0; i<1; i++) fit.makeNorm(ce[i], 1.0, m[i]);
ok = fit.invert(rank);
cout << "ok? " << ok << "; rank: " << rank << endl;
if (ok) {
fit.solve(sol, &sd, &mu);
for (uInt i=0; i<3; i++) cout << "Sol" << i << ": " << sol[i] << endl;
cout << "sd: "<< sd << "; mu: " << mu << endl;
};
cout << "----------" << endl;
exit(0);
}
static const String rank
Definition LSQFit.h:849
LSQFit()
Default constructor (empty, only usable after a set(nUnknowns))
static const String sol
Definition LSQFit.h:855
unsigned int uInt
Definition aipstype.h:49
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

Which will produce the output:

ok? 1; rank: 2
Sol0: 3
Sol1: -1
sd: 0; mu: 0
----------
ok? 1; rank: 3
Sol0: 3
Sol1: -1
Sol2: 0
sd: 0; mu: 0
----------
ok? 1; rank: 2
Sol0: 1
Sol1: 1
Sol2: 0
sd: 0; mu: 0
----------
ok? 0; rank: 2
----------

Motivation

The class was written to be able to do complex, real standard and SVD solutions in a simple and fast way.

To Do

  • a thorough check if all loops are optimal in the makeNorm() methods
  • input of condition equations with cross covariance

Definition at line 328 of file LSQFit.h.

Member Enumeration Documentation

◆ ErrorField

Offset of fields in error_p data area.

Enumerator
NC 

Number of condition equations.

SUMWEIGHT 

Sum weights of condition equations.

SUMLL 

Sum known terms squared.

CHI2 

Calculated chi^2.

N_ErrorField 

Number of error fields.

Definition at line 355 of file LSQFit.h.

◆ ReadyCode

State of the non-linear solution.

Enumerator
NONREADY 
SOLINCREMENT 
DERIVLEVEL 
MAXITER 
NOREDUCTION 
SINGULAR 
N_ReadyCode 

Definition at line 345 of file LSQFit.h.

◆ StateBit

Bits that can be set/referenced.

Enumerator
INVERTED 

Inverted matrix present.

TRIANGLE 

Triangularised.

NONLIN 

Non-linear solution.

N_StateBit 

Filler for cxx2html.

Definition at line 829 of file LSQFit.h.

Constructor & Destructor Documentation

◆ LSQFit() [1/5]

casacore::LSQFit::LSQFit ( uInt nUnknowns,
uInt nConstraints = 0 )
explicit

Construct an object with the number of unknowns and constraints, using the default collinearity factor and the default Levenberg-Marquardt adjustment factor.

Assume real

◆ LSQFit() [2/5]

casacore::LSQFit::LSQFit ( uInt nUnknowns,
const LSQReal & ,
uInt nConstraints = 0 )

Allow explicit Real specification.

◆ LSQFit() [3/5]

casacore::LSQFit::LSQFit ( uInt nUnknowns,
const LSQComplex & ,
uInt nConstraints = 0 )

Allow explicit Complex specification.

◆ LSQFit() [4/5]

casacore::LSQFit::LSQFit ( )

Default constructor (empty, only usable after a set(nUnknowns))

◆ LSQFit() [5/5]

casacore::LSQFit::LSQFit ( const LSQFit & other)

Copy constructor (deep copy)

◆ ~LSQFit()

casacore::LSQFit::~LSQFit ( )

Member Function Documentation

◆ addConstraint() [1/4]

template<class U , class V >
Bool casacore::LSQFit::addConstraint ( const V & cEq,
const std::complex< U > & obs )

◆ addConstraint() [2/4]

template<class U , class V >
Bool casacore::LSQFit::addConstraint ( const V & cEq,
const U & obs )

◆ addConstraint() [3/4]

template<class U , class V , class W >
Bool casacore::LSQFit::addConstraint ( uInt nIndex,
const W & cEqIndex,
const V & cEq,
const std::complex< U > & obs )

◆ addConstraint() [4/4]

template<class U , class V , class W >
Bool casacore::LSQFit::addConstraint ( uInt nIndex,
const W & cEqIndex,
const V & cEq,
const U & obs )

◆ clear()

void casacore::LSQFit::clear ( )
protected

Clear areas.

◆ copy() [1/5]

template<class U >
void casacore::LSQFit::copy ( const Double * beg,
const Double * end,
U & sol,
LSQComplex  )

◆ copy() [2/5]

template<class U >
void casacore::LSQFit::copy ( const Double * beg,
const Double * end,
U & sol,
LSQReal  )

Copy date from beg to end; converting if necessary to complex data.

◆ copy() [3/5]

template<class U >
void casacore::LSQFit::copy ( const Double * beg,
const Double * end,
U * sol,
LSQComplex  )

◆ copy() [4/5]

template<class U >
void casacore::LSQFit::copy ( const Double * beg,
const Double * end,
U * sol,
LSQReal  )

◆ copy() [5/5]

void casacore::LSQFit::copy ( const LSQFit & other,
Bool all = True )
protected

Copy data.

If all False, only the relevant data for non-linear solution are copied (normal equations, knows and errors).

◆ copyDiagonal() [1/2]

template<class U >
void casacore::LSQFit::copyDiagonal ( U & errors,
LSQComplex  )

◆ copyDiagonal() [2/2]

template<class U >
void casacore::LSQFit::copyDiagonal ( U & errors,
LSQReal  )

◆ createNCEQ()

void casacore::LSQFit::createNCEQ ( )
protected

Create the solution equation area nceq_p and fill it.

◆ debugIt()

void casacore::LSQFit::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:

  • nun = number of unknowns
  • np = total number of solved unknowns (nun+ncon)
  • ncon = number of constraint equations
  • ner = number of elements in chi2 vector
  • rank = rank)
  • nEq = normal equation (nun*nun as triangular matrix)
  • known = known vector (np)
  • constr = constraint matrix (ncon*nun)
  • er = error info vector (ner)
  • piv = pivot vector (np)
  • sEq = normal solution equation (np*np triangular)
  • sol = internal solution vector (np)
  • prec = collinearity precision
  • nonlin = current Levenberg factor-1

Note that all pointers may be 0.

◆ deinit()

void casacore::LSQFit::deinit ( )
protected

De-initialise area.

◆ extendConstraints()

void casacore::LSQFit::extendConstraints ( uInt n)
protected

Extend the constraint equation area to the specify number of equations.

◆ fromAipsIO()

void casacore::LSQFit::fromAipsIO ( AipsIO & )

◆ fromRecord()

Bool casacore::LSQFit::fromRecord ( String & error,
const RecordInterface & in )

Create an LSQFit object from a record.

An error message is generated, and False returned if an invalid record is given. A valid record will return True. Error messages are postfixed to error.

◆ getChi()

Double casacore::LSQFit::getChi ( ) const

Get chi^2 (both are identical); the standard deviation (per observation) and the standard deviation per weight unit.

Referenced by casacore::GenericL2Fit< T >::chiSquare(), and getChi2().

◆ getChi2()

Double casacore::LSQFit::getChi2 ( ) const
inline

Definition at line 778 of file LSQFit.h.

References getChi().

◆ getConstraint() [1/3]

template<class U >
Bool casacore::LSQFit::getConstraint ( uInt n,
std::complex< U > * cEq ) const

◆ getConstraint() [2/3]

template<class U >
Bool casacore::LSQFit::getConstraint ( uInt n,
U & cEq ) const

◆ getConstraint() [3/3]

template<class U >
Bool casacore::LSQFit::getConstraint ( uInt n,
U * cEq ) const

Get the n-th (from 0 to the rank deficiency, or missing rank, see e.g.

getDeficiency()) constraint equation as determined by invert() in SVD-mode in cEq[nUnknown]. False returned for illegal n. Note that nMissing will be equal to the number of unknowns (nUnknowns, or double that for the complex case) minus the rank as returned from the invert() method.

◆ getCovariance() [1/2]

template<class U >
Bool casacore::LSQFit::getCovariance ( std::complex< U > * covar)

◆ getCovariance() [2/2]

template<class U >
Bool casacore::LSQFit::getCovariance ( U * covar)

Get the covariance matrix (of size nUnknowns * nUnknowns)

Referenced by casacore::LSQaips::getCovariance(), and casacore::LSQaips::getCovariance().

◆ getDeficiency()

uInt casacore::LSQFit::getDeficiency ( ) const
inline

Get the rank deficiency
Warning: Note that the number is returned assuming real values; For complex values it has to be halved

Definition at line 773 of file LSQFit.h.

References n_p, and r_p.

Referenced by casacore::GenericL2Fit< T >::getRank().

◆ getErrors() [1/3]

template<class U >
Bool casacore::LSQFit::getErrors ( std::complex< U > * errors)

◆ getErrors() [2/3]

template<class U >
Bool casacore::LSQFit::getErrors ( U & errors)

◆ getErrors() [3/3]

template<class U >
Bool casacore::LSQFit::getErrors ( U * errors)

Get main diagonal of covariance function (of size nUnknowns)

Referenced by casacore::LSQaips::getErrors(), casacore::LSQaips::getErrors(), casacore::LSQaips::getErrors(), and casacore::LSQaips::getErrors().

◆ getSD()

Double casacore::LSQFit::getSD ( ) const

◆ getWeightedSD()

Double casacore::LSQFit::getWeightedSD ( ) const

◆ getWorkCOV()

void casacore::LSQFit::getWorkCOV ( )
protected

◆ getWorkSOL()

void casacore::LSQFit::getWorkSOL ( )
protected

Get work areas for solutions, covariance.

◆ ident()

const String & casacore::LSQFit::ident ( ) const

Get identification of record.

◆ imagMC() [1/2]

static Double casacore::LSQFit::imagMC ( const std::complex< Double > & x,
const std::complex< Double > & y )
inlinestaticprotected

Definition at line 939 of file LSQFit.h.

◆ imagMC() [2/2]

static Float casacore::LSQFit::imagMC ( const std::complex< Float > & x,
const std::complex< Float > & y )
inlinestaticprotected

Definition at line 945 of file LSQFit.h.

◆ init()

void casacore::LSQFit::init ( )
protected

Initialise areas.

◆ invert()

Bool casacore::LSQFit::invert ( uInt & nRank,
Bool doSVD = False )

Triangularize the normal equations and determine the rank nRank of the normal equations and, in the case of an SVD solution, the constraint equations.

The collinearity factor is used to determine if the system can be solved (in essence it is the square of the sine of the angle between a column in the normal equations and the plane suspended by the other columns: if too parallel, the equations are degenerate). If doSVD is given as False, False is returned if rank not maximal, else an SVD solution is done.

◆ invertRect()

Bool casacore::LSQFit::invertRect ( )
protected

Invert rectangular matrix (i.e.

when constraints present)

◆ isReady()

LSQFit::ReadyCode casacore::LSQFit::isReady ( ) const
inline

Ask the state of the non-linear solutions.

Definition at line 747 of file LSQFit.h.

References ready_p.

◆ makeNorm() [1/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const std::vector< std::pair< uInt, V > > & cEq,
const U & weight,
const std::complex< U > & obs,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [2/22]

template<class U , class V >
void casacore::LSQFit::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 )

◆ makeNorm() [3/22]

template<class U , class V >
void casacore::LSQFit::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 )

◆ makeNorm() [4/22]

template<class U , class V >
void casacore::LSQFit::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 )

◆ makeNorm() [5/22]

template<class U , class V >
void casacore::LSQFit::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 )

◆ makeNorm() [6/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const std::vector< std::pair< uInt, V > > & cEq,
const U & weight,
const U & obs,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [7/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const std::vector< std::pair< uInt, V > > & cEq,
const U & weight,
const U & obs,
LSQFit::Real ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [8/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const V & cEq,
const U & weight,
const std::complex< U > & obs,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [9/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const V & cEq,
const U & weight,
const std::complex< U > & obs,
LSQFit::AsReal ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [10/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const V & cEq,
const U & weight,
const std::complex< U > & obs,
LSQFit::Complex ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [11/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const V & cEq,
const U & weight,
const std::complex< U > & obs,
LSQFit::Conjugate ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [12/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const V & cEq,
const U & weight,
const std::complex< U > & obs,
LSQFit::Separable ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [13/22]

template<class U , class V >
void casacore::LSQFit::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 weight weight, given the known observed value obs.

doNorm and doKnown can be used to e.g. re-use existing normal equations, i.e. the condition equations, but make a new known side (i.e. new observations).

The versions with cEqIndex[] indicate which of the nUnknowns are actually present in the condition equation (starting indexing at 0); the other terms are supposed to be zero. E.g. if a 12-telescope array has an equation only using telescopes 2 and 4, the lengths of cEqIndex and cEq will be both 2, and the index will contain 1 and 3 (when telescope numbering starts at 1) or 2 and 4 (when telescope numbering starts at 0. The index is given as an iterator (and hence can be a raw pointer)

The complex versions can have different interpretation of the inputs, where the complex number can be seen either as a complex number; as two real numbers, or as coefficients of equations with complex conjugates. See Note 224) for the details.

Versions with pair assume that the pairs are created by the SparseDiff automatic differentiation class. The pair is an index and a value. The indices are assumed to be sorted.

Special (makeNormSorted) indexed versions exist which assume that the given indices are sorted (which is the case for the LOFAR BBS environment).

Some versions exist with two sets of equations (cEq2, obs2). If two simultaneous equations are created they will be faster.

Note that the use of const U & is due to a Float->Double conversion problem on Solaris. Linux was ok.

◆ makeNorm() [14/22]

template<class U , class V >
void casacore::LSQFit::makeNorm ( const V & cEq,
const U & weight,
const U & obs,
LSQFit::Real ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [15/22]

template<class U , class V , class W >
void casacore::LSQFit::makeNorm ( uInt nIndex,
const W & cEqIndex,
const V & cEq,
const U & weight,
const std::complex< U > & obs,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [16/22]

template<class U , class V , class W >
void casacore::LSQFit::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 )

◆ makeNorm() [17/22]

template<class U , class V , class W >
void casacore::LSQFit::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 )

◆ makeNorm() [18/22]

template<class U , class V , class W >
void casacore::LSQFit::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 )

◆ makeNorm() [19/22]

template<class U , class V , class W >
void casacore::LSQFit::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 )

◆ makeNorm() [20/22]

template<class U , class V , class W >
void casacore::LSQFit::makeNorm ( uInt nIndex,
const W & cEqIndex,
const V & cEq,
const U & weight,
const U & obs,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [21/22]

template<class U , class V , class W >
void casacore::LSQFit::makeNorm ( uInt nIndex,
const W & cEqIndex,
const V & cEq,
const U & weight,
const U & obs,
LSQFit::Real ,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNorm() [22/22]

template<class U , class V , class W >
void casacore::LSQFit::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 )

◆ makeNormSorted() [1/2]

template<class U , class V , class W >
void casacore::LSQFit::makeNormSorted ( uInt nIndex,
const W & cEqIndex,
const V & cEq,
const U & weight,
const U & obs,
Bool doNorm = True,
Bool doKnown = True )

◆ makeNormSorted() [2/2]

template<class U , class V , class W >
void casacore::LSQFit::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 )

◆ merge() [1/4]

Bool casacore::LSQFit::merge ( const LSQFit & other)

Merge other LSQFit object (i.e.

the normal equation and related information) into this. Both objects must have the same number of unknowns, and be pure normal equations (i.e. no invert(), solve(), solveLoop() or statistics calls should have been made). If merging cannot be done, False is returned. The index case (the index is an iterator) assumes that the normal equations to be merged are a sparse subset of the complete matrix. The index 'vector' specifies which unknowns are present. An index outside the scope of the final equations will be skipped.
Tip: For highest numerical precision in the case of a larger number of partial normal equations to be merged, it is best to merge them in pairs (and repeat);

◆ merge() [2/4]

Bool casacore::LSQFit::merge ( const LSQFit & other,
uInt nIndex,
const std::vector< uInt > & nEqIndex )
inline

Definition at line 703 of file LSQFit.h.

References mergeIt().

◆ merge() [3/4]

Bool casacore::LSQFit::merge ( const LSQFit & other,
uInt nIndex,
const uInt * nEqIndex )
inline

Definition at line 701 of file LSQFit.h.

References mergeIt().

◆ merge() [4/4]

template<class W >
Bool casacore::LSQFit::merge ( const LSQFit & other,
uInt nIndex,
const W & nEqIndex )
inline

Definition at line 707 of file LSQFit.h.

References mergeIt().

◆ mergeIt()

Bool casacore::LSQFit::mergeIt ( const LSQFit & other,
uInt nIndex,
const uInt * nEqIndex )
protected

Merge sparse normal equations.

Referenced by merge(), merge(), and merge().

◆ nConstraints()

uInt casacore::LSQFit::nConstraints ( ) const
inline

Get the number of constraints.

Definition at line 769 of file LSQFit.h.

References ncon_p.

Referenced by set(), set(), set(), and set().

◆ nIterations()

uInt casacore::LSQFit::nIterations ( ) const
inline

Get number of iterations done.

Definition at line 742 of file LSQFit.h.

References maxiter_p, and niter_p.

◆ normInfKnown()

Double casacore::LSQFit::normInfKnown ( const Double * known) const
protected

Get the infinite norm of the known vector.

◆ normSolution()

Double casacore::LSQFit::normSolution ( const Double * sol) const
protected

Get the norm of the current solution vector.

◆ nUnknowns()

uInt casacore::LSQFit::nUnknowns ( ) const
inline

Get the number of unknowns.

Definition at line 767 of file LSQFit.h.

References nun_p.

Referenced by casacore::LSQaips::getErrors(), casacore::GenericL2Fit< T >::getRank(), set(), set(), set(), set(), and casacore::LSQaips::solve().

◆ operator=()

LSQFit & casacore::LSQFit::operator= ( const LSQFit & other)

Assignment (deep copy)

Referenced by casacore::LSQaips::operator=().

◆ readyText()

const std::string & casacore::LSQFit::readyText ( ) const

◆ realMC() [1/2]

static Double casacore::LSQFit::realMC ( const std::complex< Double > & x,
const std::complex< Double > & y )
inlinestaticprotected

Calculate the real or imag part of x*conj(y)

Definition at line 936 of file LSQFit.h.

◆ realMC() [2/2]

static Float casacore::LSQFit::realMC ( const std::complex< Float > & x,
const std::complex< Float > & y )
inlinestaticprotected

Definition at line 942 of file LSQFit.h.

◆ reset()

void casacore::LSQFit::reset ( )

Reset status to empty.

◆ restore()

void casacore::LSQFit::restore ( Bool all = True)
protected

Restore current status.

◆ rowrt()

Double * casacore::LSQFit::rowrt ( uInt i) const
inlineprotected

Get pointer in rectangular array.

Definition at line 931 of file LSQFit.h.

References lar_p, and n_p.

◆ rowru()

Double * casacore::LSQFit::rowru ( uInt i) const
inlineprotected

Definition at line 932 of file LSQFit.h.

References lar_p, and nun_p.

◆ save()

void casacore::LSQFit::save ( Bool all = True)
protected

Save current status (or part)

◆ set() [1/7]

void casacore::LSQFit::set ( Double factor = 1e-6,
Double LMFactor = 1e-3 )

Set new factors (collinearity factor, and Levenberg-Marquardt LMFactor)

◆ set() [2/7]

void casacore::LSQFit::set ( Int nUnknowns,
const LSQComplex & ,
Int nConstraints = 0 )
inline

Definition at line 727 of file LSQFit.h.

References nConstraints(), nUnknowns(), and set().

◆ set() [3/7]

void casacore::LSQFit::set ( Int nUnknowns,
const LSQReal & ,
Int nConstraints = 0 )
inline

Definition at line 723 of file LSQFit.h.

References nConstraints(), nUnknowns(), and set().

◆ set() [4/7]

void casacore::LSQFit::set ( Int nUnknowns,
Int nConstraints = 0 )
inline

Definition at line 717 of file LSQFit.h.

References nConstraints(), nUnknowns(), and set().

◆ set() [5/7]

void casacore::LSQFit::set ( uInt nUnknowns,
const LSQComplex & ,
uInt nConstraints = 0 )

◆ set() [6/7]

void casacore::LSQFit::set ( uInt nUnknowns,
const LSQReal & ,
uInt nConstraints = 0 )
inline

Definition at line 720 of file LSQFit.h.

References nConstraints(), nUnknowns(), and set().

◆ set() [7/7]

void casacore::LSQFit::set ( uInt nUnknowns,
uInt nConstraints = 0 )

Set new sizes (default is for Real)

Referenced by set(), set(), set(), and set().

◆ setBalanced()

void casacore::LSQFit::setBalanced ( Bool balanced = False)
inline

Set the expected form of the normal equations.

Definition at line 744 of file LSQFit.h.

References balanced_p.

◆ setConstraint() [1/4]

template<class U , class V >
Bool casacore::LSQFit::setConstraint ( uInt n,
const V & cEq,
const std::complex< U > & obs )

◆ setConstraint() [2/4]

template<class U , class V >
Bool casacore::LSQFit::setConstraint ( uInt n,
const V & cEq,
const U & obs )

Add a new constraint equation (updating nConstraints); or set a numbered constraint equation (0..nConstraints-1).

False if illegal number n. The constraints are equations with nUnknowns terms, and a constant value. E.g. measuring three angles of a triangle could lead to equation [1,1,1] with obs as 3.1415. Note that each complex constraint will be converted into two real constraints (see Note 224).

◆ setConstraint() [3/4]

template<class U , class V , class W >
Bool casacore::LSQFit::setConstraint ( uInt n,
uInt nIndex,
const W & cEqIndex,
const V & cEq,
const std::complex< U > & obs )

◆ setConstraint() [4/4]

template<class U , class V , class W >
Bool casacore::LSQFit::setConstraint ( uInt n,
uInt nIndex,
const W & cEqIndex,
const V & cEq,
const U & obs )

◆ setEpsDerivative()

void casacore::LSQFit::setEpsDerivative ( Double epsder = 1e-8)
inline

Set new derivative test.

Definition at line 738 of file LSQFit.h.

References epsder_p.

◆ setEpsValue()

void casacore::LSQFit::setEpsValue ( Double epsval = 1e-8)
inline

Set new value solution test.

Definition at line 736 of file LSQFit.h.

References epsval_p.

◆ setMaxIter()

void casacore::LSQFit::setMaxIter ( uInt maxiter = 0)
inline

Set maximum number of iterations.

Definition at line 740 of file LSQFit.h.

References maxiter_p.

◆ solve() [1/3]

template<class U >
void casacore::LSQFit::solve ( std::complex< U > * sol)

◆ solve() [2/3]

template<class U >
void casacore::LSQFit::solve ( U & sol)

◆ solve() [3/3]

template<class U >
void casacore::LSQFit::solve ( U * sol)

Solve normal equations.

The solution will be given in sol.

Referenced by casacore::LSQaips::solve(), casacore::LSQaips::solve(), casacore::LSQaips::solve(), and casacore::LSQaips::solve().

◆ solveIt()

void casacore::LSQFit::solveIt ( )
protected

Solve normal equations.

◆ solveItLoop()

Bool casacore::LSQFit::solveItLoop ( Double & fit,
uInt & nRank,
Bool doSVD = False )
protected

One non-linear LM loop.

◆ solveLoop() [1/6]

template<class U >
Bool casacore::LSQFit::solveLoop ( Double & fit,
uInt & nRank,
std::complex< U > * sol,
Bool doSVD = False )

◆ solveLoop() [2/6]

template<class U >
Bool casacore::LSQFit::solveLoop ( Double & fit,
uInt & nRank,
U & sol,
Bool doSVD = False )

◆ solveLoop() [3/6]

template<class U >
Bool casacore::LSQFit::solveLoop ( Double & fit,
uInt & nRank,
U * sol,
Bool doSVD = False )

◆ solveLoop() [4/6]

template<class U >
Bool casacore::LSQFit::solveLoop ( uInt & nRank,
std::complex< U > * sol,
Bool doSVD = False )

◆ solveLoop() [5/6]

template<class U >
Bool casacore::LSQFit::solveLoop ( uInt & nRank,
U & sol,
Bool doSVD = False )

◆ solveLoop() [6/6]

template<class U >
Bool casacore::LSQFit::solveLoop ( uInt & nRank,
U * sol,
Bool doSVD = False )

Solve a loop in a non-linear set.

The methods with the fit argument are deprecated. Use the combination without the 'fit' parameter, and the isReady() call. The 'fit' parameter returns for each loop a goodness of fit indicator. If it is >0; more loops are necessary. If it is negative, and has an absolute value of say less than.001, it is probably ok, and the iterations can be stopped. Other arguments are as for solve() and invert(). The sol is used for both input (parameter guess) and output.

Referenced by casacore::LSQaips::solveLoop(), casacore::LSQaips::solveLoop(), casacore::LSQaips::solveLoop(), casacore::LSQaips::solveLoop(), casacore::LSQaips::solveLoop(), and casacore::LSQaips::solveLoop().

◆ solveMR()

void casacore::LSQFit::solveMR ( uInt nin)
protected

Solve missing rank part.

◆ toAipsIO()

void casacore::LSQFit::toAipsIO ( AipsIO & ) const

Save or restore using AipsIO.

◆ toRecord()

Bool casacore::LSQFit::toRecord ( String & error,
RecordInterface & out ) const

Create a record from an LSQFit object.

The return will be False and an error message generated only if the object does not contain a valid object. Error messages are postfixed to error.

◆ uncopy() [1/4]

template<class U >
void casacore::LSQFit::uncopy ( Double * beg,
const Double * end,
U & sol,
LSQComplex  )

◆ uncopy() [2/4]

template<class U >
void casacore::LSQFit::uncopy ( Double * beg,
const Double * end,
U & sol,
LSQReal  )

◆ uncopy() [3/4]

template<class U >
void casacore::LSQFit::uncopy ( Double * beg,
const Double * end,
U * sol,
LSQComplex  )

◆ uncopy() [4/4]

template<class U >
void casacore::LSQFit::uncopy ( Double * beg,
const Double * end,
U * sol,
LSQReal  )

Member Data Documentation

◆ ASREAL

AsReal casacore::LSQFit::ASREAL
static

Definition at line 340 of file LSQFit.h.

◆ balanced_p

Bool casacore::LSQFit::balanced_p
protected

Indicator for a well balanced normal equation.

A balanced equation is one with similar values in the main diagonal.

Definition at line 890 of file LSQFit.h.

Referenced by setBalanced().

◆ COMPLEX

Complex casacore::LSQFit::COMPLEX
static

Definition at line 338 of file LSQFit.h.

◆ CONJUGATE

Conjugate casacore::LSQFit::CONJUGATE
static

Definition at line 341 of file LSQFit.h.

◆ constr

const String casacore::LSQFit::constr
staticprotected

Definition at line 852 of file LSQFit.h.

◆ constr_p

Double* casacore::LSQFit::constr_p
protected

Constraint equation area (nun_p*ncon_p))

Definition at line 915 of file LSQFit.h.

◆ epsder_p

Double casacore::LSQFit::epsder_p
protected

Test value for known vector in non-linear loop.

||known||inf is tested

Definition at line 887 of file LSQFit.h.

Referenced by setEpsDerivative().

◆ epsval_p

Double casacore::LSQFit::epsval_p
protected

Test value for [incremental] solution in non-linear loop.

The ||sol increment||/||sol|| is tested

Definition at line 884 of file LSQFit.h.

Referenced by setEpsValue().

◆ error_p

Double* casacore::LSQFit::error_p
protected

Counts for errors (N_ErrorField)

Definition at line 913 of file LSQFit.h.

◆ errors

const String casacore::LSQFit::errors
staticprotected

◆ known

const String casacore::LSQFit::known
staticprotected

Definition at line 853 of file LSQFit.h.

◆ known_p

Double* casacore::LSQFit::known_p
protected

Known part equations (n_p)

Definition at line 911 of file LSQFit.h.

◆ lar

const String casacore::LSQFit::lar
staticprotected

Definition at line 856 of file LSQFit.h.

◆ lar_p

Double* casacore::LSQFit::lar_p
protected

Save area for non-symmetric (i.e.

with constraints) (n_p * n_p)

Definition at line 921 of file LSQFit.h.

Referenced by rowrt(), and rowru().

◆ maxiter_p

uInt casacore::LSQFit::maxiter_p
protected

Maximum number of iterations for non-linear solution.

If a non-zero maximum number of iterations is set, the value is tested in non-linear loops

Definition at line 894 of file LSQFit.h.

Referenced by nIterations(), and setMaxIter().

◆ n_p

uInt casacore::LSQFit::n_p
protected

Matrix size (will be n_p = nun_p + ncon_p)

Definition at line 871 of file LSQFit.h.

Referenced by getDeficiency(), and rowrt().

◆ nar

const String casacore::LSQFit::nar
staticprotected

Definition at line 860 of file LSQFit.h.

◆ nar_p

LSQFit* casacore::LSQFit::nar_p
protected

Save area for non-linear case (size determined internally)

Definition at line 919 of file LSQFit.h.

◆ nceq

const String casacore::LSQFit::nceq
staticprotected

Definition at line 859 of file LSQFit.h.

◆ nceq_p

LSQMatrix* casacore::LSQFit::nceq_p
protected

Normal combined with constraint equations for solutions (triangular nnc_p*nnc_p)

Definition at line 909 of file LSQFit.h.

◆ ncon

const String casacore::LSQFit::ncon
staticprotected

Definition at line 845 of file LSQFit.h.

◆ ncon_p

uInt casacore::LSQFit::ncon_p
protected

Number of constraints.

Definition at line 869 of file LSQFit.h.

Referenced by nConstraints().

◆ niter_p

uInt casacore::LSQFit::niter_p
protected

Iteration count for non-linear solution.

Definition at line 896 of file LSQFit.h.

Referenced by nIterations().

◆ nnc

const String casacore::LSQFit::nnc
staticprotected

Definition at line 850 of file LSQFit.h.

◆ nnc_p

uInt casacore::LSQFit::nnc_p
protected

Current length nceq_p.

Definition at line 906 of file LSQFit.h.

◆ nonlin

const String casacore::LSQFit::nonlin
staticprotected

Definition at line 848 of file LSQFit.h.

◆ nonlin_p

Double casacore::LSQFit::nonlin_p
protected

Levenberg current factor.

Definition at line 879 of file LSQFit.h.

◆ norm_p

LSQMatrix* casacore::LSQFit::norm_p
protected

Normal equations (triangular nun_p * nun_p)

Definition at line 904 of file LSQFit.h.

◆ nun

const String casacore::LSQFit::nun
staticprotected

Definition at line 844 of file LSQFit.h.

◆ nun_p

uInt casacore::LSQFit::nun_p
protected

Number of unknowns.

Definition at line 867 of file LSQFit.h.

Referenced by nUnknowns(), and rowru().

◆ piv

const String casacore::LSQFit::piv
staticprotected

Definition at line 851 of file LSQFit.h.

◆ piv_p

uInt* casacore::LSQFit::piv_p
protected

Pivot table (n_p)

Definition at line 902 of file LSQFit.h.

◆ prec

const String casacore::LSQFit::prec
staticprotected

Definition at line 846 of file LSQFit.h.

◆ prec_p

Double casacore::LSQFit::prec_p
protected

Collinearity precision.

Definition at line 875 of file LSQFit.h.

◆ r_p

uInt casacore::LSQFit::r_p
protected

Rank of normal equations (normally n_p)

Definition at line 873 of file LSQFit.h.

Referenced by getDeficiency().

◆ rank

const String casacore::LSQFit::rank
staticprotected

Definition at line 849 of file LSQFit.h.

◆ ready_p

ReadyCode casacore::LSQFit::ready_p
protected

Indicate the non-linear state.

A non-zero code indicates that non-linear looping is ready.

Definition at line 899 of file LSQFit.h.

Referenced by isReady().

◆ REAL

Real casacore::LSQFit::REAL
static

And values to use.

Definition at line 337 of file LSQFit.h.

◆ recid

const String casacore::LSQFit::recid
staticprotected

Record field names.

Definition at line 842 of file LSQFit.h.

◆ SEPARABLE

Separable casacore::LSQFit::SEPARABLE
static

Definition at line 339 of file LSQFit.h.

◆ sol

◆ sol_p

Double* casacore::LSQFit::sol_p
protected

Solution area (n_p)

Definition at line 917 of file LSQFit.h.

◆ startnon

const String casacore::LSQFit::startnon
staticprotected

Definition at line 847 of file LSQFit.h.

◆ startnon_p

Double casacore::LSQFit::startnon_p
protected

Levenberg start factor.

Definition at line 877 of file LSQFit.h.

◆ state

const String casacore::LSQFit::state
staticprotected

Definition at line 843 of file LSQFit.h.

◆ state_p

uInt casacore::LSQFit::state_p
protected

Bits set to indicate state.

Definition at line 865 of file LSQFit.h.

◆ stepfactor_p

Double casacore::LSQFit::stepfactor_p
protected

Levenberg step factor.

Definition at line 881 of file LSQFit.h.

◆ wcov

const String casacore::LSQFit::wcov
staticprotected

Definition at line 858 of file LSQFit.h.

◆ wcov_p

Double* casacore::LSQFit::wcov_p
protected

Definition at line 925 of file LSQFit.h.

◆ wsol

const String casacore::LSQFit::wsol
staticprotected

Definition at line 857 of file LSQFit.h.

◆ wsol_p

Double* casacore::LSQFit::wsol_p
protected

Work areas for interim solutions and covariance.

Definition at line 924 of file LSQFit.h.


The documentation for this class was generated from the following file: