#include <LMFitter.h>
Inheritance diagram for LMFitter:
A Fitter class that uses derivatives of functions for fitting.
An implementation of the Levenberg Marquart.
Definition at line 33 of file LMFitter.h.
Public Member Functions | |
virtual void | calcAlpha () |
Calculates the alpha matrix. | |
virtual bool | calcBestFit () |
Calculates the best fit. | |
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. | |
virtual bool | calcStep () |
Takes a step in the fitting and returns the change to the parameters of the function. | |
Fitter * | clone () const |
Makes a copy of the receiving object. | |
virtual void | copyFrom (const Fitter *other) |
Makes a copy of other. | |
void | fillFreeParameters (std::vector< double > &) const |
Fills the vector with the free parameters values. | |
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. | |
bool | getUseErrors () const |
Returns true if error data from the DataSource will be used if available. | |
bool | isCompatible (const FunctionBase *) const |
Returns true if the function is compatible with the objective function. | |
LMFitter (const char *name) | |
The constructor taking name of fitter as argument. | |
const std::string & | name () const |
Returns the name of the fitter. | |
bool | needsIntegrated () const |
Returns true if the Fitter needs integrated intervals. | |
virtual double | objectiveValue () const |
Calculates the value of the objective function at the current set of parameters. | |
void | setDataSource (const DataSource *source) |
Sets the source of data to be used. | |
virtual void | setFCN (StatedFCN *fcn) |
Sets the objective function. | |
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. | |
void | setFunction (FunctionBase *function) |
Sets the model function. | |
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. | |
void | setUseErrors (bool yes=true) |
Sets the fitter to use error data from the DataSource, if available. | |
virtual bool | solveSystem () |
Solves the system. | |
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 Member Functions | |
LMFitter (const LMFitter &) | |
The copy constructor. | |
Private Attributes | |
std::vector< std::vector< double > > | m_alpha |
The alpha matrix. | |
std::vector< double > | m_beta |
The beta vector. | |
double | m_chi_cutoff |
The Chi Squared cut-off parameter. | |
double | m_lambda |
The current lambda factor. | |
double | m_lambda_expand_factor |
The factor by which lambda is divided if it is too small. | |
double | m_lambda_shrink_factor |
The factor by which lambda is divided if it is too large. | |
double | m_start_lambda |
The starting lambda factor. |
LMFitter | ( | const char * | name | ) |
void calcAlpha | ( | ) | [virtual] |
Calculates the alpha matrix.
Definition at line 70 of file LMFitter.cxx.
References LMFitter::m_alpha, LMFitter::m_beta, Fitter::m_fcn, and LMFitter::m_lambda.
Referenced by LMFitter::calcCovariance(), and LMFitter::calcStep().
bool calcBestFit | ( | ) | [virtual] |
Calculates the best fit.
Returns true
if the fit converged; otherwise it returns false
.
Implements Fitter.
Definition at line 194 of file LMFitter.cxx.
References LMFitter::calcStep(), Fitter::fillFreeParameters(), LMFitter::m_beta, LMFitter::m_chi_cutoff, Fitter::m_fcn, LMFitter::m_lambda, LMFitter::m_lambda_expand_factor, LMFitter::m_lambda_shrink_factor, Fitter::m_max_iterations, LMFitter::m_start_lambda, and Fitter::objectiveValue().
int calcCovariance | ( | std::vector< std::vector< double > > & | cov | ) | [virtual] |
Calculates the covariance matrix.
Returns EXIT_SUCCESS if a minima of the chi2 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 93 of file LMFitter.cxx.
References LMFitter::calcAlpha(), hippodraw::Numeric::invertMatrix(), LMFitter::m_alpha, and LMFitter::m_lambda.
int calcDegreesOfFreedom | ( | ) | const [virtual, inherited] |
Returns the number of degrees of freedom in the fit.
Definition at line 226 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by FunctionProjector::degreesOfFreedom(), and hippodraw::Python::export_Fitter().
bool calcStep | ( | ) | [virtual] |
Takes a step in the fitting and returns the change to the parameters of the function.
Definition at line 186 of file LMFitter.cxx.
References LMFitter::calcAlpha(), and LMFitter::solveSystem().
Referenced by LMFitter::calcBestFit().
Fitter * clone | ( | ) | const [virtual] |
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 63 of file LMFitter.cxx.
References LMFitter::LMFitter().
void copyFrom | ( | const Fitter * | other | ) | [virtual, inherited] |
void fillFreeParameters | ( | std::vector< double > & | ) | const [inherited] |
Fills the vector with the free parameters values.
Definition at line 139 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by LMFitter::calcBestFit(), and BFGSFitter::calcBestFit().
StatedFCN * getFCN | ( | ) | [inherited] |
Returns the objective function object.
Definition at line 70 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by hippodraw::Python::export_Fitter().
const vector< int > & getFixedFlags | ( | ) | const [virtual, inherited] |
Returns a vector containing flags for which parameters are to be held fixed during objective function minimization.
Definition at line 153 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by MinuitMigrad::initialize().
bool getUseErrors | ( | ) | const [inherited] |
Returns true
if error data from the DataSource will be used if available.
Definition at line 116 of file Fitter.cxx.
References Fitter::m_fcn.
bool isCompatible | ( | const FunctionBase * | ) | const [inherited] |
Returns true
if the function is compatible with the objective function.
Definition at line 77 of file Fitter.cxx.
References Fitter::m_fcn.
const std::string & name | ( | ) | const [inherited] |
Returns the name of the fitter.
Definition at line 54 of file Fitter.cxx.
References Fitter::m_name.
Referenced by hippodraw::Python::export_Fitter(), and MinuitMigrad::initialize().
bool needsIntegrated | ( | ) | const [inherited] |
Returns true
if the Fitter needs integrated intervals.
Definition at line 128 of file Fitter.cxx.
References Fitter::m_fcn.
double objectiveValue | ( | ) | const [virtual, inherited] |
Calculates the value of the objective function at the current set of parameters.
Definition at line 219 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by LMFitter::calcBestFit(), hippodraw::Python::export_Fitter(), BFGSFitter::function(), BFGSFitter::gradient(), BFGSFitter::gradp(), and FunctionProjector::objectiveValue().
void setDataSource | ( | const DataSource * | source | ) | [inherited] |
Sets the source of data to be used.
Definition at line 97 of file Fitter.cxx.
References Fitter::m_fcn, and Fitter::setUseErrors().
void setFCN | ( | StatedFCN * | fcn | ) | [virtual] |
Sets the objective function.
Sets the objective function and indicate to it that it needs partial derivatives.
Reimplemented from Fitter.
Definition at line 239 of file LMFitter.cxx.
References Fitter::setFCN().
void setFitCut | ( | TupleCut * | cut | ) | [virtual, inherited] |
Sets the cut to limit range of fitting.
Definition at line 240 of file Fitter.cxx.
References Fitter::m_fcn.
void setFitRange | ( | bool | yes = true |
) | [virtual, inherited] |
Sets use of a fitting range on or off.
Definition at line 247 of file Fitter.cxx.
References Fitter::m_fcn.
void setFixedFlags | ( | const std::vector< int > & | flags | ) | [virtual, inherited] |
Sets the parameters that are to be held fixed during objective function minimization.
Definition at line 146 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by hippodraw::Python::export_Fitter().
void setFunction | ( | FunctionBase * | function | ) | [inherited] |
void setLimits | ( | const std::string & | name, | |
double | lower, | |||
double | upper | |||
) | [inherited] |
Sets the limits for the parameter of the model function with name name.
Definition at line 194 of file Fitter.cxx.
References Fitter::getParameterIndex(), and Fitter::setLimits().
void setLimits | ( | unsigned int | i, | |
double | lower, | |||
double | upper | |||
) | [virtual, inherited] |
Sets the limits for the parameter of the model function indexed by i.
This base class implementation throws a std::runtime_error. Derived classes that implement this function should override it.
Reimplemented in MinuitMigrad.
Definition at line 160 of file Fitter.cxx.
References Fitter::m_name.
Referenced by hippodraw::Python::export_Fitter(), and Fitter::setLimits().
void setStepSize | ( | const std::string & | name, | |
double | size | |||
) | [inherited] |
Sets the minimization step size for model function parameter name.
Definition at line 212 of file Fitter.cxx.
References Fitter::getParameterIndex(), and Fitter::setStepSize().
void setStepSize | ( | unsigned int | i, | |
double | size | |||
) | [virtual, inherited] |
Sets the step size for parameter of the minimization.
This base class implementation throws FitterException. Derived classes that support setting step size should override this member function.
Reimplemented in MinuitMigrad.
Definition at line 202 of file Fitter.cxx.
References Fitter::m_name.
Referenced by hippodraw::Python::export_Fitter(), and Fitter::setStepSize().
void setUseErrors | ( | bool | yes = true |
) | [inherited] |
Sets the fitter to use error data from the DataSource, if available.
Definition at line 107 of file Fitter.cxx.
References Fitter::m_fcn.
Referenced by Fitter::setDataSource().
bool solveSystem | ( | ) | [virtual] |
Solves the system.
Definition at line 105 of file LMFitter.cxx.
References LMFitter::m_alpha, and LMFitter::m_beta.
Referenced by LMFitter::calcStep().
std::vector< std::vector < double > > m_alpha [private] |
The alpha matrix.
Definition at line 43 of file LMFitter.h.
Referenced by LMFitter::calcAlpha(), LMFitter::calcCovariance(), and LMFitter::solveSystem().
std::vector< double > m_beta [private] |
The beta vector.
Definition at line 46 of file LMFitter.h.
Referenced by LMFitter::calcAlpha(), LMFitter::calcBestFit(), and LMFitter::solveSystem().
double m_chi_cutoff [private] |
The Chi Squared cut-off parameter.
If the two iterations of a step change the Chi squared less than this quantity, then no more steps are taken.
Definition at line 51 of file LMFitter.h.
Referenced by LMFitter::calcBestFit().
The objective function.
Definition at line 59 of file Fitter.h.
Referenced by LMFitter::calcAlpha(), MinuitMigrad::calcBestFit(), LMFitter::calcBestFit(), BFGSFitter::calcBestFit(), Fitter::calcDegreesOfFreedom(), MinuitMigrad::checkIndex(), Fitter::copyFrom(), Fitter::fillFreeParameters(), Fitter::Fitter(), BFGSFitter::function(), Fitter::getFCN(), Fitter::getFixedFlags(), Fitter::getParameterIndex(), Fitter::getUseErrors(), BFGSFitter::gradient(), BFGSFitter::gradp(), MinuitMigrad::initialize(), MinuitMigrad::initLimits(), Fitter::isCompatible(), Fitter::needsIntegrated(), Fitter::objectiveValue(), Fitter::setDataSource(), Fitter::setFCN(), Fitter::setFitCut(), Fitter::setFitRange(), Fitter::setFixedFlags(), Fitter::setFunction(), Fitter::setUseErrors(), and Fitter::~Fitter().
double m_lambda [private] |
The current lambda factor.
Definition at line 57 of file LMFitter.h.
Referenced by LMFitter::calcAlpha(), LMFitter::calcBestFit(), and LMFitter::calcCovariance().
double m_lambda_expand_factor [private] |
The factor by which lambda is divided if it is too small.
Definition at line 63 of file LMFitter.h.
Referenced by LMFitter::calcBestFit().
double m_lambda_shrink_factor [private] |
The factor by which lambda is divided if it is too large.
Definition at line 60 of file LMFitter.h.
Referenced by LMFitter::calcBestFit().
int m_max_iterations [protected, inherited] |
The maximum number of iterations allowed in attempting the fit.
Definition at line 62 of file Fitter.h.
Referenced by LMFitter::calcBestFit(), BFGSFitter::calcBestFit(), BFGSFitter::iterParam(), and BFGSFitter::setIterParam().
std::string m_name [protected, inherited] |
The name of the fitter.
Definition at line 51 of file Fitter.h.
Referenced by MinuitMigrad::checkIndex(), Fitter::name(), Fitter::setLimits(), and Fitter::setStepSize().
double m_start_lambda [private] |
The starting lambda factor.
Definition at line 54 of file LMFitter.h.
Referenced by LMFitter::calcBestFit().