FitLSQ.h

Classes

FitLSQ -- Interface for aips++ least squares fitting (full description)

class FitLSQ : public LSQ

Interface

Public Members
FitLSQ(uInt nUnknowns, uInt nKnowns=1, uInt nConstraints=0)
FitLSQ(uInt nUnknowns, LSQ::normType type, uInt nKnowns=1, uInt nConstraints=0)
explicit FitLSQ(Double *in)
explicit FitLSQ(Float *in)
explicit FitLSQ(DComplex *in)
explicit FitLSQ(Complex *in)
FitLSQ()
FitLSQ(const FitLSQ &other)
FitLSQ &operator=(const FitLSQ &other)
~FitLSQ()
void makeNorm(const Double cEq[], Double weight, const Double obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Double cEq[], Double weight, Double obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Float cEq[], Float weight, const Float obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Float cEq[], Float weight, Float obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const DComplex cEq[], Double weight, const DComplex obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const DComplex cEq[], Double weight, const DComplex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Complex cEq[], Float weight, const Complex obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Complex cEq[], Float weight, const Complex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Double> &cEq, Double weight, const Vector<Double> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Double> &cEq, Double weight, Double obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Float> &cEq, Float weight, const Vector<Float> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Float> &cEq, Float weight, Float obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<DComplex> &cEq, Double weight, const Vector<DComplex> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<DComplex> &cEq, Double weight, const DComplex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<DComplex> &cEq, const DComplex &weight, const DComplex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Complex> &cEq, Float weight, const Vector<Complex> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Complex> &cEq, Float weight, const Complex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Complex> &cEq, const Complex &weight, const Complex &obs, Bool doNorm=True, Bool doKnown=True)
void getConstraint(uInt &nMissing, Double *cEq) const
void getConstraint(uInt &nMissing, Array<Double> &cEq) const
void makeConstraint(const Double cEq[])
void makeConstraint(const Float cEq[])
void makeConstraint(const DComplex cEq[])
void makeConstraint(const Complex cEq[])
void makeConstraint(const Array<Double> &cEq)
void makeConstraint(const Array<Float> &cEq)
void makeConstraint(const Array<DComplex> &cEq)
void makeConstraint(const Array<Complex> &cEq)
void solve(Double sol[], Double sd[], Double mu[])
void solve(Float sol[], Double sd[], Double mu[])
void solve(Complex sol[], Double sd[], Double mu[])
void solve(DComplex sol[], Double sd[], Double mu[])
void solve(Vector<Double> &sol, Double &sd, Double &mu)
void solve(Vector<Float> &sol, Float &sd, Float &mu)
void solve(Vector<Float> &sol, Double &sd, Double &mu)
void solve(Vector<Complex> &sol, Float &sd, Float &mu)
void solve(Vector<Complex> &sol, Double &sd, Double &mu)
void solve(Vector<DComplex> &sol, Double &sd, Double &mu)
void solve(Array<Double> &sol, Vector<Double> &sd, Vector<Double> &mu)
void solve(Array<Float> &sol, Vector<Float> &sd, Vector<Float> &mu)
void solve(Array<Complex> &sol, Vector<Float> &sd, Vector<Float> &mu)
void solve(Array<DComplex> &sol, Vector<Double> &sd, Vector<Double> &mu)
Bool solveLoop(Double &fit, uInt &nRank, Double sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Float sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Complex sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, DComplex sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Double> &sol, Double &sd, Double &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Float> &sol, Double &sd, Double &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Float> &sol, Float &sd, Float &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Complex> &sol, Double &sd, Double &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Complex> &sol, Float &sd, Float &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<DComplex> &sol, Double &sd, Double &mu, Bool doSVD=False)
Bool getCovariance(Double covar[])
Bool getCovariance(Float covar[])
Bool getCovariance(DComplex *covar)
Bool getCovariance(Complex *covar)
Bool getCovariance(Array<Double> &covar)
Bool getCovariance(Array<Float> &covar)
Bool getCovariance(Array<DComplex> &covar)
Bool getCovariance(Array<Complex> &covar)
Bool getErrors(Double errors[])
Bool getErrors(Float errors[])
Bool getErrors(Vector<Double> &errors)
Bool getErrors(Vector<Float> &errors)
Bool getErrors(Vector<DComplex> &errors)
Bool getErrors(Vector<Complex> &errors)
Bool getErrors(Array<Double> &errors)
Bool getErrors(Array<Float> &errors)
Bool getErrors(Array<DComplex> &errors)
Bool getErrors(Array<Complex> &errors)

Description

Review Status

Reviewed By:
Neil Killeen
Date Reviewed:
2000/06/01
Programs:
Tests:

Prerequisite

Etymology

From Least SQuares and Fitting

Synopsis

The interface used in the FitLSQ class is in terms of aips++ Vectors, in addition to the builtin arrays used in the LSQ class. Its functionality is identical.

Example

See the tFitLSQ.cc program for extensive examples. The same example as given in the LSQBase class, but now with a Vector interface. See there for explanation.
   #include <aips/aips.h>
   #include <aips/Fitting/FitLSQ.h>
   #include <aips/Arrays/Vector.h>
    #include <iostream>
   
   int main() {
     // Condition equations for x+y=2; x-y=4;
     Double ce[2][2] = {{1, 1}, {1, -1}};
     Vector<Double> vce(2);
     Vector<Double> m(2);
     m(0) = 2; m(1) = 4;
     // Solution and error area
     Double sol[2];
     Double sd, mu;
     uInt rank;
     Bool ok;
   
     // LSQ area
     FitLSQ fit(2);
   
     // Make normal equation
     for (uInt i=0; i<2; i++) {
       for (uInt j=0; j<2; j++) vce(j) = ce[i][j];
       fit.makeNorm(vce, 1.0, m(i));
     };
     // Invert 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; 
   
     exit(0);
   }
   
Which produces:
   ok? 1; rank: 2
   Sol0: 3
   Sol1: -1
   sd: 0; mu: 0
   ----------

Motivation

The class was written to be able to interface Fitting routines to the least squares solution classes.

To Do

Member Description

FitLSQ(uInt nUnknowns, uInt nKnowns=1, uInt nConstraints=0)

Construct an object with the number of unknown, knowns and constraints, and type, using the default collinearity factor and the default Levenberg-Marquardt adjustment factor

Assume real

FitLSQ(uInt nUnknowns, LSQ::normType type, uInt nKnowns=1, uInt nConstraints=0)

Construct an object with the number of unknown, knowns and constraints, and type, using the default collinearity factor and the default Levenberg-Marquardt adjustment factor

Allow explicit complex/real specification

explicit FitLSQ(Double *in)
explicit FitLSQ(Float *in)
explicit FitLSQ(DComplex *in)
explicit FitLSQ(Complex *in)

Allow default real/complex. Use it e.g. to create a default complex object:
    myFit = FitLSQ(static_cast<Complex *>(0));

FitLSQ()

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

FitLSQ(const FitLSQ &other)

Copy constructor (deep copy)

FitLSQ &operator=(const FitLSQ &other)

Assignment (deep copy)

~FitLSQ()

void makeNorm(const Double cEq[], Double weight, const Double obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Double cEq[], Double weight, Double obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Float cEq[], Float weight, const Float obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Float cEq[], Float weight, Float obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const DComplex cEq[], Double weight, const DComplex obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const DComplex cEq[], Double weight, const DComplex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Complex cEq[], Float weight, const Complex obs[], Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Complex cEq[], Float weight, const Complex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Double> &cEq, Double weight, const Vector<Double> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Double> &cEq, Double weight, Double obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Float> &cEq, Float weight, const Vector<Float> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Float> &cEq, Float weight, Float obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<DComplex> &cEq, Double weight, const Vector<DComplex> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<DComplex> &cEq, Double weight, const DComplex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<DComplex> &cEq, const DComplex &weight, const DComplex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Complex> &cEq, Float weight, const Vector<Complex> &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Complex> &cEq, Float weight, const Complex &obs, Bool doNorm=True, Bool doKnown=True)
void makeNorm(const Vector<Complex> &cEq, const Complex &weight, const Complex &obs, Bool doNorm=True, Bool doKnown=True)

Make normal equations using the cEq condition equations (with nUnknowns elements) and a weight weight, given the known observed values obs (with nKnowns elements). doNorm and doKnown can be used to e.g. re-use existing normal equations, but make a new known side.

void getConstraint(uInt &nMissing, Double *cEq) const
void getConstraint(uInt &nMissing, Array<Double> &cEq) const

Get the nMissing (the rank deficiency, or missing rank) constraint equations as cEq[nUnknowns][nMissing]. 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.

void makeConstraint(const Double cEq[])
void makeConstraint(const Float cEq[])
void makeConstraint(const DComplex cEq[])
void makeConstraint(const Complex cEq[])
void makeConstraint(const Array<Double> &cEq)
void makeConstraint(const Array<Float> &cEq)
void makeConstraint(const Array<DComplex> &cEq)
void makeConstraint(const Array<Complex> &cEq)

Set constraint equations cEq (with [nUnknowns][nConstraints] elements).

void solve(Double sol[], Double sd[], Double mu[])
void solve(Float sol[], Double sd[], Double mu[])
void solve(Complex sol[], Double sd[], Double mu[])
void solve(DComplex sol[], Double sd[], Double mu[])
void solve(Vector<Double> &sol, Double &sd, Double &mu)
void solve(Vector<Float> &sol, Float &sd, Float &mu)
void solve(Vector<Float> &sol, Double &sd, Double &mu)
void solve(Vector<Complex> &sol, Float &sd, Float &mu)
void solve(Vector<Complex> &sol, Double &sd, Double &mu)
void solve(Vector<DComplex> &sol, Double &sd, Double &mu)
void solve(Array<Double> &sol, Vector<Double> &sd, Vector<Double> &mu)
void solve(Array<Float> &sol, Vector<Float> &sd, Vector<Float> &mu)
void solve(Array<Complex> &sol, Vector<Float> &sd, Vector<Float> &mu)
void solve(Array<DComplex> &sol, Vector<Double> &sd, Vector<Double> &mu)

Solve normal equations. The solution will be given in sol, with the adjustment error mu, and the standard deviation sd. I.e. mu is per unit weight, sd per observation. In the cases where the solution is returned in a Vector, the Array given as input will be resized and reshaped (if necessary), to the properly sized Vector.

Bool solveLoop(Double &fit, uInt &nRank, Vector<Float> &sol, Double &sd, Double &mu, Bool doSVD=False)

Solve a Levenberg-Marquardt loop. Note that the solution sol is used both and input and output. No check on the size is done.

Remove this when Traits updated

Bool solveLoop(Double &fit, uInt &nRank, Vector<Complex> &sol, Double &sd, Double &mu, Bool doSVD=False)

Solve a Levenberg-Marquardt loop. Note that the solution sol is used both and input and output. No check on the size is done.

Remove this when Traits updated

Bool solveLoop(Double &fit, uInt &nRank, Double sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Float sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Complex sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, DComplex sol[], Double sd[], Double mu[], Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Double> &sol, Double &sd, Double &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Float> &sol, Float &sd, Float &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<Complex> &sol, Float &sd, Float &mu, Bool doSVD=False)
Bool solveLoop(Double &fit, uInt &nRank, Vector<DComplex> &sol, Double &sd, Double &mu, Bool doSVD=False)

Solve a Levenberg-Marquardt loop. Note that the solution sol is used both and input and output. No check on the size is done.

Bool getCovariance(Double covar[])
Bool getCovariance(Float covar[])
Bool getCovariance(DComplex *covar)
Bool getCovariance(Complex *covar)
Bool getCovariance(Array<Double> &covar)
Bool getCovariance(Array<Float> &covar)
Bool getCovariance(Array<DComplex> &covar)
Bool getCovariance(Array<Complex> &covar)

Get the covariance matrix. False if an error occurred (of size nUnknowns * nUnknowns)

Bool getErrors(Double errors[])
Bool getErrors(Float errors[])
Bool getErrors(Vector<Double> &errors)
Bool getErrors(Vector<Float> &errors)
Bool getErrors(Vector<DComplex> &errors)
Bool getErrors(Vector<Complex> &errors)
Bool getErrors(Array<Double> &errors)
Bool getErrors(Array<Float> &errors)
Bool getErrors(Array<DComplex> &errors)
Bool getErrors(Array<Complex> &errors)

Get the errors for the individual unknowns. False if an error occurred. (of size nUnknowns)