10 #ifndef ROOT_Minuit2_FumiliFCNAdapter 11 #define ROOT_Minuit2_FumiliFCNAdapter 40 template<
class Function>
46 typedef typename Function::Type_t
Type_t;
58 return fFunc.operator()(&v[0]);
61 return fFunc.operator()(
v);
88 template<
class Function>
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");
167 #endif //ROOT_Minuit2_FCNAdapter #define MN_ERROR_MSG(str)
Namespace for new ROOT classes and functions.
double Up() const
Error definition of the function.
double operator()(const double *v) const
std::vector< double > & Hessian()
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...
virtual unsigned int Dimension()
return number of function variable (parameters) , i.e.
template wrapped class for adapting to FumiliFCNBase signature
virtual const std::vector< double > & Gradient() const
Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll me...
Extension of the FCNBase for the Fumili method.
FumiliFCNAdapter(const Function &f, unsigned int ndim, double up=1.)
void EvaluateAll(const std::vector< double > &v)
evaluate gradient hessian and function value needed by fumili