NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fitcontroller Class Reference

This class contains the internal fit logic and the interface to the GSL fitting module. More...

#include <fitcontroller.hpp>

Collaboration diagram for Fitcontroller:

Public Member Functions

 Fitcontroller ()
 Default constructor. More...
 
 Fitcontroller (Parser *_parser)
 Constructor taking a pointer to the current parser. More...
 
 ~Fitcontroller ()
 Destructor. More...
 
void setParser (mu::Parser *_parser)
 Register the parser. More...
 
bool fit (FitVector &vx, FitVector &vy, const std::string &__sExpr, const std::string &__sRestrictions, mu::varmap_type &mParamsMap, double __dPrecision=1e-4, int nMaxIterations=500)
 Calculate an unweighted 1D-fit. More...
 
bool fit (FitVector &vx, FitVector &vy, FitVector &vy_w, const std::string &__sExpr, const std::string &__sRestrictions, mu::varmap_type &mParamsMap, double __dPrecision=1e-4, int nMaxIterations=500)
 Calculate a weighted 1D-fit. More...
 
bool fit (FitVector &vx, FitVector &vy, FitMatrix &vz, const std::string &__sExpr, const std::string &__sRestrictions, mu::varmap_type &mParamsMap, double __dPrecision=1e-4, int nMaxIterations=500)
 Calculate an unweighted 2D-fit. More...
 
bool fit (FitVector &vx, FitVector &vy, FitMatrix &vz, FitMatrix &vz_w, const std::string &__sExpr, const std::string &__sRestrictions, mu::varmap_type &mParamsMap, double __dPrecision=1e-4, int nMaxIterations=500)
 Calculate a weighted 2D-fit. More...
 
double getFitChi () const
 Return the weighted sum of the residuals. More...
 
int getIterations () const
 Return the number of needed iterations. More...
 
std::string getFitFunction ()
 Returns the fit function, where each parameter is replaced with its value converted to a string. More...
 
FitMatrix getCovarianceMatrix () const
 Returns the covariance matrix of the performed fit. More...
 

Static Public Attributes

static mu::Parser_fitParser = 0
 
static int nDimensions = 0
 
static mu::varmap_type mParams
 

Private Member Functions

bool fitctrl (const std::string &__sExpr, const std::string &__sRestrictions, FitData &_fData, double __dPrecision, int nMaxIterations)
 This is the central fitting function using the data passed from the interface functions. More...
 

Static Private Member Functions

static int fitfunction (const gsl_vector *params, void *data, gsl_vector *fvals)
 Fit function for the usual case without any restrictions. More...
 
static int fitjacobian (const gsl_vector *params, void *data, gsl_matrix *Jac)
 Create the jacobian matrix without using restrictions. More...
 
static int fitfuncjac (const gsl_vector *params, void *data, gsl_vector *fvals, gsl_matrix *Jac)
 Combination of fit function and the corresponding jacobian. More...
 
static int fitfunctionrestricted (const gsl_vector *params, void *data, gsl_vector *fvals)
 Fit function respecting additional restrictions. More...
 
static int fitjacobianrestricted (const gsl_vector *params, void *data, gsl_matrix *Jac)
 Jacobian matrix respecting additional restrictions. More...
 
static int fitfuncjacrestricted (const gsl_vector *params, void *data, gsl_vector *fvals, gsl_matrix *Jac)
 Combination of fit function and the corresponding jacobian respecting additional restrictions. More...
 
static double evalRestrictions (const mu::value_type *v, int nVals)
 Evaluate additional restrictions. More...
 
static void removeNANVals (gsl_vector *fvals, unsigned int nSize)
 Replace NaNs with some very large value to avoid converging towards NaNs. More...
 
static void removeNANVals (gsl_matrix *Jac, unsigned int nLines, unsigned int nCols)
 Replace NaNs with some very large value to avoid converging towards NaNs. More...
 

Private Attributes

int nIterations
 
double dChiSqr
 
std::string sExpr
 
FitMatrix vCovarianceMatrix
 

Static Private Attributes

static mu::value_typexvar = 0
 
static mu::value_typeyvar = 0
 
static mu::value_typezvar = 0
 

Detailed Description

This class contains the internal fit logic and the interface to the GSL fitting module.

Definition at line 72 of file fitcontroller.hpp.

Constructor & Destructor Documentation

◆ Fitcontroller() [1/2]

Fitcontroller::Fitcontroller ( )

Default constructor.

Definition at line 35 of file fitcontroller.cpp.

References dChiSqr, nIterations, sExpr, xvar, yvar, and zvar.

◆ Fitcontroller() [2/2]

Fitcontroller::Fitcontroller ( Parser _parser)

Constructor taking a pointer to the current parser.

Parameters
_parserParser*

Definition at line 54 of file fitcontroller.cpp.

References _fitParser, mu::ParserBase::GetVar(), xvar, yvar, and zvar.

Here is the call graph for this function:

◆ ~Fitcontroller()

Fitcontroller::~Fitcontroller ( )

Destructor.

Definition at line 67 of file fitcontroller.cpp.

References _fitParser, xvar, yvar, and zvar.

Member Function Documentation

◆ evalRestrictions()

double Fitcontroller::evalRestrictions ( const mu::value_type v,
int  nVals 
)
staticprivate

Evaluate additional restrictions.

Parameters
vconst value_type*
nValsint
Returns
double

Definition at line 502 of file fitcontroller.cpp.

References mu::real().

Referenced by fitctrl(), fitfunctionrestricted(), and fitjacobianrestricted().

Here is the call graph for this function:

◆ fit() [1/4]

bool Fitcontroller::fit ( FitVector vx,
FitVector vy,
const std::string &  __sExpr,
const std::string &  __sRestrictions,
mu::varmap_type mParamsMap,
double  __dPrecision = 1e-4,
int  nMaxIterations = 500 
)
inline

Calculate an unweighted 1D-fit.

Parameters
vxFitVector&
vyFitVector&
__sExprconst std::string&
__sRestrictionsconst std::string&
mParamsMapmu::varmap_type&
__dPrecisiondouble
nMaxIterationsint
Returns
bool

Definition at line 133 of file fitcontroller.hpp.

References fit().

Referenced by applyFitAlgorithm(), calculateChiMap(), and fit().

Here is the call graph for this function:

◆ fit() [2/4]

bool Fitcontroller::fit ( FitVector vx,
FitVector vy,
FitMatrix vz,
const std::string &  __sExpr,
const std::string &  __sRestrictions,
mu::varmap_type mParamsMap,
double  __dPrecision = 1e-4,
int  nMaxIterations = 500 
)
inline

Calculate an unweighted 2D-fit.

Parameters
vxFitVector&
vyFitVector&
vzFitMatrix&
__sExprconst std::string&
__sRestrictionsconst std::string&
mParamsMapmu::varmap_type&
__dPrecisiondouble
nMaxIterationsint
Returns
bool

Definition at line 155 of file fitcontroller.hpp.

References fit().

Here is the call graph for this function:

◆ fit() [3/4]

bool Fitcontroller::fit ( FitVector vx,
FitVector vy,
FitMatrix vz,
FitMatrix vz_w,
const std::string &  __sExpr,
const std::string &  __sRestrictions,
mu::varmap_type mParamsMap,
double  __dPrecision = 1e-4,
int  nMaxIterations = 500 
)

Calculate a weighted 2D-fit.

Parameters
vxFitVector&
vyFitVector&
vzFitMatrix&
vz_wFitMatrix&
__sExprconst string&
__sRestrictionsconst string&
mParamsMapmu::varmap_type&
__dPrecisiondouble
nMaxIterationsint
Returns
bool

Definition at line 844 of file fitcontroller.cpp.

References fitctrl(), mParams, FitData::vx, FitData::vy, FitData::vz, and FitData::vz_w.

Here is the call graph for this function:

◆ fit() [4/4]

bool Fitcontroller::fit ( FitVector vx,
FitVector vy,
FitVector vy_w,
const std::string &  __sExpr,
const std::string &  __sRestrictions,
mu::varmap_type mParamsMap,
double  __dPrecision = 1e-4,
int  nMaxIterations = 500 
)

Calculate a weighted 1D-fit.

Parameters
vxFitVector&
vyFitVector&
vy_wFitVector&
__sExprconst string&
__sRestrictionsconst string&
mParamsMapmu::varmap_type&
__dPrecisiondouble
nMaxIterationsint
Returns
bool

Definition at line 817 of file fitcontroller.cpp.

References fitctrl(), mParams, FitData::vx, FitData::vy, and FitData::vy_w.

Here is the call graph for this function:

◆ fitctrl()

bool Fitcontroller::fitctrl ( const std::string &  __sExpr,
const std::string &  __sRestrictions,
FitData _fData,
double  __dPrecision,
int  nMaxIterations 
)
private

This is the central fitting function using the data passed from the interface functions.

Parameters
__sExprconst string&
__sRestrictionsconst string&
_fDataFitData&
__dPrecisiondouble
nMaxIterationsint
Returns
bool

Definition at line 615 of file fitcontroller.cpp.

References _fitParser, dChiSqr, FitData::dPrecision, mu::ParserBase::Eval(), evalRestrictions(), fitfuncjac(), fitfuncjacrestricted(), fitfunction(), fitfunctionrestricted(), fitjacobian(), fitjacobianrestricted(), func, NumeReKernel::GetAsyncCancelState(), SyntaxError::invalid_position, mu::isinf(), mu::isnan(), mParams, nIterations, SyntaxError::PROCESS_ABORTED_BY_USER, mu::ParserBase::SetExpr(), sExpr, vCovarianceMatrix, FitData::vx, FitData::vy, FitData::vy_w, FitData::vz, and FitData::vz_w.

Referenced by fit().

Here is the call graph for this function:

◆ fitfuncjac()

int Fitcontroller::fitfuncjac ( const gsl_vector *  params,
void *  data,
gsl_vector *  fvals,
gsl_matrix *  Jac 
)
staticprivate

Combination of fit function and the corresponding jacobian.

Parameters
paramsconst gsl_vector*
datavoid*
fvalsgsl_vector*
Jacgsl_matrix*
Returns
int

Definition at line 272 of file fitcontroller.cpp.

References fitfunction(), and fitjacobian().

Referenced by fitctrl().

Here is the call graph for this function:

◆ fitfuncjacrestricted()

int Fitcontroller::fitfuncjacrestricted ( const gsl_vector *  params,
void *  data,
gsl_vector *  fvals,
gsl_matrix *  Jac 
)
staticprivate

Combination of fit function and the corresponding jacobian respecting additional restrictions.

Parameters
paramsconst gsl_vector*
datavoid*
fvalsgsl_vector*
Jacgsl_matrix*
Returns
int

Definition at line 486 of file fitcontroller.cpp.

References fitfunctionrestricted(), and fitjacobianrestricted().

Referenced by fitctrl().

Here is the call graph for this function:

◆ fitfunction()

int Fitcontroller::fitfunction ( const gsl_vector *  params,
void *  data,
gsl_vector *  fvals 
)
staticprivate

Fit function for the usual case without any restrictions.

Parameters
paramsconst gsl_vector*
datavoid*
fvalsgsl_vector*
Returns
int

Definition at line 87 of file fitcontroller.cpp.

References _fitParser, mu::ParserBase::Eval(), mu::isinf(), mu::isnan(), mParams, removeNANVals(), FitData::vx, FitData::vy, FitData::vy_w, FitData::vz, FitData::vz_w, xvar, and yvar.

Referenced by fitctrl(), and fitfuncjac().

Here is the call graph for this function:

◆ fitfunctionrestricted()

int Fitcontroller::fitfunctionrestricted ( const gsl_vector *  params,
void *  data,
gsl_vector *  fvals 
)
staticprivate

Fit function respecting additional restrictions.

Parameters
paramsconst gsl_vector*
datavoid*
fvalsgsl_vector*
Returns
int

Definition at line 290 of file fitcontroller.cpp.

References _fitParser, mu::ParserBase::Eval(), evalRestrictions(), mu::isinf(), mu::isnan(), mParams, removeNANVals(), FitData::vx, FitData::vy, FitData::vy_w, FitData::vz, FitData::vz_w, xvar, and yvar.

Referenced by fitctrl(), and fitfuncjacrestricted().

Here is the call graph for this function:

◆ fitjacobian()

int Fitcontroller::fitjacobian ( const gsl_vector *  params,
void *  data,
gsl_matrix *  Jac 
)
staticprivate

Create the jacobian matrix without using restrictions.

Parameters
paramsconst gsl_vector*
datavoid*
Jacgsl_matrix*
Returns
int

Definition at line 152 of file fitcontroller.cpp.

References _fitParser, FitData::dPrecision, mu::ParserBase::Eval(), mu::isinf(), mu::isnan(), mParams, removeNANVals(), FitData::vx, FitData::vy, FitData::vy_w, FitData::vz, FitData::vz_w, xvar, and yvar.

Referenced by fitctrl(), and fitfuncjac().

Here is the call graph for this function:

◆ fitjacobianrestricted()

int Fitcontroller::fitjacobianrestricted ( const gsl_vector *  params,
void *  data,
gsl_matrix *  Jac 
)
staticprivate

Jacobian matrix respecting additional restrictions.

Parameters
paramsconst gsl_vector*
datavoid*
Jacgsl_matrix*
Returns
int

Definition at line 359 of file fitcontroller.cpp.

References _fitParser, FitData::dPrecision, mu::ParserBase::Eval(), evalRestrictions(), mu::isinf(), mu::isnan(), mParams, removeNANVals(), FitData::vx, FitData::vy, FitData::vy_w, FitData::vz, FitData::vz_w, xvar, and yvar.

Referenced by fitctrl(), and fitfuncjacrestricted().

Here is the call graph for this function:

◆ getCovarianceMatrix()

FitMatrix Fitcontroller::getCovarianceMatrix ( ) const

Returns the covariance matrix of the performed fit.

Returns
FitMatrix

Definition at line 918 of file fitcontroller.cpp.

References vCovarianceMatrix.

Referenced by fitDataSet().

◆ getFitChi()

double Fitcontroller::getFitChi ( ) const
inline

Return the weighted sum of the residuals.

Returns
double

Definition at line 170 of file fitcontroller.hpp.

References dChiSqr.

Referenced by calculateChiMap(), createTeXExport(), fitDataSet(), and getFitOptionsTable().

◆ getFitFunction()

string Fitcontroller::getFitFunction ( )

Returns the fit function, where each parameter is replaced with its value converted to a string.

Returns
string

Definition at line 865 of file fitcontroller.cpp.

References checkDelimiter(), mParams, sExpr, StripSpaces(), and toString().

Referenced by fitDataSet().

Here is the call graph for this function:

◆ getIterations()

int Fitcontroller::getIterations ( ) const
inline

Return the number of needed iterations.

Returns
int

Definition at line 180 of file fitcontroller.hpp.

References nIterations.

Referenced by createTeXExport(), getFitAnalysis(), and getFitOptionsTable().

◆ removeNANVals() [1/2]

void Fitcontroller::removeNANVals ( gsl_matrix *  Jac,
unsigned int  nLines,
unsigned int  nCols 
)
staticprivate

Replace NaNs with some very large value to avoid converging towards NaNs.

Parameters
Jacgsl_matrix*
nLinesunsigned int
nColsunsigned int
Returns
void

Definition at line 568 of file fitcontroller.cpp.

References mu::isinf(), and mu::isnan().

Here is the call graph for this function:

◆ removeNANVals() [2/2]

void Fitcontroller::removeNANVals ( gsl_vector *  fvals,
unsigned int  nSize 
)
staticprivate

Replace NaNs with some very large value to avoid converging towards NaNs.

Parameters
fvalsgsl_vector*
nSizeunsigned int
Returns
void

Definition at line 530 of file fitcontroller.cpp.

References mu::isinf(), and mu::isnan().

Referenced by fitfunction(), fitfunctionrestricted(), fitjacobian(), and fitjacobianrestricted().

Here is the call graph for this function:

◆ setParser()

void Fitcontroller::setParser ( mu::Parser _parser)
inline

Register the parser.

Parameters
_parsermu::Parser*
Returns
void

Definition at line 110 of file fitcontroller.hpp.

References _fitParser, mu::ParserBase::GetVar(), xvar, yvar, and zvar.

Here is the call graph for this function:

Member Data Documentation

◆ _fitParser

Parser * Fitcontroller::_fitParser = 0
static

◆ dChiSqr

double Fitcontroller::dChiSqr
private

Definition at line 83 of file fitcontroller.hpp.

Referenced by Fitcontroller(), fitctrl(), and getFitChi().

◆ mParams

mu::varmap_type Fitcontroller::mParams
static

◆ nDimensions

int Fitcontroller::nDimensions = 0
static

Definition at line 96 of file fitcontroller.hpp.

◆ nIterations

int Fitcontroller::nIterations
private

Definition at line 82 of file fitcontroller.hpp.

Referenced by Fitcontroller(), fitctrl(), and getIterations().

◆ sExpr

std::string Fitcontroller::sExpr
private

Definition at line 84 of file fitcontroller.hpp.

Referenced by Fitcontroller(), fitctrl(), and getFitFunction().

◆ vCovarianceMatrix

FitMatrix Fitcontroller::vCovarianceMatrix
private

Definition at line 85 of file fitcontroller.hpp.

Referenced by fitctrl(), and getCovarianceMatrix().

◆ xvar

mu::value_type * Fitcontroller::xvar = 0
staticprivate

◆ yvar

mu::value_type * Fitcontroller::yvar = 0
staticprivate

◆ zvar

mu::value_type * Fitcontroller::zvar = 0
staticprivate

Definition at line 88 of file fitcontroller.hpp.

Referenced by Fitcontroller(), setParser(), and ~Fitcontroller().


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