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"
34#include "gsl/gsl_version.h"
66#if GSL_MAJOR_VERSION > 1
71 if (
fType == 0)
fType = gsl_multifit_fdfsolver_lmsder;
79 if (
fVec != 0) gsl_vector_free(
fVec);
80 if (
fTmp != 0) gsl_vector_free(
fTmp);
81 if (
fCov != 0) gsl_matrix_free(
fCov);
82#if GSL_MAJOR_VERSION > 1
83 if (fJac != 0) gsl_matrix_free(fJac);
99 if (
this == &rhs)
return *
this;
109 fSolver = gsl_multifit_fdfsolver_alloc(
fType, npoints, npar);
110 if (
fVec != 0) gsl_vector_free(
fVec);
111 fVec = gsl_vector_alloc( npar );
112 if (
fTmp != 0) gsl_vector_free(
fTmp);
113 fTmp = gsl_vector_alloc( npar );
114 if (
fCov != 0) gsl_matrix_free(
fCov);
115 fCov = gsl_matrix_alloc( npar, npar );
116#if GSL_MAJOR_VERSION > 1
117 if (fJac != 0) gsl_matrix_free(fJac);
118 fJac = gsl_matrix_alloc( npoints, npar );
124 int Set(
const std::vector<Func> & funcVec,
const double *
x) {
127 unsigned int npts = funcVec.size();
128 if (npts == 0)
return -1;
130 unsigned int npar = funcVec[0].NDim();
141 std::copy(
x,
x+npar,
fVec->data);
143 gsl_vector_set_zero(
fTmp);
145 gsl_matrix_set_zero(
fCov);
146#if GSL_MAJOR_VERSION > 1
148 gsl_matrix_set_zero(fJac);
154 if (
fSolver == 0)
return "undefined";
155 return std::string(gsl_multifit_fdfsolver_name(
fSolver) );
160 return gsl_multifit_fdfsolver_iterate(
fSolver);
164 const double *
X()
const {
166 gsl_vector *
x = gsl_multifit_fdfsolver_position(
fSolver);
173#if GSL_MAJOR_VERSION > 1
184 static double kEpsrel = 0.0001;
185#if GSL_MAJOR_VERSION > 1
186 gsl_multifit_fdfsolver_jac (
fSolver, fJac);
187 int ret = gsl_multifit_covar(fJac, kEpsrel,
fCov);
189 int ret = gsl_multifit_covar(
fSolver->J, kEpsrel,
fCov);
199 return gsl_multifit_test_gradient(
fVec, absTol);
206 return gsl_multifit_test_delta(
fSolver->dx,
fSolver->x, absTol, relTol);
214 if (
g == 0)
return edm;
216 if (
c == 0)
return edm;
217 if (
fTmp == 0)
return edm;
218 int status = gsl_blas_dgemv(CblasNoTrans, 1.0,
fCov,
fVec, 0.,
fTmp);
219 if (status == 0) status |= gsl_blas_ddot(
fVec,
fTmp, &edm);
220 if (status != 0)
return -1;
235#if GSL_MAJOR_VERSION > 1
236 mutable gsl_matrix * fJac;
238 const gsl_multifit_fdfsolver_type *
fType;
wrapper to a multi-dim function withtout derivatives for multi-dimensional minimization algorithm
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()
GSLMultiFit, internal class for implementing GSL non linear least square GSL fitting.
int TestGradient(double absTol) const
test gradient (ask from solver gradient vector)
GSLMultiFit(const GSLMultiFit &)
Copy constructor.
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)
int TestDelta(double absTol, double relTol) const
test using abs and relative tolerance |dx| < absTol + relTol*|x| for every component
GSLMultiFitFunctionWrapper fFunc
gsl_multifit_fdfsolver * fSolver
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.
GSLMultiFit & operator=(const GSLMultiFit &rhs)
Assignment operator.
const double * Gradient() const
gradient value at the minimum
const gsl_multifit_fdfsolver_type * fType
const double * CovarMatrix() const
return covariance matrix of the parameters
const double * X() const
parameter values at the minimum
int Set(const std::vector< Func > &funcVec, const double *x)
set the solver parameters
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...