Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
LMFitter Class Reference

A Fitter class. More...

#include <LMFitter.h>

Inheritance diagram for LMFitter:
Inheritance graph
[legend]
Collaboration diagram for LMFitter:
Collaboration graph
[legend]

List of all members.

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.
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.
StatedFCNgetFCN ()
 Returns the objective function object.
virtual const std::vector< int > & getFixedFlags () const
 Sets the limits of the model function parameter values.
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.
virtual void setLimits (unsigned int i, double lower, double upper)
 Sets the limits for the parameter of the model function indexed by i.
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 setStepSize (unsigned int i, double size)
 Sets the step size for parameter of the minimization.
void setStepSize (const std::string &name, double size)
 Sets the minimization step size for model function parameter name.
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

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

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>
@author Kaustuv <kaustuv@stanford.edu>
@author Paul F. Kunz <Paul_Kunz@slac.stanford.edu>

Definition at line 33 of file LMFitter.h.


Constructor & Destructor Documentation

LMFitter ( const LMFitter fitter) [private]

The copy constructor.

Definition at line 52 of file LMFitter.cxx.

Referenced by LMFitter::clone().

LMFitter ( const char *  name)

The constructor taking name of fitter as argument.

Definition at line 41 of file LMFitter.cxx.


Member Function Documentation

void calcAlpha ( ) [virtual]

Calculates the alpha matrix.

Todo:
Should probably move this implementation into the FCN.

Definition at line 71 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]
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).

Note:
Thecovarience matrix is inverse of half the hessian at the optimal solution, and this semihessian matrix is nothing but the m_alpha matrix as calculated above BUT w/o the diagonal elements being scaled by the factor of (1+lambda). So we can set lamba = 0 to calculate it.

Reimplemented from Fitter.

Definition at line 94 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 228 of file Fitter.cxx.

References Fitter::m_fcn.

Referenced by FunctionProjector::degreesOfFreedom().

bool calcStep ( ) [virtual]

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

Definition at line 187 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.

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

Implements Fitter.

Definition at line 64 of file LMFitter.cxx.

References LMFitter::LMFitter().

void copyFrom ( const Fitter other) [virtual, inherited]

Makes a copy of other.

Definition at line 49 of file Fitter.cxx.

References Fitter::m_fcn.

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

Fills the vector with the free parameters values.

Definition at line 141 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 72 of file Fitter.cxx.

References Fitter::m_fcn.

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

Sets the limits of the model function parameter values.

Attempts to set the limits of the model function parameter values. This base class implementation throws a FitterException. Derived classes that support setting limits of the parameter values should override this member function. Returns a vector containing flags for which parameters are to be held fixed during objective function minimization.

Definition at line 155 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 118 of file Fitter.cxx.

References Fitter::m_fcn.

bool isCompatible ( const FunctionBase function) const [inherited]

Returns true if the function is compatible with the objective function.

Definition at line 79 of file Fitter.cxx.

References Fitter::m_fcn.

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

Returns the name of the fitter.

Definition at line 56 of file Fitter.cxx.

References Fitter::m_name.

Referenced by Fitter::getParameterIndex(), MinuitMigrad::initialize(), BFGSFitter::iterParam(), and BFGSFitter::setIterParam().

bool needsIntegrated ( ) const [inherited]

Returns true if the Fitter needs integrated intervals.

Definition at line 130 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 221 of file Fitter.cxx.

References Fitter::m_fcn.

Referenced by LMFitter::calcBestFit(), 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 99 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 240 of file LMFitter.cxx.

void setFitCut ( TupleCut cut) [virtual, inherited]

Sets the cut to limit range of fitting.

Definition at line 242 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 249 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 148 of file Fitter.cxx.

References Fitter::m_fcn.

void setFunction ( FunctionBase function) [inherited]

Sets the model function.

Definition at line 90 of file Fitter.cxx.

References Fitter::m_fcn.

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 162 of file Fitter.cxx.

References Fitter::m_name.

Referenced by Fitter::setLimits().

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 196 of file Fitter.cxx.

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

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 204 of file Fitter.cxx.

References Fitter::m_name.

Referenced by Fitter::setStepSize().

void setStepSize ( const std::string &  name,
double  size 
) [inherited]

Sets the minimization step size for model function parameter name.

Definition at line 214 of file Fitter.cxx.

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

void setUseErrors ( bool  yes = true) [inherited]

Sets the fitter to use error data from the DataSource, if available.

Definition at line 109 of file Fitter.cxx.

References Fitter::m_fcn.

Referenced by Fitter::setDataSource().

bool solveSystem ( ) [virtual]

Solves the system.

Definition at line 106 of file LMFitter.cxx.

References LMFitter::m_alpha, and LMFitter::m_beta.

Referenced by LMFitter::calcStep().


Member Data Documentation

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

StatedFCN* m_fcn [protected, inherited]
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().


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

Generated for HippoDraw Class Library by doxygen