Fitter Class Reference

#include <Fitter.h>

Inheritance diagram for Fitter:

Inheritance graph
BFGSFitterLMFitterMinuitMigrad
[legend]
Collaboration diagram for Fitter:

Collaboration graph
StatedFCNFCNBaseFunctionBase
[legend]
List of all members.

Detailed Description

The base class for fitters.

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

Definition at line 33 of file Fitter.h.

Public Member Functions

virtual bool calcBestFit ()=0
 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 Fitterclone () const=0
 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
 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.
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 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.
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 ~Fitter ()
 The virtual destructor.

Protected Member Functions

 Fitter (const char *name)
 The required constructor.
 Fitter (const Fitter &)
 The copy constructor.

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

unsigned int getParameterIndex (const std::string &name)
 Returns the index to the model function parameters name.


Constructor & Destructor Documentation

Fitter ( const Fitter  )  [protected]

The copy constructor.

Makes a copy of the data members and a clone of the StatedFCN.

Definition at line 32 of file Fitter.cxx.

References Fitter::clone(), and Fitter::m_fcn.

Fitter ( const char *  name  )  [protected]

The required constructor.

Definition at line 24 of file Fitter.cxx.

~Fitter (  )  [virtual]

The virtual destructor.

Definition at line 40 of file Fitter.cxx.

References Fitter::m_fcn.


Member Function Documentation

virtual bool calcBestFit (  )  [pure virtual]

Calculates the best fit.

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

Implemented in BFGSFitter, LMFitter, and MinuitMigrad.

Referenced by hippodraw::Python::export_Fitter(), and FunctionProjector::fitFunction().

int calcCovariance ( std::vector< std::vector< double > > &  cov  )  [virtual]

Calculates the covariance matrix.

Returns EXIT_SUCCESS if a minima of the objective functions is found, returns EXIT_FAILURE in case algorithm converges on other stationary points (i.e. on saddle points).

This member function should be overridden by a derived class if supported. The implementation in this base class returns EXIT_FAILURE.

Reimplemented in BFGSFitter, LMFitter, and MinuitMigrad.

Definition at line 233 of file Fitter.cxx.

int calcDegreesOfFreedom (  )  const [virtual]

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

virtual Fitter* clone (  )  const [pure 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.

Implemented in BFGSFitter, LMFitter, and MinuitMigrad.

Referenced by Fitter::Fitter().

void copyFrom ( const Fitter other  )  [virtual]

Makes a copy of other.

Definition at line 47 of file Fitter.cxx.

References Fitter::m_fcn.

void fillFreeParameters ( std::vector< double > &   )  const

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

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]

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

unsigned int getParameterIndex ( const std::string &  name  )  [private]

Returns the index to the model function parameters name.

If name is not found, throws a std::runtime_error.

Definition at line 170 of file Fitter.cxx.

References Fitter::m_fcn, and num_util::size().

Referenced by Fitter::setLimits(), and Fitter::setStepSize().

bool getUseErrors (  )  const

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

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

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

Returns true if the Fitter needs integrated intervals.

Definition at line 128 of file Fitter.cxx.

References Fitter::m_fcn.

double objectiveValue (  )  const [virtual]

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  ) 

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

Sets the objective function object to be used and takes possession of it. That is, will delete an existing object, if there is one, and will delete the object in this object's destructor.

Attention:
A derived class that has special requirements, such as need for partial derivatives with respect to the parameters should override this method to set those requirements.

Reimplemented in LMFitter.

Definition at line 61 of file Fitter.cxx.

References Fitter::m_fcn.

Referenced by LMFitter::setFCN().

void setFitCut ( TupleCut cut  )  [virtual]

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]

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]

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  ) 

Sets the model function.

Definition at line 88 of file Fitter.cxx.

References Fitter::m_fcn.

void setLimits ( const std::string &  name,
double  lower,
double  upper 
)

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]

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 
)

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]

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  ) 

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


Member Data Documentation

StatedFCN* m_fcn [protected]

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

int m_max_iterations [protected]

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]

The name of the fitter.

Definition at line 51 of file Fitter.h.

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


The documentation for this class was generated from the following files:
Generated for HippoDraw Class Library by doxygen