GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GOptimizerLM Class Reference

Levenberg Marquardt optimizer class. More...

#include <GOptimizerLM.hpp>

Inheritance diagram for GOptimizerLM:
GOptimizer GBase

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...
 
GOptimizerLMoperator= (const GOptimizerLM &opt)
 Assignment operator. More...
 
virtual void clear (void)
 Clear object. More...
 
virtual GOptimizerLMclone (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 GOptimizeroperator= (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...
 
GLogm_logger
 Pointer to optional logger. More...
 

Detailed Description

Levenberg Marquardt optimizer class.

This method implements an Levenberg Marquardt optimizer.

Definition at line 51 of file GOptimizerLM.hpp.

Constructor & Destructor Documentation

GOptimizerLM::GOptimizerLM ( void  )

Void constructor.

Definition at line 56 of file GOptimizerLM.cpp.

References init_members().

Referenced by clone().

GOptimizerLM::GOptimizerLM ( GLog log)
explicit

Constructor with logger.

Parameters
[in]logLogger 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.

Parameters
[in]optOptimizer from which the instance should be built.

Definition at line 89 of file GOptimizerLM.cpp.

References copy_members(), and init_members().

GOptimizerLM::~GOptimizerLM ( void  )
virtual

Destructor.

Definition at line 105 of file GOptimizerLM.cpp.

References free_members().

Member Function Documentation

void GOptimizerLM::accept_dec ( const double &  value)
inline

Set acceptable function decrease.

Parameters
[in]valueAcceptable 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().

const double & GOptimizerLM::accept_dec ( void  ) const
inline

Return acceptable function decrease.

Returns
Acceptable function decrease.

Definition at line 432 of file GOptimizerLM.hpp.

References m_accept_dec.

std::string GOptimizerLM::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GOptimizerLM").

Implements GOptimizer.

Definition at line 141 of file GOptimizerLM.hpp.

void GOptimizerLM::clear ( void  )
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().

GOptimizerLM * GOptimizerLM::clone ( void  ) const
virtual

Clone object.

Implements GOptimizer.

Definition at line 179 of file GOptimizerLM.cpp.

References GOptimizerLM().

void GOptimizerLM::copy_members ( const GOptimizerLM opt)
protected
void GOptimizerLM::eps ( const double &  eps)
inline

Set requested absolute convergence precision.

Parameters
[in]epsRequested absolute convergence precision.

Definition at line 282 of file GOptimizerLM.hpp.

References eps(), and m_eps.

Referenced by GCOMDris::vetorate_fit().

const double & GOptimizerLM::eps ( void  ) const
inline

Return requested absolute convergence precision.

Returns
Requested absolute convergence precision.

Definition at line 420 of file GOptimizerLM.hpp.

References m_eps.

Referenced by eps().

void GOptimizerLM::errors ( GOptimizerFunction fct,
GOptimizerPars pars 
)
virtual

Compute parameter uncertainties.

Parameters
[in]fctOptimizer function.
[in]parsFunction 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().

void GOptimizerLM::free_members ( void  )
protected

Delete class members.

Definition at line 722 of file GOptimizerLM.cpp.

Referenced by clear(), operator=(), and ~GOptimizerLM().

void GOptimizerLM::init_members ( void  )
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=().

int GOptimizerLM::iter ( void  ) const
inlinevirtual

Return number of iterations.

Returns
Number of iterations.

Implements GOptimizer.

Definition at line 177 of file GOptimizerLM.hpp.

References m_iter.

Referenced by GCOMDris::vetorate_fit().

double GOptimizerLM::iteration ( GOptimizerFunction fct,
GOptimizerPars pars 
)
protected

Perform one LM iteration.

Parameters
[in]fctOptimizer function.
[in]parsFunction parameters.
Returns
Step size for iteration.

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().

const double & GOptimizerLM::lambda ( void  ) const
inline

Return lambda value.

Returns
Lambda value.

Definition at line 408 of file GOptimizerLM.hpp.

References m_lambda.

void GOptimizerLM::lambda_dec ( const double &  value)
inline

Set lambda decrement value.

Parameters
[in]valueLambda decrement value.

Definition at line 269 of file GOptimizerLM.hpp.

References m_lambda_dec, and value().

const double & GOptimizerLM::lambda_dec ( void  ) const
inline

Return lambda decrement value.

Returns
Lambda decrement value.

Definition at line 396 of file GOptimizerLM.hpp.

References m_lambda_dec.

void GOptimizerLM::lambda_inc ( const double &  value)
inline

Set lambda increment value.

Parameters
[in]valueLambda increment value.

Definition at line 256 of file GOptimizerLM.hpp.

References m_lambda_inc, and value().

const double & GOptimizerLM::lambda_inc ( void  ) const
inline

Return lambda increment value.

Returns
Lambda increment value.

Definition at line 384 of file GOptimizerLM.hpp.

References m_lambda_inc.

Referenced by optimize().

void GOptimizerLM::lambda_start ( const double &  value)
inline

Set lambda starting value.

Parameters
[in]valueLambda starting value.

Definition at line 243 of file GOptimizerLM.hpp.

References m_lambda_start, and value().

const double & GOptimizerLM::lambda_start ( void  ) const
inline

Return lambda starting value.

Returns
Lambda starting value.

Definition at line 372 of file GOptimizerLM.hpp.

References m_lambda_start.

void GOptimizerLM::logger ( GLog log)
inline

Set logger.

Parameters
[in]logLogger to use in optimizer.

Set the logger into which the optimizer will dump any output.

Definition at line 191 of file GOptimizerLM.hpp.

References log(), and m_logger.

void GOptimizerLM::max_boundary_hits ( const int &  max_hit)
inline

Set maximum number of parameter boundary hits.

Parameters
[in]max_hitMaximum number of parameter boundary hits.

Definition at line 230 of file GOptimizerLM.hpp.

References m_max_hit.

const int & GOptimizerLM::max_boundary_hits ( void  ) const
inline

Return maximum number of parameter boundary hits.

Returns
Maximum number of parameter boundary hits.

Definition at line 360 of file GOptimizerLM.hpp.

References m_max_hit.

void GOptimizerLM::max_iter ( const int &  max_iter)
inline

Set maximum number of iterations.

Parameters
[in]max_iterMaximum number of iterations.

Definition at line 204 of file GOptimizerLM.hpp.

References m_max_iter, and max_iter().

Referenced by GCOMDris::vetorate_fit().

const int & GOptimizerLM::max_iter ( void  ) const
inline

Return maximum number of iterations.

Returns
Maximum number of iterations.

Definition at line 336 of file GOptimizerLM.hpp.

References m_max_iter.

Referenced by max_iter().

void GOptimizerLM::max_stalls ( const int &  max_stalls)
inline

Set maximum number of allowed subsequent stalls.

Parameters
[in]max_stallsMaximum number of allowed subsequent stalls.

Definition at line 217 of file GOptimizerLM.hpp.

References m_max_stall, and max_stalls().

const int & GOptimizerLM::max_stalls ( void  ) const
inline

Return maximum number of allowed subsequent stalls.

Returns
Maximum number of allowed subsequent stalls.

Definition at line 348 of file GOptimizerLM.hpp.

References m_max_stall.

Referenced by max_stalls().

const int & GOptimizerLM::nfree ( void  ) const
inline

Return number of free model parameters.

Returns
Number of free model parameters.

Definition at line 324 of file GOptimizerLM.hpp.

References m_nfree.

const int & GOptimizerLM::npars ( void  ) const
inline

Return number of model parameters.

Returns
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.

Parameters
[in]optOptimizer to be assigned.

Definition at line 126 of file GOptimizerLM.cpp.

References copy_members(), free_members(), init_members(), and GOptimizer::operator=().

std::string GOptimizerLM::print ( const GChatter chatter = NORMAL) const
virtual

Print optimizer information.

Parameters
[in]chatterChattiness.
Returns
String containing optimizer information.

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().

int GOptimizerLM::status ( void  ) const
inlinevirtual

Return optimizer status.

Returns
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.

Returns
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().

double GOptimizerLM::step_size ( const GVector grad,
const GOptimizerPars pars 
)
protected

Return LM step size.

Parameters
[in]gradFunction gradient.
[in]parsFunction 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().

double GOptimizerLM::value ( void  ) const
inlinevirtual

Return function value.

Returns
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().

Member Data Documentation

double GOptimizerLM::m_accept_dec
protected

Acceptable function decrease.

Definition at line 113 of file GOptimizerLM.hpp.

Referenced by accept_dec(), copy_members(), init_members(), iteration(), and print().

double GOptimizerLM::m_delta
protected

Function improvement.

Definition at line 126 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and optimize().

double GOptimizerLM::m_eps
protected

Absolute precision.

Definition at line 112 of file GOptimizerLM.hpp.

Referenced by copy_members(), eps(), init_members(), optimize(), and print().

std::vector<bool> GOptimizerLM::m_hit_boundary
protected

Bookkeeping array for boundary hits.

Definition at line 119 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), optimize(), and step_size().

std::vector<int> GOptimizerLM::m_hit_maximum
protected

Bookkeeping of successive maximum hits.

Definition at line 121 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and optimize().

std::vector<int> GOptimizerLM::m_hit_minimum
protected

Bookkeeping of successive minimum hits.

Definition at line 120 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and optimize().

int GOptimizerLM::m_iter
protected

Iteration.

Definition at line 128 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iter(), optimize(), and print().

double GOptimizerLM::m_lambda
protected

Actual lambda.

Definition at line 124 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), lambda(), optimize(), and print().

double GOptimizerLM::m_lambda_dec
protected

Lambda decrease.

Definition at line 111 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and lambda_dec().

double GOptimizerLM::m_lambda_inc
protected

Lambda increase.

Definition at line 110 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and lambda_inc().

double GOptimizerLM::m_lambda_start
protected

Initial start value.

Definition at line 109 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), lambda_start(), and optimize().

GLog* GOptimizerLM::m_logger
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().

int GOptimizerLM::m_max_dec
protected

Maximum number of function decrease.

Definition at line 117 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), and iteration().

int GOptimizerLM::m_max_hit
protected

Maximum number of successive hits.

Definition at line 116 of file GOptimizerLM.hpp.

Referenced by init_members(), iteration(), and max_boundary_hits().

int GOptimizerLM::m_max_iter
protected

Maximum number of iterations.

Definition at line 114 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), max_iter(), and optimize().

int GOptimizerLM::m_max_stall
protected

Maximum number of stalls.

Definition at line 115 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), max_stalls(), and optimize().

int GOptimizerLM::m_nfree
protected

Number of free parameters.

Definition at line 108 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), nfree(), optimize(), and print().

int GOptimizerLM::m_npars
protected

Number of parameters.

Definition at line 107 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), npars(), optimize(), and print().

int GOptimizerLM::m_num_dec
protected

Number of function decreases.

Definition at line 129 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and optimize().

std::vector<bool> GOptimizerLM::m_par_freeze
protected

Bookkeeping of parameter freeze.

Definition at line 122 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and optimize().

std::vector<bool> GOptimizerLM::m_par_remove
protected

Bookkeeping of parameter removal.

Definition at line 123 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), iteration(), and optimize().

int GOptimizerLM::m_status
protected

Fit status.

Definition at line 127 of file GOptimizerLM.hpp.

Referenced by copy_members(), errors(), init_members(), iteration(), optimize(), status(), and status_string().

bool GOptimizerLM::m_step_adjust
protected

Adjust step size to boundaries.

Definition at line 118 of file GOptimizerLM.hpp.

Referenced by copy_members(), init_members(), and step_size().

double GOptimizerLM::m_value
protected

Actual function value.

Definition at line 125 of file GOptimizerLM.hpp.

Referenced by copy_members(), errors(), init_members(), iteration(), optimize(), print(), and value().


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