25#ifndef FITCONTROLLER_HPP
26#define FITCONTROLLER_HPP
31#include <gsl/gsl_multifit_nlin.h>
32#include <gsl/gsl_blas.h>
33#include <gsl/gsl_vector.h>
35#include "../ParserLib/muParser.h"
36#include "../utils/tools.hpp"
37#include "../ui/error.hpp"
75 static int fitfunction(
const gsl_vector* params,
void* data, gsl_vector* fvals);
76 static int fitjacobian(
const gsl_vector* params,
void* data, gsl_matrix* Jac);
77 static int fitfuncjac(
const gsl_vector* params,
void* data, gsl_vector* fvals, gsl_matrix* Jac);
80 static int fitfuncjacrestricted(
const gsl_vector* params,
void* data, gsl_vector* fvals, gsl_matrix* Jac);
90 bool fitctrl(
const std::string& __sExpr,
const std::string& __sRestrictions,
FitData& _fData,
double __dPrecision,
int nMaxIterations);
91 static void removeNANVals(gsl_vector* fvals,
unsigned int nSize);
92 static void removeNANVals(gsl_matrix* Jac,
unsigned int nLines,
unsigned int nCols);
133 inline 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)
136 return fit(vx,vy, vy_w, __sExpr, __sRestrictions, mParamsMap, __dPrecision, nMaxIterations);
157 FitMatrix vz_w(vz.size(), std::vector<double>(vz[0].size(), 0.0));
158 return fit(vx, vy, vz, vz_w, __sExpr, __sRestrictions, mParamsMap, __dPrecision, nMaxIterations);
This class contains the internal fit logic and the interface to the GSL fitting module.
static mu::value_type * xvar
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.
static int fitfunctionrestricted(const gsl_vector *params, void *data, gsl_vector *fvals)
Fit function respecting additional restrictions.
static mu::value_type * yvar
static mu::value_type * zvar
void setParser(mu::Parser *_parser)
Register the parser.
static mu::Parser * _fitParser
static double evalRestrictions(const mu::value_type *v, int nVals)
Evaluate additional restrictions.
int getIterations() const
Return the number of needed iterations.
static mu::varmap_type mParams
FitMatrix vCovarianceMatrix
FitMatrix getCovarianceMatrix() const
Returns the covariance matrix of the performed fit.
static void removeNANVals(gsl_vector *fvals, unsigned int nSize)
Replace NaNs with some very large value to avoid converging towards NaNs.
static int fitfuncjac(const gsl_vector *params, void *data, gsl_vector *fvals, gsl_matrix *Jac)
Combination of fit function and the corresponding jacobian.
static int fitjacobian(const gsl_vector *params, void *data, gsl_matrix *Jac)
Create the jacobian matrix without using restrictions.
static int fitfunction(const gsl_vector *params, void *data, gsl_vector *fvals)
Fit function for the usual case without any restrictions.
double getFitChi() const
Return the weighted sum of the residuals.
static int fitjacobianrestricted(const gsl_vector *params, void *data, gsl_matrix *Jac)
Jacobian matrix respecting additional restrictions.
~Fitcontroller()
Destructor.
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.
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.
Fitcontroller()
Default constructor.
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.
std::string getFitFunction()
Returns the fit function, where each parameter is replaced with its value converted to a string.
const varmap_type & GetVar() const
Return a map containing the used variables only.
Mathematical expressions parser.
std::vector< std::vector< double > > FitMatrix
Typedef for readability.
std::vector< double > FitVector
Typedef for readability.
Namespace for mathematical applications.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Defines the datapoints, which shall be fitted.