lsst.jointcal  15.0-7-gab4c137+2
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lsst::jointcal::FitterBase Class Referenceabstract

Base class for fitters. More...

#include <FitterBase.h>

Inheritance diagram for lsst::jointcal::FitterBase:
lsst::jointcal::AstrometryFit lsst::jointcal::PhotometryFit

Public Member Functions

 FitterBase (std::shared_ptr< Associations > associations)
 
 FitterBase (FitterBase const &)=delete
 No copy or move: there is only ever one fitter of a given type. More...
 
 FitterBase (FitterBase &&)=delete
 
FitterBaseoperator= (FitterBase const &)=delete
 
FitterBaseoperator= (FitterBase &&)=delete
 
MinimizeResult minimize (std::string const &whatToFit, double nSigmaCut=0)
 Does a 1 step minimization, assuming a linear model. More...
 
Chi2Statistic computeChi2 () const
 Returns the chi2 for the current state. More...
 
void leastSquareDerivatives (TripletList &tripletList, Eigen::VectorXd &grad) const
 Evaluates the chI^2 derivatives (Jacobian and gradient) for the current whatToFit setting. More...
 
virtual void offsetParams (Eigen::VectorXd const &delta)=0
 Offset the parameters by the requested quantities. More...
 
virtual void assignIndices (std::string const &whatToFit)=0
 Set parameters to fit and assign indices in the big matrix. More...
 
virtual void saveChi2Contributions (std::string const &baseName) const
 Save the full chi2 term per star that was used in the minimization, for debugging. More...
 
virtual void saveChi2MeasContributions (std::string const &baseName) const =0
 Save a CSV file containing residuals of measurement terms. More...
 
virtual void saveChi2RefContributions (std::string const &baseName) const =0
 Save a CSV file containing residuals of reference terms. More...
 

Protected Member Functions

unsigned findOutliers (double nSigmaCut, MeasuredStarList &msOutliers, FittedStarList &fsOutliers) const
 Find Measurements and references contributing more than a cut, computed as

\[ <chi2> + nSigmaCut + rms(chi2). \]

The outliers are NOT removed, and no refit is done. More...

 
void outliersContributions (MeasuredStarList &msOutliers, FittedStarList &fsOutliers, TripletList &tripletList, Eigen::VectorXd &grad)
 Contributions to derivatives from (presumably) outlier terms. More...
 
void removeMeasOutliers (MeasuredStarList &outliers)
 Remove measuredStar outliers from the fit. No Refit done. More...
 
void removeRefOutliers (FittedStarList &outliers)
 Remove refStar outliers from the fit. No Refit done. More...
 
virtual void getIndicesOfMeasuredStar (MeasuredStar const &measuredStar, std::vector< unsigned > &indices) const =0
 Set the indices of a measured star from the full matrix, for outlier removal. More...
 
virtual void accumulateStatImageList (CcdImageList const &ccdImageList, Chi2Accumulator &accum) const =0
 Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for measurements. More...
 
virtual void accumulateStatRefStars (Chi2Accumulator &accum) const =0
 Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for RefStars. More...
 
virtual void leastSquareDerivativesMeasurement (CcdImage const &ccdImage, TripletList &tripletList, Eigen::VectorXd &grad, MeasuredStarList const *measuredStarList=nullptr) const =0
 Compute the derivatives of the measured stars and model for one CcdImage. More...
 
virtual void leastSquareDerivativesReference (FittedStarList const &fittedStarList, TripletList &tripletList, Eigen::VectorXd &grad) const =0
 Compute the derivatives of the reference terms. More...
 

Protected Attributes

std::shared_ptr< Associations_associations
 
std::string _whatToFit
 
int _lastNTrip
 
unsigned int _nParTot
 
unsigned _nMeasuredStars
 
LOG_LOGGER _log
 

Detailed Description

Base class for fitters.

Implements minimize and findOutliers. Chi2, residual, derivative, etc. calculations must be implemented in the child class via the virtual methods.

Definition at line 29 of file FitterBase.h.

Constructor & Destructor Documentation

◆ FitterBase() [1/3]

lsst::jointcal::FitterBase::FitterBase ( std::shared_ptr< Associations associations)
inlineexplicit

Definition at line 31 of file FitterBase.h.

◆ FitterBase() [2/3]

lsst::jointcal::FitterBase::FitterBase ( FitterBase const &  )
delete

No copy or move: there is only ever one fitter of a given type.

◆ FitterBase() [3/3]

lsst::jointcal::FitterBase::FitterBase ( FitterBase &&  )
delete

Member Function Documentation

◆ accumulateStatImageList()

virtual void lsst::jointcal::FitterBase::accumulateStatImageList ( CcdImageList const &  ccdImageList,
Chi2Accumulator accum 
) const
protectedpure virtual

Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for measurements.

◆ accumulateStatRefStars()

virtual void lsst::jointcal::FitterBase::accumulateStatRefStars ( Chi2Accumulator accum) const
protectedpure virtual

Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for RefStars.

◆ assignIndices()

virtual void lsst::jointcal::FitterBase::assignIndices ( std::string const &  whatToFit)
pure virtual

Set parameters to fit and assign indices in the big matrix.

Parameters
[in]whatToFitSee child class documentation for valid string values.

Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.

◆ computeChi2()

Chi2Statistic lsst::jointcal::FitterBase::computeChi2 ( ) const

Returns the chi2 for the current state.

Definition at line 15 of file FitterBase.cc.

◆ findOutliers()

unsigned lsst::jointcal::FitterBase::findOutliers ( double  nSigmaCut,
MeasuredStarList msOutliers,
FittedStarList fsOutliers 
) const
protected

Find Measurements and references contributing more than a cut, computed as

\[ <chi2> + nSigmaCut + rms(chi2). \]

The outliers are NOT removed, and no refit is done.

After returning from here, there are still measurements that contribute above the cut, but their contribution should be evaluated after a refit before discarding them.

Parameters
[in]nSigmaCutNumber of sigma to select on.
[out]msOutlierslist of MeasuredStar outliers to populate
[out]fsOutlierslist of FittedStar outliers to populate
Returns
Total number of outliers that were removed.

Definition at line 25 of file FitterBase.cc.

◆ getIndicesOfMeasuredStar()

virtual void lsst::jointcal::FitterBase::getIndicesOfMeasuredStar ( MeasuredStar const &  measuredStar,
std::vector< unsigned > &  indices 
) const
protectedpure virtual

Set the indices of a measured star from the full matrix, for outlier removal.

◆ leastSquareDerivatives()

void lsst::jointcal::FitterBase::leastSquareDerivatives ( TripletList tripletList,
Eigen::VectorXd &  grad 
) const

Evaluates the chI^2 derivatives (Jacobian and gradient) for the current whatToFit setting.

The Jacobian is given as triplets in a sparse matrix, the gradient as a dense vector. The parameters which vary, and their indices, are to be set using assignIndices.

Parameters
tripletListtripletList of (row,col,value) representing the Jacobian of the chi2.
gradThe gradient of the chi2.

Definition at line 230 of file FitterBase.cc.

◆ leastSquareDerivativesMeasurement()

virtual void lsst::jointcal::FitterBase::leastSquareDerivativesMeasurement ( CcdImage const &  ccdImage,
TripletList tripletList,
Eigen::VectorXd &  grad,
MeasuredStarList const *  measuredStarList = nullptr 
) const
protectedpure virtual

Compute the derivatives of the measured stars and model for one CcdImage.

The last argument will process a sub-list for outlier removal.

◆ leastSquareDerivativesReference()

virtual void lsst::jointcal::FitterBase::leastSquareDerivativesReference ( FittedStarList const &  fittedStarList,
TripletList tripletList,
Eigen::VectorXd &  grad 
) const
protectedpure virtual

Compute the derivatives of the reference terms.

◆ minimize()

MinimizeResult lsst::jointcal::FitterBase::minimize ( std::string const &  whatToFit,
double  nSigmaCut = 0 
)

Does a 1 step minimization, assuming a linear model.

This is a complete Newton Raphson step. Compute first and second derivatives, solve for the step and apply it, without a line search.

It calls assignIndices, leastSquareDerivatives, solves the linear system and calls offsetParams, then removes outliers in a loop if requested. Relies on sparse linear algebra.

Parameters
[in]whatToFitSee child method assignIndices for valid string values.
[in]nSigmaCutHow many sigma to reject outliers at. Outlier rejection ignored for nSigmaCut=0.
Returns
Return code describing success/failure of fit.
Note
When fitting one parameter set by itself (e.g. "Model"), the system is purely linear, which should result in the optimal chi2 after a single step. This can be used to debug the fitter by fitting that parameter set twice in a row: the second run with the same "whatToFit" will produce no change in the fitted parameters, if the calculations and indices are defined correctly.

Definition at line 119 of file FitterBase.cc.

◆ offsetParams()

virtual void lsst::jointcal::FitterBase::offsetParams ( Eigen::VectorXd const &  delta)
pure virtual

Offset the parameters by the requested quantities.

The used parameter layout is the one from the last call to assignIndices or minimize(). There is no easy way to check that the current setting of whatToFit and the provided Delta vector are compatible: we can only test the size.

Parameters
[in]deltavector of offsets to apply

Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.

◆ operator=() [1/2]

FitterBase& lsst::jointcal::FitterBase::operator= ( FitterBase const &  )
delete

◆ operator=() [2/2]

FitterBase& lsst::jointcal::FitterBase::operator= ( FitterBase &&  )
delete

◆ outliersContributions()

void lsst::jointcal::FitterBase::outliersContributions ( MeasuredStarList msOutliers,
FittedStarList fsOutliers,
TripletList tripletList,
Eigen::VectorXd &  grad 
)
protected

Contributions to derivatives from (presumably) outlier terms.

No discarding done.

Definition at line 205 of file FitterBase.cc.

◆ removeMeasOutliers()

void lsst::jointcal::FitterBase::removeMeasOutliers ( MeasuredStarList outliers)
protected

Remove measuredStar outliers from the fit. No Refit done.

Definition at line 216 of file FitterBase.cc.

◆ removeRefOutliers()

void lsst::jointcal::FitterBase::removeRefOutliers ( FittedStarList outliers)
protected

Remove refStar outliers from the fit. No Refit done.

Definition at line 224 of file FitterBase.cc.

◆ saveChi2Contributions()

void lsst::jointcal::FitterBase::saveChi2Contributions ( std::string const &  baseName) const
virtual

Save the full chi2 term per star that was used in the minimization, for debugging.

Saves results to text files "baseName-meas.csv" and "baseName-ref.csv" for the MeasuredStar and RefStar contributions, respectively. This method is mostly useful for debugging: we will probably want to create a better persistence system for jointcal's internal representations in the future (see DM-12446).

Definition at line 238 of file FitterBase.cc.

◆ saveChi2MeasContributions()

virtual void lsst::jointcal::FitterBase::saveChi2MeasContributions ( std::string const &  baseName) const
pure virtual

Save a CSV file containing residuals of measurement terms.

Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.

◆ saveChi2RefContributions()

virtual void lsst::jointcal::FitterBase::saveChi2RefContributions ( std::string const &  baseName) const
pure virtual

Save a CSV file containing residuals of reference terms.

Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.

Member Data Documentation

◆ _associations

std::shared_ptr<Associations> lsst::jointcal::FitterBase::_associations
protected

Definition at line 114 of file FitterBase.h.

◆ _lastNTrip

int lsst::jointcal::FitterBase::_lastNTrip
protected

Definition at line 117 of file FitterBase.h.

◆ _log

LOG_LOGGER lsst::jointcal::FitterBase::_log
protected

Definition at line 122 of file FitterBase.h.

◆ _nMeasuredStars

unsigned lsst::jointcal::FitterBase::_nMeasuredStars
protected

Definition at line 119 of file FitterBase.h.

◆ _nParTot

unsigned int lsst::jointcal::FitterBase::_nParTot
protected

Definition at line 118 of file FitterBase.h.

◆ _whatToFit

std::string lsst::jointcal::FitterBase::_whatToFit
protected

Definition at line 115 of file FitterBase.h.


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