27 #ifndef ROOT_Math_GSLMultiFit
28 #define ROOT_Math_GSLMultiFit
30 #include "gsl/gsl_vector.h"
31 #include "gsl/gsl_matrix.h"
32 #include "gsl/gsl_multifit_nlin.h"
33 #include "gsl/gsl_blas.h"
65 if (
fType == 0)
fType = gsl_multifit_fdfsolver_lmsder;
73 if (
fVec != 0) gsl_vector_free(
fVec);
74 if (
fCov != 0) gsl_matrix_free(
fCov);
89 if (
this == &rhs)
return *
this;
99 fSolver = gsl_multifit_fdfsolver_alloc(
fType, npoints, npar);
104 int Set(
const std::vector<Func> & funcVec,
const double *
x) {
107 unsigned int npts = funcVec.size();
108 if (npts == 0)
return -1;
110 unsigned int npar = funcVec[0].NDim();
119 if (
fVec != 0) gsl_vector_free(
fVec);
120 fVec = gsl_vector_alloc( npar );
121 std::copy(x,x+npar,
fVec->data);
127 if (
fSolver == 0)
return "undefined";
128 return std::string(gsl_multifit_fdfsolver_name(
fSolver) );
133 return gsl_multifit_fdfsolver_iterate(
fSolver);
137 const double *
X()
const {
139 gsl_vector *
x = gsl_multifit_fdfsolver_position(
fSolver);
153 if (
fCov != 0) gsl_matrix_free(
fCov);
154 unsigned int npar =
fSolver->fdf->p;
155 fCov = gsl_matrix_alloc( npar, npar );
156 static double kEpsrel = 0.0001;
157 int ret = gsl_multifit_covar(
fSolver->J, kEpsrel,
fCov);
166 return gsl_multifit_test_gradient(
fVec, absTol);
173 return gsl_multifit_test_delta(
fSolver->dx,
fSolver->x, absTol, relTol);
181 if (g == 0)
return edm;
183 if (c == 0)
return edm;
184 gsl_vector * tmp = gsl_vector_alloc(
fSolver->fdf->p );
185 int status = gsl_blas_dgemv(CblasNoTrans, 1.0,
fCov,
fVec, 0.,tmp);
186 if (status == 0) status |= gsl_blas_ddot(
fVec, tmp, &edm);
187 gsl_vector_free(tmp);
188 if (status != 0)
return -1;
202 const gsl_multifit_fdfsolver_type *
fType;
const gsl_multifit_fdfsolver_type * fType
int TestDelta(double absTol, double relTol) const
test using abs and relative tolerance |dx| < absTol + relTol*|x| for every component ...
GSLMultiFit, internal class for implementing GSL non linear least square GSL fitting.
GSLMultiFit(const gsl_multifit_fdfsolver_type *type=0)
Default constructor No need to specify the type so far since only one solver exists so far...
const double * Gradient() const
gradient value at the minimum
int Set(const std::vector< Func > &funcVec, const double *x)
set the solver parameters
gsl_multifit_fdfsolver * fSolver
const double * CovarMatrix() const
return covariance matrix of the parameters
GSLMultiFit(const GSLMultiFit &)
Copy constructor.
const double * X() const
parameter values at the minimum
GSLMultiFit & operator=(const GSLMultiFit &rhs)
Assignment operator.
int TestGradient(double absTol) const
test gradient (ask from solver gradient vector)
GSLMultiFitFunctionWrapper fFunc
void SetFunction(const FuncVector &f, unsigned int nres, unsigned int npar)
Fill gsl function structure from a C++ function iterator and size and number of residuals.
gsl_multifit_function_fdf * GetFunc()
wrapper to a multi-dim function withtout derivatives for multi-dimensional minimization algorithm ...
void CreateSolver(unsigned int npoints, unsigned int npar)
create the minimizer from the type and size of number of fitting points and number of parameters ...
~GSLMultiFit()
Destructor (no operations)