LSSTApplications
20.0.0
LSSTDataManagementBasePackage
|
Go to the documentation of this file.
24 #ifndef LSST_MEAS_MODELFIT_optimizer_h_INCLUDED
25 #define LSST_MEAS_MODELFIT_optimizer_h_INCLUDED
35 namespace lsst {
namespace meas {
namespace modelfit {
91 ndarray::Array<Scalar const,2,1>
const & parameters,
92 ndarray::Array<Scalar,1,1>
const & output
104 ndarray::Array<Scalar const,1,1>
const & parameters,
105 ndarray::Array<Scalar,1,1>
const & residuals
122 ndarray::Array<Scalar const,1,1>
const & parameters,
123 ndarray::Array<Scalar,2,-2>
const & derivatives
142 virtual Scalar computePrior(ndarray::Array<Scalar const,1,1>
const & parameters)
const {
return 1.0; }
159 ndarray::Array<Scalar const,1,1>
const & parameters,
160 ndarray::Array<Scalar,1,1>
const & gradient,
161 ndarray::Array<Scalar,2,1>
const & hessian
163 gradient.deep() = 0.0;
164 hessian.deep() = 0.0;
191 "If true, ignore the SR1 update term in the Hessian, resulting in a Levenberg-Marquardt-like method"
196 "Skip the SR1 update if |v||s| / (|v||s|) is less than this threshold"
201 "If the trust radius falls below this threshold, consider the algorithm converged"
206 "If the maximum of the gradient falls below this threshold, consider the algorithm converged"
211 "relative step size used for numerical derivatives (added to other steps)"
216 "absolute step size used for numerical derivatives (added to other steps)"
221 "step size (in units of trust radius) used for numerical derivatives (added to relative step)"
226 "steps with reduction ratio greater than this are accepted"
231 "the initial trust region will be set to this value"
236 "steps with reduction radio greater than this may increase the trust radius"
241 "steps with length this fraction of the trust radius may increase the trust radius"
246 "when increase the trust region size, multiply the radius by this factor"
251 "steps with reduction radio less than this will decrease the trust radius"
256 "when reducing the trust region size, multiply the radius by this factor"
261 "value passed as the tolerance to solveTrustRegion"
266 "maximum number of iterations (i.e. function evaluations and trust region subproblems) per step"
271 "maximum number of steps"
276 "whether to save all iterations for debugging purposes"
304 bool doRecordDerivatives
317 ndarray::Array<Scalar const,1,1>
const &
nested,
329 ndarray::Array<Scalar const,1,1>
const &
nested,
330 ndarray::Array<Scalar,1,1>
const & gradient,
331 ndarray::Array<Scalar,2,2>
const & hessian
336 ndarray::Array<Scalar,1,1>
const & gradient,
337 ndarray::Array<Scalar,2,2>
const & hessian
342 ndarray::Array<Scalar const,2,1>
const &
parameters,
343 ndarray::Array<Scalar,1,1>
const & output
428 ndarray::Array<Scalar const,1,1>
const & parameters,
436 bool step() {
return _stepImpl(0); }
439 return _stepImpl(0, &recorder, &history);
442 int run() {
return _runImpl(); }
445 return _runImpl(&recorder, &history);
452 ndarray::Array<Scalar const,1,1>
getParameters()
const {
return _current.parameters; }
454 ndarray::Array<Scalar const,1,1>
getResiduals()
const {
return _current.residuals; }
456 ndarray::Array<Scalar const,1,1>
getGradient()
const {
return _gradient; }
458 ndarray::Array<Scalar const,2,2>
getHessian()
const {
return _hessian; }
465 struct IterationData {
468 ndarray::Array<Scalar,1,1> parameters;
469 ndarray::Array<Scalar,1,1> residuals;
471 IterationData(
int dataSize,
int parameterSize);
486 void _computeDerivatives();
492 IterationData _current;
494 ndarray::Array<Scalar,1,1> _step;
495 ndarray::Array<Scalar,1,1> _gradient;
496 ndarray::Array<Scalar,2,2> _hessian;
497 ndarray::Array<
Scalar,2,-2> _residualDerivative;
519 ndarray::Array<Scalar,1,1>
const &
x,
520 ndarray::Array<Scalar const,2,1>
const & F, ndarray::Array<Scalar const,1,1>
const & g,
521 double r,
double tolerance
526 #endif // !LSST_MEAS_MODELFIT_optimizer_h_INCLUDED
void fillObjectiveModelGrid(afw::table::BaseRecord const &record, ndarray::Array< Scalar const, 2, 1 > const ¶meters, ndarray::Array< Scalar, 1, 1 > const &output) const
double skipSR1UpdateThreshold
"Skip the SR1 update if |v||s| / (|v||s|) is less than this threshold" ;
OptimizerHistoryRecorder(afw::table::Schema const &schema)
bool doSaveIterations
"whether to save all iterations for debugging purposes" ;
boost::shared_ptr< Objective const > getObjective() const
OptimizerHistoryRecorder(afw::table::Schema &schema, boost::shared_ptr< Model > model, bool doRecordDerivatives)
void unpackDerivatives(afw::table::BaseRecord const &record, Vector &gradient, Matrix &hessian) const
void unpackDerivatives(afw::table::BaseRecord const &record, ndarray::Array< Scalar, 1, 1 > const &gradient, ndarray::Array< Scalar, 2, 2 > const &hessian) const
double trustRegionInitialSize
"the initial trust region will be set to this value" ;
Base class for Bayesian priors.
OptimizerHistoryRecorder HistoryRecorder
void removeSR1Term()
Remove the symmetric-rank-1 secant term from the Hessian, making it just (J^T J)
double numDiffRelStep
"relative step size used for numerical derivatives (added to other steps)" ;
ndarray::Array< Scalar const, 1, 1 > getResiduals() const
void fillObjectiveValueGrid(ndarray::Array< Scalar const, 2, 1 > const ¶meters, ndarray::Array< Scalar, 1, 1 > const &output) const
Evaluate the Objective on a 1-d grid.
double Scalar
Typedefs to be used for probability and parameter values.
OptimizerObjective(int dataSize_, int parameterSize_)
Base class constructor; must be called by all subclasses.
Abstract base class and concrete factories that define multi-shapelet galaxy models.
Defines the fields and offsets for a table.
Scalar getObjectiveValue() const
bool step(HistoryRecorder const &recorder, afw::table::BaseCatalog &history)
@ FAILED_MAX_OUTER_ITERATIONS
afw::table::Key< int > outer
Base class for optimizer/sampler likelihood functions that compute likelihood at a point.
double trustRegionShrinkReductionRatio
"steps with reduction radio less than this will decrease the trust radius" ;
Base class for objective functions for Optimizer.
Control const & getControl() const
virtual ~OptimizerObjective()
Configuration object for Optimizer.
int maxInnerIterations
"maximum number of iterations (i.e. function evaluations and trust region subproblems) per step" ;
Optimizer(boost::shared_ptr< Objective const > objective, ndarray::Array< Scalar const, 1, 1 > const ¶meters, Control const &ctrl)
double trustRegionShrinkFactor
"when reducing the trust region size, multiply the radius by this factor" ;
virtual Scalar computePrior(ndarray::Array< Scalar const, 1, 1 > const ¶meters) const
Compute the value of the Bayesian prior for the given parameter vector.
ItemVariant const * other
Base class for all records.
double stepAcceptThreshold
"steps with reduction ratio greater than this are accepted" ;
void solveTrustRegion(ndarray::Array< Scalar, 1, 1 > const &x, ndarray::Array< Scalar const, 2, 1 > const &F, ndarray::Array< Scalar const, 1, 1 > const &g, double r, double tolerance)
Solve a symmetric quadratic matrix equation with a ball constraint.
virtual void differentiatePrior(ndarray::Array< Scalar const, 1, 1 > const ¶meters, ndarray::Array< Scalar, 1, 1 > const &gradient, ndarray::Array< Scalar, 2, 1 > const &hessian) const
Compute the first and second derivatives of the Bayesian prior with respect to the parameters.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
bool noSR1Term
"If true, ignore the SR1 update term in the Hessian, resulting in a Levenberg-Marquardt-like method" ...
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
A preprocessor macro used to define fields in C++ "control object" structs.
afw::table::Key< int > inner
A numerical optimizer customized for least-squares problems with Bayesian priors.
A base class for image defects.
@ FAILED_MAX_INNER_ITERATIONS
void unpackDerivatives(ndarray::Array< Scalar const, 1, 1 > const &nested, Vector &gradient, Matrix &hessian) const
virtual bool differentiateResiduals(ndarray::Array< Scalar const, 1, 1 > const ¶meters, ndarray::Array< Scalar, 2,-2 > const &derivatives) const
Evaluate analytic derivatives of the model or signal that they are not available.
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
virtual bool hasPrior() const
Return true if the Objective has a Bayesian prior as well as a likelihood.
ndarray::Array< Scalar const, 1, 1 > getParameters() const
int run(HistoryRecorder const &recorder, afw::table::BaseCatalog &history)
double numDiffTrustRadiusStep
"step size (in units of trust radius) used for numerical derivatives (added to relative step)" ;
ndarray::Array< Scalar const, 2, 2 > getHessian() const
int maxOuterIterations
"maximum number of steps" ;
virtual void computeResiduals(ndarray::Array< Scalar const, 1, 1 > const ¶meters, ndarray::Array< Scalar, 1, 1 > const &residuals) const =0
Evaluate the residuals of the model for a given parameter vector.
afw::table::Key< int > state
void apply(int outerIterCount, int innerIterCount, afw::table::BaseCatalog &history, Optimizer const &optimizer) const
OptimizerObjective Objective
double trustRegionGrowStepFraction
"steps with length this fraction of the trust radius may increase the trust radius" ;
void swap(CameraSys &a, CameraSys &b)
double trustRegionGrowFactor
"when increase the trust region size, multiply the radius by this factor" ;
double trustRegionSolverTolerance
"value passed as the tolerance to solveTrustRegion" ;
double trustRegionGrowReductionRatio
"steps with reduction radio greater than this may increase the trust radius" ;
void unpackDerivatives(ndarray::Array< Scalar const, 1, 1 > const &nested, ndarray::Array< Scalar, 1, 1 > const &gradient, ndarray::Array< Scalar, 2, 2 > const &hessian) const
ndarray::Array< Scalar const, 1, 1 > getGradient() const
static boost::shared_ptr< OptimizerObjective > makeFromLikelihood(boost::shared_ptr< Likelihood > likelihood, boost::shared_ptr< Prior > prior=boost::shared_ptr< Prior >())
Return a concrete Objective object built from a Likelihood and Prior.
double minTrustRadiusThreshold
"If the trust radius falls below this threshold, consider the algorithm converged" ;
double gradientThreshold
"If the maximum of the gradient falls below this threshold, consider the algorithm converged" ;
double numDiffAbsStep
"absolute step size used for numerical derivatives (added to other steps)" ;