26#ifndef SCIMATH_LSQFIT_H 
   27#define SCIMATH_LSQFIT_H 
   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> 
  454           std::complex<U> *
sol,
 
  466           std::complex<U> *
sol,
 
  511  template <
class U, 
class V>
 
  512    void makeNorm(
const V &cEq, 
const U &weight, 
const U &obs,
 
  514  template <
class U, 
class V>
 
  515    void makeNorm(
const V &cEq, 
const U &weight, 
const U &obs,
 
  518  template <
class U, 
class V>
 
  520          const std::complex<U> &obs,
 
  522  template <
class U, 
class V>
 
  524          const std::complex<U> &obs,
 
  527  template <
class U, 
class V>
 
  529          const std::complex<U> &obs,
 
  532  template <
class U, 
class V>
 
  534          const std::complex<U> &obs,
 
  537  template <
class U, 
class V>
 
  539          const std::complex<U> &obs,
 
  543  template <
class U, 
class V, 
class W>
 
  545          const V &cEq, 
const U &weight, 
const U &obs,
 
  547  template <
class U, 
class V, 
class W>
 
  549          const V &cEq, 
const V &cEq2,
 
  550          const U &weight, 
const U &obs, 
const U &obs2,
 
  552  template <
class U, 
class V, 
class W>
 
  554          const V &cEq, 
const U &weight, 
const U &obs,
 
  557  template <
class U, 
class V, 
class W>
 
  559          const V &cEq, 
const U &weight,
 
  560          const std::complex<U> &obs,
 
  562  template <
class U, 
class V, 
class W>
 
  564          const V &cEq, 
const U &weight,
 
  565          const std::complex<U> &obs,
 
  568  template <
class U, 
class V, 
class W>
 
  570          const V &cEq, 
const U &weight,
 
  571          const std::complex<U> &obs,
 
  574  template <
class U, 
class V, 
class W>
 
  576          const V &cEq, 
const U &weight,
 
  577          const std::complex<U> &obs,
 
  580  template <
class U, 
class V, 
class W>
 
  582          const V &cEq, 
const U &weight,
 
  583          const std::complex<U> &obs,
 
  587  template <
class U, 
class V>
 
  588    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  589          const U &weight, 
const U &obs,
 
  591  template <
class U, 
class V>
 
  592    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  593          const U &weight, 
const U &obs,
 
  596  template <
class U, 
class V>
 
  597    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  599          const std::complex<U> &obs,
 
  601  template <
class U, 
class V>
 
  602    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  604          const std::complex<U> &obs,
 
  607  template <
class U, 
class V>
 
  608    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  610          const std::complex<U> &obs,
 
  613  template <
class U, 
class V>
 
  614    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  616          const std::complex<U> &obs,
 
  619  template <
class U, 
class V>
 
  620    void makeNorm(
const std::vector<std::pair<uInt, V> > &cEq,
 
  622          const std::complex<U> &obs,
 
  626  template <
class U, 
class V, 
class W>
 
  628              const V &cEq, 
const U &weight,
 
  631  template <
class U, 
class V, 
class W>
 
  633              const V &cEq, 
const V &cEq2, 
const U &weight,
 
  634              const U &obs, 
const U &obs2,
 
  661  template <
class U, 
class V>
 
  663  template <
class U, 
class V>
 
  665               const std::complex<U> &obs);
 
  666  template <
class U, 
class V, 
class W>
 
  668               const V &cEq, 
const U &obs);
 
  669  template <
class U, 
class V, 
class W>
 
  672               const std::complex<U> &obs);
 
  673  template <
class U, 
class V>
 
  675  template <
class U, 
class V>
 
  677               const std::complex<U> &obs);
 
  678  template <
class U, 
class V, 
class W>
 
  680               const V &cEq, 
const U &obs);
 
  681  template <
class U, 
class V, 
class W>
 
  684               const std::complex<U> &obs);
 
  702    return mergeIt(other, nIndex, nEqIndex); }
 
 
  704         const std::vector<uInt> &nEqIndex) {
 
  705    return mergeIt(other, nIndex, &nEqIndex[0]); }
 
 
  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]); }
 
 
  937               const std::complex<Double> &y) {
 
  938    return (x.real()*y.real() + x.imag()*y.imag()); };
 
 
  940               const std::complex<Double> &y) {
 
  941    return (x.imag()*y.real() - x.real()*y.imag()); };
 
 
  943               const std::complex<Float> &y) {
 
  944    return (x.real()*y.real() + x.imag()*y.imag()); };
 
 
  946               const std::complex<Float> &y) {
 
  947    return (x.imag()*y.real() - x.real()*y.imag()); };
 
 
 
  992#ifndef CASACORE_NO_AUTO_TEMPLATES 
  993#include <casacore/scimath/Fitting/LSQFit2.tcc> 
Type of complex numeric class indicator
 
Double stepfactor_p
Levenberg step factor.
 
void solve(U *sol)
Solve normal equations.
 
Double prec_p
Collinearity precision.
 
uInt nUnknowns() const
Get the number of unknowns.
 
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)
 
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
 
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
 
Double * wsol_p
Work areas for interim solutions and covariance.
 
Bool getCovariance(std::complex< U > *covar)
 
static const String recid
Record field names.
 
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.
 
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.
 
void makeNorm(const V &cEq, const U &weight, const std::complex< U > &obs, Bool doNorm=True, Bool doKnown=True)
 
static const String nonlin
 
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.
 
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)
 
static const String constr
 
LSQFit * nar_p
Save area for non-linear case (size determined internally)
 
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.
 
uInt state_p
Bits set to indicate state.
 
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
 
Double * rowrt(uInt i) const
Get pointer in rectangular array.
 
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.
 
Double * constr_p
Constraint equation area (nun_p*ncon_p))
 
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)
 
Bool getErrors(U &errors)
 
Bool solveLoop(Double &fit, uInt &nRank, U *sol, Bool doSVD=False)
 
uInt * piv_p
Pivot table (n_p)
 
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.
 
LSQMatrix * nceq_p
Normal combined with constraint equations for solutions (triangular nnc_p*nnc_p)
 
Bool addConstraint(const V &cEq, const std::complex< U > &obs)
 
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)
 
Double * lar_p
Save area for non-symmetric (i.e.
 
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.
 
static Double realMC(const std::complex< Double > &x, const std::complex< Double > &y)
Calculate the real or imag part of x*conj(y)
 
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)
 
static const String known
 
Bool setConstraint(uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
 
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)
 
void solve(std::complex< U > *sol)
 
void setMaxIter(uInt maxiter=0)
Set maximum number of iterations.
 
Bool getErrors(U *errors)
Get main diagonal of covariance function (of size nUnknowns)
 
void set(uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
 
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
 
uInt nConstraints() const
Get the number of constraints.
 
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 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)
 
void copy(const LSQFit &other, Bool all=True)
Copy data.
 
LSQFit()
Default constructor (empty, only usable after a set(nUnknowns))
 
Double * sol_p
Solution area (n_p)
 
Bool setConstraint(uInt n, uInt nIndex, const W &cEqIndex, const V &cEq, const U &obs)
 
void setEpsValue(Double epsval=1e-8)
Set new value solution test.
 
void getWorkSOL()
Get work areas for solutions, covariance.
 
static Double imagMC(const std::complex< Double > &x, const std::complex< Double > &y)
 
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)
 
uInt niter_p
Iteration count for non-linear solution.
 
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.
 
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)
 
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.
 
void setBalanced(Bool balanced=False)
Set the expected form of the normal equations.
 
void fromAipsIO(AipsIO &)
 
Bool balanced_p
Indicator for a well balanced normal equation.
 
void set(uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
 
void restore(Bool all=True)
Restore current status.
 
StateBit
Bits that can be set/referenced.
 
@ NONLIN
Non-linear solution.
 
@ TRIANGLE
Triangularised.
 
@ N_StateBit
Filler for cxx2html.
 
@ INVERTED
Inverted matrix present.
 
void uncopy(Double *beg, const Double *end, U &sol, LSQReal)
 
ErrorField
Offset of fields in error_p data area.
 
@ NC
Number of condition equations.
 
@ SUMWEIGHT
Sum weights of condition equations.
 
@ N_ErrorField
Number of error fields.
 
@ SUMLL
Sum known terms squared.
 
Bool merge(const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
 
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)
 
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.
 
static Float imagMC(const std::complex< Float > &x, const std::complex< Float > &y)
 
static const String startnon
 
uInt getDeficiency() const
Get the rank deficiency  Warning: Note that the number is returned assuming real values; For complex ...
 
void copyDiagonal(U &errors, LSQComplex)
 
static Real REAL
And values to use.
 
Bool mergeIt(const LSQFit &other, uInt nIndex, const uInt *nEqIndex)
Merge sparse normal equations.
 
ReadyCode
State of the non-linear solution.
 
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.
 
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
 
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 Float realMC(const std::complex< Float > &x, const std::complex< Float > &y)
 
void setEpsDerivative(Double epsder=1e-8)
Set new derivative test.
 
void solveMR(uInt nin)
Solve missing rank part.
 
void set(Int nUnknowns, const LSQReal &, Int nConstraints=0)
 
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)
 
LSQFit & operator=(const LSQFit &other)
Assignment (deep copy)
 
Bool addConstraint(uInt nIndex, const W &cEqIndex, const V &cEq, const std::complex< U > &obs)
 
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.
 
void copy(const Double *beg, const Double *end, U &sol, LSQComplex)
 
void copyDiagonal(U &errors, LSQReal)
 
String: the storage and methods of handling collections of characters.
 
this file contains all the compiler specific defines
 
bool Bool
Define the standard types used by Casacore.
 
LatticeExprNode all(const LatticeExprNode &expr)
 
Simple classes to overload templated memberfunctions.