10#ifndef ROOT_Minuit2_FumiliFCNAdapter
11#define ROOT_Minuit2_FumiliFCNAdapter
42template <
class Function>
47 typedef typename Function::Type_t
Type_t;
51 double operator()(std::vector<double>
const &
v)
const override {
return fFunc.operator()(&
v[0]); }
53 double Up()
const override {
return fUp; }
68template <
class Function>
71 MnPrint print(
"FumiliFCNAdapter");
76 print.
Error(
"npar", npar,
"v.size()",
v.size());
77 assert(npar ==
v.size());
80 std::vector<double> &grad =
Gradient();
81 std::vector<double> &hess =
Hessian();
83 assert(grad.size() == npar);
84 grad.assign(npar, 0.0);
85 hess.assign(hess.size(), 0.0);
87 unsigned int ndata =
fFunc.NPoints();
89 std::vector<double> gf(npar);
90 std::vector<double>
h(hess.size());
95 if (
fFunc.Type() == Function::kLeastSquare) {
96 print.
Debug(
"Chi2 FCN: Evaluate gradient and Hessian");
98 for (
unsigned int i = 0; i < ndata; ++i) {
100 double fval =
fFunc.DataElement(&
v.front(), i, &gf[0]);
102 for (
unsigned int j = 0; j < npar; ++j) {
103 grad[j] += 2. * fval * gf[j];
104 for (
unsigned int k = j; k < npar; ++k) {
105 int idx = j + k * (k + 1) / 2;
106 hess[idx] += 2.0 * gf[j] * gf[k];
110 }
else if (
fFunc.Type() == Function::kLogLikelihood) {
111 print.
Debug(
"LogLikelihood FCN: Evaluate gradient and Hessian");
112 for (
unsigned int i = 0; i < ndata; ++i) {
115 fFunc.DataElement(&
v.front(), i, &gf[0]);
117 for (
unsigned int j = 0; j < npar; ++j) {
120 for (
unsigned int k = j; k < npar; ++k) {
121 int idx = j + k * (k + 1) / 2;
122 hess[idx] += gfj * gf[k];
126 }
else if (
fFunc.Type() == Function::kPoissonLikelihood) {
127 print.
Debug(
"Poisson Likelihood FCN: Evaluate gradient and Hessian");
129 for (
unsigned int i = 0; i < ndata; ++i) {
131 fFunc.DataElement(&
v.front(), i, gf.data(),
h.data());
132 for (
size_t j = 0; j < npar; ++j) {
134 for (
unsigned int k = j; k < npar; ++k) {
135 int idx = j + k * (k + 1) / 2;
141 print.
Error(
"Type of fit method is not supported, it must be chi2 or log-likelihood or Poisson Likelihood");
Double_t(* Function)(Double_t)
double Up() const override
Error definition of the function.
double operator()(const double *v) const
void SetErrorDef(double up) override
add interface to set dynamically a new error definition Re-implement this function if needed.
void EvaluateAll(std::vector< double > const &v) override
evaluate gradient hessian and function value needed by Fumili
FumiliFCNAdapter(const Function &f, unsigned int ndim, double up=1.)
double operator()(std::vector< double > const &v) const override
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
FumiliFCNBase()
Default Constructor.
std::vector< double > Hessian(std::vector< double > const &) const override
Return Value of the i-th j-th element of the Hessian matrix estimated previously using the FumiliFCNB...
virtual const std::vector< double > & Gradient() const
Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll me...
virtual unsigned int Dimension()
return number of function variable (parameters) , i.e.
void Debug(const Ts &... args)
void Error(const Ts &... args)