Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

LMFitter Class Reference

#include <LMFitter.h>

Inheritance diagram for LMFitter:

Inheritance graph
[legend]
Collaboration diagram for LMFitter:

Collaboration graph
[legend]
List of all members.

Detailed Description

A Fitter class.

A Fitter class that uses derivatives of functions for fitting.

An implementation of the Levenberg Marquart.

Requests:
Make the fit() method a member function of the DataRep instead of the function in the Python interface.

Author:
Daniel Engovatov <engo@slac.stanford.edu>

Kaustuv <kaustuv@stanford.edu>

Paul F. Kunz <Paul_Kunz@slac.stanford.edu>

Definition at line 32 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.
Fitterclone () const
 Makes a copy of the receiving object.
void fillFreeParameters (std::vector< double > &) const
 Fills the vector with the free parameters values.
StatedFCNgetFCN ()
 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.
double iterParam (std::string name)
 Given a string, this function returns the value of the associated iteration parameter.
 LMFitter (const char *name)
 The constructor taking name of fitter as argument.
const std::stringname () const
 Returns the name of the fitter.
virtual bool needsDerivatives () const
 Returns true as thi fitter needs 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 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.
virtual bool solveSystem ()
 Solves the system.

Protected Attributes

StatedFCNm_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

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.
std::map< std::string, double * > m_iter_params
 Map of the various iteration parameters to their name.
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.


Constructor & Destructor Documentation

LMFitter::LMFitter const char *  name  ) 
 

The constructor taking name of fitter as argument.

Definition at line 48 of file LMFitter.cxx.

References m_chi_cutoff, m_iter_params, m_lambda_expand_factor, m_lambda_shrink_factor, and m_start_lambda.

Referenced by clone().


Member Function Documentation

void LMFitter::calcAlpha  )  [virtual]
 

Calculates the alpha matrix.

Todo:
Should probably move this implementation into the FCN.

Definition at line 77 of file LMFitter.cxx.

References m_alpha, m_beta, Fitter::m_fcn, and m_lambda.

Referenced by calcCovariance(), and calcStep().

bool LMFitter::calcBestFit  )  [virtual]
 

Calculates the best fit.

Returns true if the fit converged; otherwise it returns false.

Implements Fitter.

Definition at line 201 of file LMFitter.cxx.

References std::abs(), calcStep(), Fitter::fillFreeParameters(), m_beta, m_chi_cutoff, Fitter::m_fcn, m_lambda, m_lambda_expand_factor, m_lambda_shrink_factor, Fitter::m_max_iterations, m_start_lambda, and Fitter::objectiveValue().

int LMFitter::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 100 of file LMFitter.cxx.

References calcAlpha(), hippodraw::Numeric::invertMatrix(), m_alpha, and m_lambda.

int Fitter::calcDegreesOfFreedom  )  const [virtual, inherited]
 

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

bool LMFitter::calcStep  )  [virtual]
 

Takes a step in the fitting and returns the change to the parameters of the function.

Definition at line 193 of file LMFitter.cxx.

References calcAlpha(), and solveSystem().

Referenced by calcBestFit().

Fitter * LMFitter::clone  )  const [virtual]
 

Makes a copy of the receiving object.

Makes copy of receiving object by creating a new one with the only constructor.

Attention:
Objects created with this function may not be complete until the setFCN member function is called.

Implements Fitter.

Definition at line 63 of file LMFitter.cxx.

References LMFitter().

void Fitter::fillFreeParameters std::vector< double > &   )  const [inherited]
 

Fills the vector with the free parameters values.

Definition at line 68 of file Fitter.cxx.

References Fitter::m_fcn.

Referenced by calcBestFit(), and BFGSFitter::calcBestFit().

StatedFCN * Fitter::getFCN  )  [inherited]
 

Returns the objective function object.

Definition at line 54 of file Fitter.cxx.

References Fitter::m_fcn.

Referenced by hippodraw::Python::export_Fitter().

const vector< int > & Fitter::getFixedFlags  )  const [virtual, inherited]
 

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

double LMFitter::iterParam std::string  name  ) 
 

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 243 of file LMFitter.cxx.

References m_iter_params, and Fitter::m_max_iterations.

const std::string & Fitter::name  )  const [inherited]
 

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

bool LMFitter::needsDerivatives  )  const [virtual]
 

Returns true as thi fitter needs the function to calculate its partial derivatives.

Implements Fitter.

Definition at line 70 of file LMFitter.cxx.

double Fitter::objectiveValue  )  const [virtual, inherited]
 

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 calcBestFit(), hippodraw::Python::export_Fitter(), BFGSFitter::function(), BFGSFitter::gradient(), BFGSFitter::gradp(), and FunctionProjector::objectiveValue().

void Fitter::setFCN StatedFCN fcn  )  [inherited]
 

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.

void Fitter::setFitCut TupleCut cut  )  [virtual, inherited]
 

Sets the cut to limit range of fitting.

Definition at line 179 of file Fitter.cxx.

References Fitter::m_fcn.

void Fitter::setFitRange bool  yes = true  )  [virtual, inherited]
 

Sets use of a fitting range on or off.

Definition at line 186 of file Fitter.cxx.

References Fitter::m_fcn.

void Fitter::setFixedFlags const std::vector< int > &  flags  )  [virtual, inherited]
 

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

int LMFitter::setIterParam std::string  name,
double  value
 

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 263 of file LMFitter.cxx.

References m_iter_params, and Fitter::m_max_iterations.

void Fitter::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 123 of file Fitter.cxx.

References Fitter::getParameterIndex(), and Fitter::setLimits().

void Fitter::setLimits unsigned int  i,
double  lower,
double  upper
[virtual, inherited]
 

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

void Fitter::setStepSize const std::string name,
double  size
[inherited]
 

Sets the minimization step size for model function parameter name.

Definition at line 151 of file Fitter.cxx.

References Fitter::getParameterIndex(), and Fitter::setStepSize().

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

bool LMFitter::solveSystem  )  [virtual]
 

Solves the system.

Definition at line 112 of file LMFitter.cxx.

References std::abs(), m_alpha, m_beta, and std::swap().

Referenced by calcStep().


Member Data Documentation

std::vector< std::vector < double > > LMFitter::m_alpha [private]
 

The alpha matrix.

Definition at line 42 of file LMFitter.h.

Referenced by calcAlpha(), calcCovariance(), and solveSystem().

std::vector< double > LMFitter::m_beta [private]
 

The beta vector.

Definition at line 45 of file LMFitter.h.

Referenced by calcAlpha(), calcBestFit(), and solveSystem().

double LMFitter::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 50 of file LMFitter.h.

Referenced by calcBestFit(), and LMFitter().

StatedFCN* Fitter::m_fcn [protected, inherited]
 

The objective function.

Definition at line 55 of file Fitter.h.

Referenced by calcAlpha(), MinuitMigrad::calcBestFit(), calcBestFit(), BFGSFitter::calcBestFit(), Fitter::calcDegreesOfFreedom(), MinuitMigrad::checkIndex(), Fitter::fillFreeParameters(), Fitter::Fitter(), BFGSFitter::function(), Fitter::getFCN(), Fitter::getFixedFlags(), Fitter::getParameterIndex(), BFGSFitter::gradient(), BFGSFitter::gradp(), MinuitMigrad::initialize(), Fitter::objectiveValue(), Fitter::setFCN(), Fitter::setFitCut(), Fitter::setFitRange(), Fitter::setFixedFlags(), and Fitter::~Fitter().

std::map< std::string, double * > LMFitter::m_iter_params [private]
 

Map of the various iteration parameters to their name.

Definition at line 65 of file LMFitter.h.

Referenced by iterParam(), LMFitter(), and setIterParam().

double LMFitter::m_lambda [private]
 

The current lambda factor.

Definition at line 56 of file LMFitter.h.

Referenced by calcAlpha(), calcBestFit(), and calcCovariance().

double LMFitter::m_lambda_expand_factor [private]
 

The factor by which lambda is divided if it is too small.

Definition at line 62 of file LMFitter.h.

Referenced by calcBestFit(), and LMFitter().

double LMFitter::m_lambda_shrink_factor [private]
 

The factor by which lambda is divided if it is too large.

Definition at line 59 of file LMFitter.h.

Referenced by calcBestFit(), and LMFitter().

int Fitter::m_max_iterations [protected, inherited]
 

The maximum number of iterations allowed in attempting the fit.

Definition at line 58 of file Fitter.h.

Referenced by calcBestFit(), BFGSFitter::calcBestFit(), iterParam(), BFGSFitter::iterParam(), setIterParam(), and BFGSFitter::setIterParam().

std::string Fitter::m_name [protected, inherited]
 

The name of the fitter.

Definition at line 47 of file Fitter.h.

Referenced by MinuitMigrad::checkIndex(), Fitter::name(), Fitter::setLimits(), and Fitter::setStepSize().

double LMFitter::m_start_lambda [private]
 

The starting lambda factor.

Definition at line 53 of file LMFitter.h.

Referenced by calcBestFit(), and LMFitter().


The documentation for this class was generated from the following files:
Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3