10#ifndef ROOT_Minuit2_FumiliFCNAdapter
11#define ROOT_Minuit2_FumiliFCNAdapter
40template<
class Function>
46 typedef typename Function::Type_t
Type_t;
58 return fFunc.operator()(&
v[0]);
61 return fFunc.operator()(
v);
88template<
class Function>
94 unsigned int npar = Dimension();
95 if (npar !=
v.size() ) std::cout <<
"npar = " << npar <<
" " <<
v.size() << std::endl;
96 assert(npar ==
v.size());
99 std::vector<double> & grad = Gradient();
100 std::vector<double> & hess = Hessian();
102 assert(grad.size() == npar);
103 grad.assign( npar, 0.0);
104 hess.assign( hess.size(), 0.0);
107 unsigned int ndata = fFunc.NPoints();
109 std::vector<double> gf(npar);
115 if (fFunc.Type() == Function::kLeastSquare) {
117 for (
unsigned int i = 0; i < ndata; ++i) {
119 double fval = fFunc.DataElement(&
v.front(), i, &gf[0]);
124 for (
unsigned int j = 0; j < npar; ++j) {
125 grad[j] += 2. * fval * gf[j];
126 for (
unsigned int k = j; k < npar; ++ k) {
127 int idx = j + k*(k+1)/2;
128 hess[idx] += 2.0 * gf[j] * gf[k];
133 else if (fFunc.Type() == Function::kLogLikelihood) {
136 for (
unsigned int i = 0; i < ndata; ++i) {
140 double fval = fFunc.DataElement(&
v.front(), i, &gf[0]);
144 for (
unsigned int j = 0; j < npar; ++j) {
147 for (
unsigned int k = j; k < npar; ++ k) {
148 int idx = j + k*(k+1)/2;
149 hess[idx] += gfj * gf[k] ;
155 MN_ERROR_MSG(
"FumiliFCNAdapter: type of fit method is not supported, it must be chi2 or log-likelihood");
#define MN_ERROR_MSG(str)
Double_t(* Function)(Double_t)
template wrapped class for adapting to FumiliFCNBase signature
double operator()(const double *v) const
void SetErrorDef(double up)
add interface to set dynamically a new error definition Re-implement this function if needed.
double operator()(const std::vector< double > &v) const
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
void EvaluateAll(const std::vector< double > &v)
evaluate gradient hessian and function value needed by fumili
FumiliFCNAdapter(const Function &f, unsigned int ndim, double up=1.)
double Up() const
Error definition of the function.
Extension of the FCNBase for the Fumili method.
static long int sum(long int i)