Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions

Fitter Class Reference

The base class for fitters. More...

#include <Fitter.h>

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

List of all members.

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
 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.
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.
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 ~Fitter ()
 The virtual destructor.

Protected Member Functions

 Fitter (const Fitter &)
 The copy constructor.
 Fitter (const char *name)
 The required 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.

Detailed Description

The base class for fitters.

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

Definition at line 33 of file Fitter.h.


Constructor & Destructor Documentation

Fitter ( const Fitter fitter) [protected]

The copy constructor.

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

Definition at line 34 of file Fitter.cxx.

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

Fitter ( const char *  name) [protected]

The required constructor.

Definition at line 26 of file Fitter.cxx.

~Fitter ( ) [virtual]

The virtual destructor.

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

int calcDegreesOfFreedom ( ) const [virtual]

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

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

References Fitter::m_fcn.

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

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

Returns the objective function object.

Definition at line 72 of file Fitter.cxx.

References Fitter::m_fcn.

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

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

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

References Fitter::m_fcn, Fitter::name(), 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 118 of file Fitter.cxx.

References Fitter::m_fcn.

bool isCompatible ( const FunctionBase function) const

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

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

Returns true if the Fitter needs integrated intervals.

Definition at line 130 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 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)

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

References Fitter::m_fcn.

void setFitCut ( TupleCut cut) [virtual]

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]

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]

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)

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]

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 
)

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 ( const std::string &  name,
double  size 
)

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

References Fitter::m_name.

Referenced by Fitter::setStepSize().

void setUseErrors ( bool  yes = true)

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


Member Data Documentation

StatedFCN* m_fcn [protected]
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