GammaLib
2.1.0.dev
|
Levenberg Marquardt optimizer class. More...
#include <GOptimizerLM.hpp>
Public Member Functions | |
GOptimizerLM (void) | |
Void constructor. More... | |
GOptimizerLM (GLog *log) | |
Constructor with logger. More... | |
GOptimizerLM (const GOptimizerLM &opt) | |
Copy constructor. More... | |
virtual | ~GOptimizerLM (void) |
Destructor. More... | |
GOptimizerLM & | operator= (const GOptimizerLM &opt) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear object. More... | |
virtual GOptimizerLM * | clone (void) const |
Clone object. More... | |
virtual std::string | classname (void) const |
Return class name. More... | |
virtual void | optimize (GOptimizerFunction &fct, GOptimizerPars &pars) |
Optimize function parameters. More... | |
virtual void | errors (GOptimizerFunction &fct, GOptimizerPars &pars) |
Compute parameter uncertainties. More... | |
virtual double | value (void) const |
Return function value. More... | |
virtual int | status (void) const |
Return optimizer status. More... | |
virtual int | iter (void) const |
Return number of iterations. More... | |
virtual std::string | print (const GChatter &chatter=NORMAL) const |
Print optimizer information. More... | |
void | logger (GLog *log) |
Set logger. More... | |
void | max_iter (const int &max_iter) |
Set maximum number of iterations. More... | |
void | max_stalls (const int &max_stalls) |
Set maximum number of allowed subsequent stalls. More... | |
void | max_boundary_hits (const int &max_hit) |
Set maximum number of parameter boundary hits. More... | |
void | lambda_start (const double &value) |
Set lambda starting value. More... | |
void | lambda_inc (const double &value) |
Set lambda increment value. More... | |
void | lambda_dec (const double &value) |
Set lambda decrement value. More... | |
void | eps (const double &eps) |
Set requested absolute convergence precision. More... | |
void | accept_dec (const double &value) |
Set acceptable function decrease. More... | |
const int & | npars (void) const |
Return number of model parameters. More... | |
const int & | nfree (void) const |
Return number of free model parameters. More... | |
const int & | max_iter (void) const |
Return maximum number of iterations. More... | |
const int & | max_stalls (void) const |
Return maximum number of allowed subsequent stalls. More... | |
const int & | max_boundary_hits (void) const |
Return maximum number of parameter boundary hits. More... | |
const double & | lambda_start (void) const |
Return lambda starting value. More... | |
const double & | lambda_inc (void) const |
Return lambda increment value. More... | |
const double & | lambda_dec (void) const |
Return lambda decrement value. More... | |
const double & | lambda (void) const |
Return lambda value. More... | |
const double & | eps (void) const |
Return requested absolute convergence precision. More... | |
const double & | accept_dec (void) const |
Return acceptable function decrease. More... | |
std::string | status_string (void) const |
Set fit status string. More... | |
Public Member Functions inherited from GOptimizer | |
GOptimizer (void) | |
Constructor. More... | |
GOptimizer (const GOptimizer &opt) | |
Copy constructor. More... | |
virtual | ~GOptimizer (void) |
Destructor. More... | |
virtual GOptimizer & | operator= (const GOptimizer &opt) |
Assignment operator. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GOptimizerLM &opt) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
double | iteration (GOptimizerFunction &fct, GOptimizerPars &pars) |
Perform one LM iteration. More... | |
double | step_size (const GVector &grad, const GOptimizerPars &pars) |
Return LM step size. More... | |
Protected Member Functions inherited from GOptimizer | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GOptimizer &opt) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
Protected Attributes | |
int | m_npars |
Number of parameters. More... | |
int | m_nfree |
Number of free parameters. More... | |
double | m_lambda_start |
Initial start value. More... | |
double | m_lambda_inc |
Lambda increase. More... | |
double | m_lambda_dec |
Lambda decrease. More... | |
double | m_eps |
Absolute precision. More... | |
double | m_accept_dec |
Acceptable function decrease. More... | |
int | m_max_iter |
Maximum number of iterations. More... | |
int | m_max_stall |
Maximum number of stalls. More... | |
int | m_max_hit |
Maximum number of successive hits. More... | |
int | m_max_dec |
Maximum number of function decrease. More... | |
bool | m_step_adjust |
Adjust step size to boundaries. More... | |
std::vector< bool > | m_hit_boundary |
Bookkeeping array for boundary hits. More... | |
std::vector< int > | m_hit_minimum |
Bookkeeping of successive minimum hits. More... | |
std::vector< int > | m_hit_maximum |
Bookkeeping of successive maximum hits. More... | |
std::vector< bool > | m_par_freeze |
Bookkeeping of parameter freeze. More... | |
std::vector< bool > | m_par_remove |
Bookkeeping of parameter removal. More... | |
double | m_lambda |
Actual lambda. More... | |
double | m_value |
Actual function value. More... | |
double | m_delta |
Function improvement. More... | |
int | m_status |
Fit status. More... | |
int | m_iter |
Iteration. More... | |
int | m_num_dec |
Number of function decreases. More... | |
GLog * | m_logger |
Pointer to optional logger. More... | |
Levenberg Marquardt optimizer class.
This method implements an Levenberg Marquardt optimizer.
Definition at line 51 of file GOptimizerLM.hpp.
GOptimizerLM::GOptimizerLM | ( | void | ) |
Void constructor.
Definition at line 56 of file GOptimizerLM.cpp.
References init_members().
Referenced by clone().
|
explicit |
Constructor with logger.
[in] | log | Logger to use in optimizer. |
Definition at line 71 of file GOptimizerLM.cpp.
References init_members(), log(), and m_logger.
GOptimizerLM::GOptimizerLM | ( | const GOptimizerLM & | opt | ) |
Copy constructor.
[in] | opt | Optimizer from which the instance should be built. |
Definition at line 89 of file GOptimizerLM.cpp.
References copy_members(), and init_members().
|
virtual |
|
inline |
Set acceptable function decrease.
[in] | value | Acceptable function decrease. |
Sets the acceptable function decrease value for which the new solution will be kept and the iterations continue. This strategy provides better convergence in case that a function decrease is encountered.
Definition at line 299 of file GOptimizerLM.hpp.
References m_accept_dec, and value().
|
inline |
Return acceptable function decrease.
Definition at line 432 of file GOptimizerLM.hpp.
References m_accept_dec.
|
inlinevirtual |
Return class name.
Implements GOptimizer.
Definition at line 141 of file GOptimizerLM.hpp.
|
virtual |
Clear object.
This method properly resets the object to an initial state.
Implements GOptimizer.
Definition at line 161 of file GOptimizerLM.cpp.
References GOptimizer::free_members(), free_members(), GOptimizer::init_members(), and init_members().
|
virtual |
Clone object.
Implements GOptimizer.
Definition at line 179 of file GOptimizerLM.cpp.
References GOptimizerLM().
|
protected |
Copy class members.
[in] | opt | GOptimizerLM members to be copied. |
Definition at line 687 of file GOptimizerLM.cpp.
References m_accept_dec, m_delta, m_eps, m_hit_boundary, m_hit_maximum, m_hit_minimum, m_iter, m_lambda, m_lambda_dec, m_lambda_inc, m_lambda_start, m_logger, m_max_dec, m_max_iter, m_max_stall, m_nfree, m_npars, m_num_dec, m_par_freeze, m_par_remove, m_status, m_step_adjust, and m_value.
Referenced by GOptimizerLM(), and operator=().
|
inline |
Set requested absolute convergence precision.
[in] | eps | Requested absolute convergence precision. |
Definition at line 282 of file GOptimizerLM.hpp.
Referenced by GCOMDris::vetorate_fit().
|
inline |
Return requested absolute convergence precision.
Definition at line 420 of file GOptimizerLM.hpp.
References m_eps.
Referenced by eps().
|
virtual |
Compute parameter uncertainties.
[in] | fct | Optimizer function. |
[in] | pars | Function parameters. |
Compute parameter uncertainties from the diagonal elements of the curvature matrix.
Implements GOptimizer.
Definition at line 454 of file GOptimizerLM.cpp.
References GMatrixSparse::cholesky_decompose(), GMatrixSparse::cholesky_solver(), GOptimizerFunction::curvature(), GOptimizerFunction::eval(), G_LM_BAD_ERRORS, G_LM_NOT_POSTIVE_DEFINITE, m_logger, m_status, m_value, npars(), GOptimizerPars::size(), sqrt(), and GOptimizerFunction::value().
Referenced by GCOMDris::vetorate_fit().
|
protected |
Delete class members.
Definition at line 722 of file GOptimizerLM.cpp.
Referenced by clear(), operator=(), and ~GOptimizerLM().
|
protected |
Initialise class members.
< Changed on 30/10/2014 from 1.0e-6
< Do not allow to decrease
< Changed on 30/10/2014 from 1000
< Maximum successive boundary hits before freeze
< Maximum number of function decreases
Definition at line 643 of file GOptimizerLM.cpp.
References m_accept_dec, m_delta, m_eps, m_hit_boundary, m_hit_maximum, m_hit_minimum, m_iter, m_lambda, m_lambda_dec, m_lambda_inc, m_lambda_start, m_logger, m_max_dec, m_max_hit, m_max_iter, m_max_stall, m_nfree, m_npars, m_num_dec, m_par_freeze, m_par_remove, m_status, m_step_adjust, and m_value.
Referenced by clear(), GOptimizerLM(), and operator=().
|
inlinevirtual |
Return number of iterations.
Implements GOptimizer.
Definition at line 177 of file GOptimizerLM.hpp.
References m_iter.
Referenced by GCOMDris::vetorate_fit().
|
protected |
Perform one LM iteration.
[in] | fct | Optimizer function. |
[in] | pars | Function parameters. |
This method performs one LM iteration. Note that the method only acts on the parameter value, i.e. it does not worry about the true scale of the parameter. It calls the eval() method of the optimizer function which is assumed to return the gradient and curvature matrix with respect to the parameter values (and not the scaled true values).
Definition at line 742 of file GOptimizerLM.cpp.
References abs(), GOptimizerFunction::curvature(), GOptimizerFunction::eval(), G_LM_NOT_POSTIVE_DEFINITE, GOptimizerFunction::gradient(), m_accept_dec, m_delta, m_hit_maximum, m_hit_minimum, m_lambda, m_lambda_dec, m_lambda_inc, m_logger, m_max_dec, m_max_hit, m_npars, m_num_dec, m_par_freeze, m_par_remove, m_status, m_value, GMatrixSparse::solve(), step_size(), and GOptimizerFunction::value().
Referenced by optimize().
|
inline |
Return lambda value.
Definition at line 408 of file GOptimizerLM.hpp.
References m_lambda.
|
inline |
Set lambda decrement value.
[in] | value | Lambda decrement value. |
Definition at line 269 of file GOptimizerLM.hpp.
References m_lambda_dec, and value().
|
inline |
Return lambda decrement value.
Definition at line 396 of file GOptimizerLM.hpp.
References m_lambda_dec.
|
inline |
Set lambda increment value.
[in] | value | Lambda increment value. |
Definition at line 256 of file GOptimizerLM.hpp.
References m_lambda_inc, and value().
|
inline |
Return lambda increment value.
Definition at line 384 of file GOptimizerLM.hpp.
References m_lambda_inc.
Referenced by optimize().
|
inline |
Set lambda starting value.
[in] | value | Lambda starting value. |
Definition at line 243 of file GOptimizerLM.hpp.
References m_lambda_start, and value().
|
inline |
Return lambda starting value.
Definition at line 372 of file GOptimizerLM.hpp.
References m_lambda_start.
|
inline |
Set logger.
[in] | log | Logger to use in optimizer. |
Set the logger into which the optimizer will dump any output.
Definition at line 191 of file GOptimizerLM.hpp.
|
inline |
Set maximum number of parameter boundary hits.
[in] | max_hit | Maximum number of parameter boundary hits. |
Definition at line 230 of file GOptimizerLM.hpp.
References m_max_hit.
|
inline |
Return maximum number of parameter boundary hits.
Definition at line 360 of file GOptimizerLM.hpp.
References m_max_hit.
|
inline |
Set maximum number of iterations.
[in] | max_iter | Maximum number of iterations. |
Definition at line 204 of file GOptimizerLM.hpp.
References m_max_iter, and max_iter().
Referenced by GCOMDris::vetorate_fit().
|
inline |
Return maximum number of iterations.
Definition at line 336 of file GOptimizerLM.hpp.
References m_max_iter.
Referenced by max_iter().
|
inline |
Set maximum number of allowed subsequent stalls.
[in] | max_stalls | Maximum number of allowed subsequent stalls. |
Definition at line 217 of file GOptimizerLM.hpp.
References m_max_stall, and max_stalls().
|
inline |
Return maximum number of allowed subsequent stalls.
Definition at line 348 of file GOptimizerLM.hpp.
References m_max_stall.
Referenced by max_stalls().
|
inline |
Return number of free model parameters.
Definition at line 324 of file GOptimizerLM.hpp.
References m_nfree.
|
inline |
Return number of model parameters.
Definition at line 312 of file GOptimizerLM.hpp.
References m_npars.
Referenced by errors().
GOptimizerLM & GOptimizerLM::operator= | ( | const GOptimizerLM & | opt | ) |
Assignment operator.
[in] | opt | Optimizer to be assigned. |
Definition at line 126 of file GOptimizerLM.cpp.
References copy_members(), free_members(), init_members(), and GOptimizer::operator=().
|
virtual |
Optimize function parameters.
[in] | fct | Optimization function. |
[in] | pars | Function parameters. |
Implements GOptimizer.
Definition at line 191 of file GOptimizerLM.cpp.
References abs(), GOptimizerFunction::curvature(), GOptimizerFunction::eval(), G_LM_CONVERGED, G_LM_STALLED, GOptimizerFunction::gradient(), iteration(), lambda_inc(), m_delta, m_eps, m_hit_boundary, m_hit_maximum, m_hit_minimum, m_iter, m_lambda, m_lambda_start, m_logger, m_max_iter, m_max_stall, m_nfree, m_npars, m_num_dec, m_par_freeze, m_par_remove, m_status, m_value, GOptimizerPars::nfree(), GOptimizerPars::size(), status(), gammalib::str(), and GOptimizerFunction::value().
Referenced by GCOMDris::vetorate_fit().
Print optimizer information.
[in] | chatter | Chattiness. |
Implements GOptimizer.
Definition at line 594 of file GOptimizerLM.cpp.
References abs(), m_accept_dec, m_eps, m_iter, m_lambda, m_nfree, m_npars, m_value, gammalib::parformat(), SILENT, status_string(), and gammalib::str().
|
inlinevirtual |
Return optimizer status.
Implements GOptimizer.
Definition at line 165 of file GOptimizerLM.hpp.
References m_status.
Referenced by optimize(), and status_string().
std::string GOptimizerLM::status_string | ( | void | ) | const |
Set fit status string.
Definition at line 556 of file GOptimizerLM.cpp.
References G_LM_BAD_ERRORS, G_LM_CONVERGED, G_LM_NOT_POSTIVE_DEFINITE, G_LM_SINGULAR, G_LM_STALLED, m_status, and status().
Referenced by print(), and GCOMDris::vetorate_fit().
|
protected |
Return LM step size.
[in] | grad | Function gradient. |
[in] | pars | Function parameters. |
Determine the size of the LM step. By default a step size of 1 is taken. If m_step_adjust=true then the step size will be estimated so that the next parameter vector should stay within the parameter boundaries (provided that boundaries exist).
Definition at line 1015 of file GOptimizerLM.cpp.
References m_hit_boundary, m_logger, m_step_adjust, and GOptimizerPars::size().
Referenced by iteration().
|
inlinevirtual |
Return function value.
Implements GOptimizer.
Definition at line 153 of file GOptimizerLM.hpp.
References m_value.
Referenced by accept_dec(), lambda_dec(), lambda_inc(), lambda_start(), and GCOMDris::vetorate_fit().
|
protected |
Acceptable function decrease.
Definition at line 113 of file GOptimizerLM.hpp.
Referenced by accept_dec(), copy_members(), init_members(), iteration(), and print().
|
protected |
Function improvement.
Definition at line 126 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and optimize().
|
protected |
Absolute precision.
Definition at line 112 of file GOptimizerLM.hpp.
Referenced by copy_members(), eps(), init_members(), optimize(), and print().
|
protected |
Bookkeeping array for boundary hits.
Definition at line 119 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), optimize(), and step_size().
|
protected |
Bookkeeping of successive maximum hits.
Definition at line 121 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and optimize().
|
protected |
Bookkeeping of successive minimum hits.
Definition at line 120 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and optimize().
|
protected |
Iteration.
Definition at line 128 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iter(), optimize(), and print().
|
protected |
Actual lambda.
Definition at line 124 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), lambda(), optimize(), and print().
|
protected |
Lambda decrease.
Definition at line 111 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and lambda_dec().
|
protected |
Lambda increase.
Definition at line 110 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and lambda_inc().
|
protected |
Initial start value.
Definition at line 109 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), lambda_start(), and optimize().
|
protected |
Pointer to optional logger.
Definition at line 130 of file GOptimizerLM.hpp.
Referenced by copy_members(), errors(), GOptimizerLM(), init_members(), iteration(), logger(), optimize(), and step_size().
|
protected |
Maximum number of function decrease.
Definition at line 117 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), and iteration().
|
protected |
Maximum number of successive hits.
Definition at line 116 of file GOptimizerLM.hpp.
Referenced by init_members(), iteration(), and max_boundary_hits().
|
protected |
Maximum number of iterations.
Definition at line 114 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), max_iter(), and optimize().
|
protected |
Maximum number of stalls.
Definition at line 115 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), max_stalls(), and optimize().
|
protected |
Number of free parameters.
Definition at line 108 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), nfree(), optimize(), and print().
|
protected |
Number of parameters.
Definition at line 107 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), npars(), optimize(), and print().
|
protected |
Number of function decreases.
Definition at line 129 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and optimize().
|
protected |
Bookkeeping of parameter freeze.
Definition at line 122 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and optimize().
|
protected |
Bookkeeping of parameter removal.
Definition at line 123 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), iteration(), and optimize().
|
protected |
Fit status.
Definition at line 127 of file GOptimizerLM.hpp.
Referenced by copy_members(), errors(), init_members(), iteration(), optimize(), status(), and status_string().
|
protected |
Adjust step size to boundaries.
Definition at line 118 of file GOptimizerLM.hpp.
Referenced by copy_members(), init_members(), and step_size().
|
protected |
Actual function value.
Definition at line 125 of file GOptimizerLM.hpp.
Referenced by copy_members(), errors(), init_members(), iteration(), optimize(), print(), and value().