LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
|
Base class for fitters. More...
#include <FitterBase.h>
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. | |
FitterBase (FitterBase &&)=delete | |
FitterBase & | operator= (FitterBase const &)=delete |
FitterBase & | operator= (FitterBase &&)=delete |
MinimizeResult | minimize (std::string const &whatToFit, double nSigmaCut=0, double sigmaRelativeTolerance=0, bool doRankUpdate=true, bool doLineSearch=false, std::string const &dumpMatrixFile="") |
Does a 1 step minimization, assuming a linear model. | |
Chi2Statistic | computeChi2 () const |
Returns the chi2 for the current state. | |
void | leastSquareDerivatives (TripletList &tripletList, Eigen::VectorXd &grad) const |
Evaluates the chI^2 derivatives (Jacobian and gradient) for the current whatToFit setting. | |
virtual void | offsetParams (Eigen::VectorXd const &delta)=0 |
Offset the parameters by the requested quantities. | |
virtual void | assignIndices (std::string const &whatToFit)=0 |
Set parameters to fit and assign indices in the big matrix. | |
virtual void | saveChi2Contributions (std::string const &baseName) const |
Save the full chi2 term per star that was used in the minimization, for debugging. | |
virtual | ~FitterBase ()=default |
Protected Member Functions | |
virtual void | saveChi2MeasContributions (std::string const &filename) const =0 |
Save a CSV file containing residuals of measurement terms. | |
virtual void | saveChi2RefContributions (std::string const &filename) const =0 |
Save a CSV file containing residuals of reference terms. | |
std::size_t | findOutliers (double nSigmaCut, MeasuredStarList &msOutliers, FittedStarList &fsOutliers, double &cut) const |
Find Measurements and references contributing more than a cut, computed as. | |
void | outliersContributions (MeasuredStarList &msOutliers, FittedStarList &fsOutliers, TripletList &tripletList, Eigen::VectorXd &grad) |
Contributions to derivatives from (presumably) outlier terms. | |
void | removeMeasOutliers (MeasuredStarList &outliers) |
Remove measuredStar outliers from the fit. No Refit done. | |
void | removeRefOutliers (FittedStarList &outliers) |
Remove refStar outliers from the fit. No Refit done. | |
virtual void | getIndicesOfMeasuredStar (MeasuredStar const &measuredStar, IndexVector &indices) const =0 |
Set the indices of a measured star from the full matrix, for outlier removal. | |
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. | |
virtual void | accumulateStatRefStars (Chi2Accumulator &accum) const =0 |
Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for RefStars. | |
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. | |
virtual void | leastSquareDerivativesReference (FittedStarList const &fittedStarList, TripletList &tripletList, Eigen::VectorXd &grad) const =0 |
Compute the derivatives of the reference terms. | |
Protected Attributes | |
std::shared_ptr< Associations > | _associations |
std::string | _whatToFit |
Eigen::Index | _lastNTrip |
Eigen::Index | _nTotal |
Eigen::Index | _nModelParams |
Eigen::Index | _nStarParams |
LOG_LOGGER | _log |
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 55 of file FitterBase.h.
|
inlineexplicit |
Definition at line 57 of file FitterBase.h.
|
delete |
No copy or move: there is only ever one fitter of a given type.
|
delete |
|
virtualdefault |
|
protectedpure virtual |
Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for measurements.
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
|
protectedpure virtual |
Compute the chi2 (per star or total, depending on which Chi2Accumulator is used) for RefStars.
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
|
pure virtual |
Set parameters to fit and assign indices in the big matrix.
[in] | whatToFit | See child class documentation for valid string values. |
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
Chi2Statistic lsst::jointcal::FitterBase::computeChi2 | ( | ) | const |
Returns the chi2 for the current state.
Definition at line 43 of file FitterBase.cc.
|
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.
[in] | nSigmaCut | Number of sigma to select on. |
[out] | msOutliers | list of MeasuredStar outliers to populate |
[out] | fsOutliers | list of FittedStar outliers to populate |
[out] | cut | value of chi2 that defines which objects are outliers |
Definition at line 53 of file FitterBase.cc.
|
protectedpure virtual |
Set the indices of a measured star from the full matrix, for outlier removal.
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
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.
tripletList | tripletList of (row,col,value) representing the Jacobian of the chi2. |
grad | The gradient of the chi2. |
Definition at line 347 of file FitterBase.cc.
|
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.
Implemented in lsst::jointcal::PhotometryFit, and lsst::jointcal::AstrometryFit.
|
protectedpure virtual |
Compute the derivatives of the reference terms.
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
MinimizeResult lsst::jointcal::FitterBase::minimize | ( | std::string const & | whatToFit, |
double | nSigmaCut = 0, | ||
double | sigmaRelativeTolerance = 0, | ||
bool | doRankUpdate = true, | ||
bool | doLineSearch = false, | ||
std::string const & | dumpMatrixFile = "" ) |
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, with an optional 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 via Eigen's CholmodSupport package.
[in] | whatToFit | See child method assignIndices for valid string values. |
[in] | nSigmaCut | How many sigma to reject outliers at. Outlier rejection ignored for nSigmaCut=0. |
[in] | sigmaRelativeTolerance | Percentage change in the chi2 cut for outliers tolerated for termination. If value is zero, minimization iterations will continue until there are no outliers. |
[in] | doRankUpdate | Use CholmodSimplicialLDLT2.update() to do a fast rank update after outlier removal; otherwise do a slower full recomputation of the matrix. Only matters if nSigmaCut != 0. |
[in] | doLineSearch | Use boost's brent_find_minima to perform a line search after the gradient solution is found, and apply the scale factor to the computed offsets. The line search is done in the domain [-1, 2], but if the scale factor is far from 1.0, then the problem is likely in a significantly non-linear regime. |
[in] | dumpMatrixFile | Write the pre-fit Hessian matrix and gradient to the files with "-mat.txt" and "-grad.txt". Be aware, this requires a large increase in memory usage to create a dense matrix before writing it; the output file may be large. Writing the matrix can be helpful for debugging bad fits. Read it and compute the real eigenvalues (recall that the Hessian is symmetric by construction) with numpy: hessian = np.matrix(np.loadtxt("dumpMatrixFile-mat.txt"))
values, vectors = np.linalg.eigh(hessian)
|
Definition at line 179 of file FitterBase.cc.
|
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.
[in] | delta | vector of offsets to apply |
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
|
delete |
|
delete |
|
protected |
Contributions to derivatives from (presumably) outlier terms.
No discarding done.
Definition at line 322 of file FitterBase.cc.
|
protected |
Remove measuredStar outliers from the fit. No Refit done.
Definition at line 333 of file FitterBase.cc.
|
protected |
Remove refStar outliers from the fit. No Refit done.
Definition at line 341 of file FitterBase.cc.
|
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 355 of file FitterBase.cc.
|
protectedpure virtual |
Save a CSV file containing residuals of measurement terms.
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
|
protectedpure virtual |
Save a CSV file containing residuals of reference terms.
Implemented in lsst::jointcal::AstrometryFit, and lsst::jointcal::PhotometryFit.
|
protected |
Definition at line 165 of file FitterBase.h.
|
protected |
Definition at line 168 of file FitterBase.h.
|
protected |
Definition at line 174 of file FitterBase.h.
|
protected |
Definition at line 170 of file FitterBase.h.
|
protected |
Definition at line 171 of file FitterBase.h.
|
protected |
Definition at line 169 of file FitterBase.h.
|
protected |
Definition at line 166 of file FitterBase.h.