#include <BFGSFitter.h>
Inheritance diagram for BFGSFitter:
The entire minimization algorithm relies heavily on the description given in Numerical Optimization by Jorge Nocedal, Stephen J. Wright Publisher: Springer Verlag; (August 27, 1999) ISBN: 0387987932). In the following description we will refer to this book a number of times.
Definition at line 31 of file BFGSFitter.h.
Public Member Functions | |
BFGSFitter (const char *name) | |
The constructor taking name of fitter as argument. | |
virtual bool | calcBestFit () |
Main driver routine for BFGS algorithm which has been used in computing the bets fit for the function. | |
virtual int | calcCovariance (std::vector< std::vector< double > > &cov) |
Calculates the covariance matrix. | |
virtual int | calcDegreesOfFreedom () const |
Returns the number of degrees of freedom in the fit. | |
Fitter * | clone () const |
Makes a copy of the receiving object. | |
void | fillFreeParameters (std::vector< double > &) const |
Fills the vector with the free parameters values. | |
double | function (const std::vector< double > &x) const |
The objective function. | |
StatedFCN * | getFCN () |
Returns the objective function object. | |
virtual const std::vector< int > & | getFixedFlags () const |
Returns a vector containing flags for which parameters are to be held fixed during objective function minimization. | |
std::vector< double > | gradient (const std::vector< double > &x) const |
The gradient of the objective function. | |
double | gradp (const std::vector< double > &u, const std::vector< double > &p) const |
Efficient computation of gradient of the objective function with a vector p. | |
const std::vector< double > & | initIter () const |
Returns the initial value of the iterate. | |
double | interpolate (const std::vector< double > &x0, const std::vector< double > &p, double Alphaim, double Alphai) const |
A cubic interpolation routine. | |
double | iterParam (std::string name) |
Given a string, this function returns the value of the associated iteration parameter. | |
const std::string & | name () const |
Returns the name of the fitter. | |
virtual bool | needsDerivatives () const |
Returns false as this fitter does not need the function to calculate its partial derivatives. | |
virtual double | objectiveValue () const |
Calculates the value of the objective function at the current set of parameters. | |
void | setFCN (StatedFCN *fcn) |
Sets the objective function object. | |
virtual void | setFitCut (TupleCut *cut) |
Sets the cut to limit range of fitting. | |
virtual void | setFitRange (bool yes=true) |
Sets use of a fitting range on or off. | |
virtual void | setFixedFlags (const std::vector< int > &flags) |
Sets the parameters that are to be held fixed during objective function minimization. | |
int | setInitIter (const std::vector< double > &xinit) |
Sets the initial value of the iterate, assuming it is given as a vector. | |
int | setIterParam (std::string name, double value) |
Given a string and a double, this function sets the value of the associated iteration parameter. | |
void | setLimits (const std::string &name, double lower, double upper) |
Sets the limits for the parameter of the model function with name name. | |
virtual void | setLimits (unsigned int i, double lower, double upper) |
Sets the limits for the parameter of the model function indexed by i. | |
void | setStepSize (const std::string &name, double size) |
Sets the minimization step size for model function parameter name. | |
virtual void | setStepSize (unsigned int i, double size) |
Sets the step size for parameter of the minimization. | |
double | wolfeStep (const std::vector< double > &x0, const std::vector< double > &p) const |
Computes a step satisfying the Wolfe conditions. | |
double | zoom (const std::vector< double > &x0, const std::vector< double > &p, double phi0, double dphi0, double Alphalo, double Alphahi) const |
A function which helps out Wolfe in deciding the step length. | |
Protected Attributes | |
StatedFCN * | m_fcn |
The objective function. | |
int | m_max_iterations |
The maximum number of iterations allowed in attempting the fit. | |
std::string | m_name |
The name of the fitter. | |
Private Attributes | |
double | m_alpha1 |
First step length to try and this must be less than Alpha_max. | |
double | m_alpha_max |
Maximum step length to try, suggested value by Nocedal and Wright is alpha_max = 4. | |
double | m_c1 |
c1,c2 - constants such that 0 < c1 < c2 < 1 and they ensure that strong Wolfe conditions hold true. | |
double | m_c2 |
c1,c2 - constants such that 0 < c1 < c2 < 1 and they ensure that strong Wolfe conditions hold true. | |
double | m_grad_cutoff |
The gradient cut-off parameter. | |
std::map< std::string, double * > | m_iter_params |
Map of the various iteration parameters to their name. | |
std::vector< std::vector< double > > | m_M |
The inverse of the quasi-hessian. | |
double | m_proj_cutoff |
The projection cut-off parameter. | |
double | m_step_cutoff |
The step cut-off parameter. | |
std::vector< double > | m_xinit |
The initial value to start the iteration from. |
|
The constructor taking name of fitter as argument.
Definition at line 57 of file BFGSFitter.cxx. References m_alpha1, m_alpha_max, m_c1, m_c2, m_grad_cutoff, m_iter_params, m_proj_cutoff, and m_step_cutoff. Referenced by clone(). |
|
Main driver routine for BFGS algorithm which has been used in computing the bets fit for the function.
Implements Fitter. Definition at line 89 of file BFGSFitter.cxx. References std::abs(), hippodraw::Numeric::eye(), Fitter::fillFreeParameters(), function(), gradient(), hippodraw::Numeric::innerProduct(), Fitter::m_fcn, m_grad_cutoff, m_M, Fitter::m_max_iterations, m_proj_cutoff, m_step_cutoff, m_xinit, norm, hippodraw::Numeric::outerProduct(), setInitIter(), and wolfeStep(). |
|
Calculates the covariance matrix. Returns EXIT_SUCCESS if a minima of the log likelihood functions is found, returns EXIT_FAILURE in case algorithm converges on other stationary points (i.e. on saddle points). Reimplemented from Fitter. Definition at line 472 of file BFGSFitter.cxx. References hippodraw::Numeric::cholFactor(), m_M, and m_xinit. |
|
Returns the number of degrees of freedom in the fit.
Definition at line 165 of file Fitter.cxx. References Fitter::m_fcn. Referenced by FunctionProjector::degreesOfFreedom(), and hippodraw::Python::export_Fitter(). |
|
Makes a copy of the receiving object. Makes copy of receiving object by creating a new one with the only constructor.
Implements Fitter. Definition at line 77 of file BFGSFitter.cxx. References BFGSFitter(). |
|
Fills the vector with the free parameters values.
Definition at line 68 of file Fitter.cxx. References Fitter::m_fcn. Referenced by LMFitter::calcBestFit(), and calcBestFit(). |
|
The objective function.
Definition at line 319 of file BFGSFitter.cxx. References Fitter::m_fcn, and Fitter::objectiveValue(). Referenced by calcBestFit(), interpolate(), wolfeStep(), and zoom(). |
|
Returns the objective function object.
Definition at line 54 of file Fitter.cxx. References Fitter::m_fcn. Referenced by hippodraw::Python::export_Fitter(). |
|
Returns a vector containing flags for which parameters are to be held fixed during objective function minimization.
Definition at line 82 of file Fitter.cxx. References Fitter::m_fcn. Referenced by MinuitMigrad::calcBestFit(). |
|
The gradient of the objective function.
Definition at line 351 of file BFGSFitter.cxx. References Fitter::m_fcn, and Fitter::objectiveValue(). Referenced by calcBestFit(). |
|
Efficient computation of gradient of the objective function with a vector p.
Definition at line 404 of file BFGSFitter.cxx. References Fitter::m_fcn, and Fitter::objectiveValue(). Referenced by interpolate(), wolfeStep(), and zoom(). |
|
Returns the initial value of the iterate.
Definition at line 453 of file BFGSFitter.cxx. References m_xinit. |
|
A cubic interpolation routine.
Definition at line 287 of file BFGSFitter.cxx. References std::abs(), function(), gradp(), std::sqrt(), and std::swap(). Referenced by zoom(). |
|
Given a string, this function returns the value of the associated iteration parameter. Names of the various iteration parameters have been chosen according to the following simple rule. m_foo_bar is called foo_bar. Definition at line 494 of file BFGSFitter.cxx. References m_iter_params, and Fitter::m_max_iterations. |
|
Returns the name of the fitter.
Definition at line 61 of file Fitter.cxx. References Fitter::m_name. Referenced by hippodraw::Python::export_Fitter(), and MinuitMigrad::initialize(). |
|
Returns
Implements Fitter. Definition at line 84 of file BFGSFitter.cxx. |
|
Calculates the value of the objective function at the current set of parameters.
Definition at line 158 of file Fitter.cxx. References Fitter::m_fcn. Referenced by LMFitter::calcBestFit(), hippodraw::Python::export_Fitter(), function(), gradient(), gradp(), and FunctionProjector::objectiveValue(). |
|
Sets the objective function object. Sets the objective function object to be used and takes possession of it. That is, will delete the current object, if there is one, and will delete the object in this object's destructor. Definition at line 45 of file Fitter.cxx. References Fitter::m_fcn. |
|
Sets the cut to limit range of fitting.
Definition at line 179 of file Fitter.cxx. References Fitter::m_fcn. |
|
Sets use of a fitting range on or off.
Definition at line 186 of file Fitter.cxx. References Fitter::m_fcn. |
|
Sets the parameters that are to be held fixed during objective function minimization.
Definition at line 75 of file Fitter.cxx. References Fitter::m_fcn. Referenced by hippodraw::Python::export_Fitter(). |
|
Sets the initial value of the iterate, assuming it is given as a vector.
Definition at line 458 of file BFGSFitter.cxx. References m_xinit. Referenced by calcBestFit(). |
|
Given a string and a double, this function sets the value of the associated iteration parameter. Names of the various parameters have been chosen according to the following simple rule. m_foo_bar is called foo_bar. Definition at line 514 of file BFGSFitter.cxx. References m_iter_params, and Fitter::m_max_iterations. |
|
Sets the limits for the parameter of the model function with name name.
Definition at line 123 of file Fitter.cxx. References Fitter::getParameterIndex(), and Fitter::setLimits(). |
|
Sets the limits for the parameter of the model function indexed by i.
Reimplemented in MinuitMigrad. Definition at line 89 of file Fitter.cxx. References Fitter::m_name. Referenced by hippodraw::Python::export_Fitter(), and Fitter::setLimits(). |
|
Sets the minimization step size for model function parameter name.
Definition at line 151 of file Fitter.cxx. References Fitter::getParameterIndex(), and Fitter::setStepSize(). |
|
Sets the step size for parameter of the minimization. This base class implementation throws FitterException. Derived classes that suport setting step size should override this member function. Reimplemented in MinuitMigrad. Definition at line 141 of file Fitter.cxx. References Fitter::m_name. Referenced by hippodraw::Python::export_Fitter(), and Fitter::setStepSize(). |
|
Computes a step satisfying the Wolfe conditions. Based on Algorithm 3.2 (Line Search Algorithm) on pp. 58--60 of "Numerical Optimization" by Jorge Nocedal and Stephen J. Wright Definition at line 171 of file BFGSFitter.cxx. References std::abs(), function(), gradp(), m_alpha1, m_alpha_max, m_c1, m_c2, std::min(), std::sqrt(), and zoom(). Referenced by calcBestFit(). |
|
A function which helps out Wolfe in deciding the step length. Based on Algorithm 3.3 (zoom) on pg. 60 of "Numerical Optimization" by Jorge Nocedal and Stephen J. Wright Definition at line 234 of file BFGSFitter.cxx. References std::abs(), function(), gradp(), interpolate(), m_c1, and m_c2. Referenced by wolfeStep(). |
|
First step length to try and this must be less than Alpha_max. (typically Alpha1 = 1 for Newton's method and relatives) Definition at line 83 of file BFGSFitter.h. Referenced by BFGSFitter(), and wolfeStep(). |
|
Maximum step length to try, suggested value by Nocedal and Wright is alpha_max = 4.
Definition at line 79 of file BFGSFitter.h. Referenced by BFGSFitter(), and wolfeStep(). |
|
c1,c2 - constants such that 0 < c1 < c2 < 1 and they ensure that strong Wolfe conditions hold true. Strong Wolfe conditions: f(x_k + Alpha_k * p_k) <= f(x_k) + c1 * Alpha_k * grad f(x_k)'*p_k (1) |grad f(x_k + Alpha_k * p_k)'*p_k| >= c2 * grad f(x_k)' * p_k (2) The lower the c2 value, the closer you are asking the algorithm to get to an actual local minimum. The lower the c1 value, the sole demand being made is that the direction be a direction of descent. Nocedal and Wright suggest use of following: c1 = 1e-4; c2 = 0.9; Definition at line 75 of file BFGSFitter.h. Referenced by BFGSFitter(), wolfeStep(), and zoom(). |
|
c1,c2 - constants such that 0 < c1 < c2 < 1 and they ensure that strong Wolfe conditions hold true. Strong Wolfe conditions: f(x_k + Alpha_k * p_k) <= f(x_k) + c1 * Alpha_k * grad f(x_k)'*p_k (1) |grad f(x_k + Alpha_k * p_k)'*p_k| >= c2 * grad f(x_k)' * p_k (2) The lower the c2 value, the closer you are asking the algorithm to get to an actual local minimum. The lower the c1 value, the sole demand being made is that the direction be a direction of descent. Nocedal and Wright suggest use of following: c1 = 1e-4; c2 = 0.9; Definition at line 75 of file BFGSFitter.h. Referenced by BFGSFitter(), wolfeStep(), and zoom(). |
|
The objective function.
Definition at line 55 of file Fitter.h. Referenced by LMFitter::calcAlpha(), MinuitMigrad::calcBestFit(), LMFitter::calcBestFit(), calcBestFit(), Fitter::calcDegreesOfFreedom(), MinuitMigrad::checkIndex(), Fitter::fillFreeParameters(), Fitter::Fitter(), function(), Fitter::getFCN(), Fitter::getFixedFlags(), Fitter::getParameterIndex(), gradient(), gradp(), MinuitMigrad::initialize(), Fitter::objectiveValue(), Fitter::setFCN(), Fitter::setFitCut(), Fitter::setFitRange(), Fitter::setFixedFlags(), and Fitter::~Fitter(). |
|
The gradient cut-off parameter. If two successive iterations change the the norm of the gradient of Likelihood function less than this quantity, then iteration is terminated Definition at line 48 of file BFGSFitter.h. Referenced by BFGSFitter(), and calcBestFit(). |
|
Map of the various iteration parameters to their name.
Definition at line 86 of file BFGSFitter.h. Referenced by BFGSFitter(), iterParam(), and setIterParam(). |
|
The inverse of the quasi-hessian.
Definition at line 40 of file BFGSFitter.h. Referenced by calcBestFit(), and calcCovariance(). |
|
The maximum number of iterations allowed in attempting the fit.
Definition at line 58 of file Fitter.h. Referenced by LMFitter::calcBestFit(), calcBestFit(), LMFitter::iterParam(), iterParam(), LMFitter::setIterParam(), and setIterParam(). |
|
The name of the fitter.
Definition at line 47 of file Fitter.h. Referenced by MinuitMigrad::checkIndex(), Fitter::name(), Fitter::setLimits(), and Fitter::setStepSize(). |
|
The projection cut-off parameter. If the projection of step on the gradient is less than this quantity, then iteration is terminated Definition at line 57 of file BFGSFitter.h. Referenced by BFGSFitter(), and calcBestFit(). |
|
The step cut-off parameter. If the two successive iterations result in the norm of difference of iterates less than this quantity, then iteration is terminated Definition at line 53 of file BFGSFitter.h. Referenced by BFGSFitter(), and calcBestFit(). |
|
The initial value to start the iteration from.
Definition at line 43 of file BFGSFitter.h. Referenced by calcBestFit(), calcCovariance(), initIter(), and setInitIter(). |