Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FCNGradAdapter.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Author: L. Moneta 10/2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 ROOT Foundation, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#ifndef ROOT_Minuit2_FCNGradAdapter
11#define ROOT_Minuit2_FCNGradAdapter
12
14#include "Minuit2/MnPrint.h"
15
16#include <vector>
17
18namespace ROOT {
19
20namespace Minuit2 {
21
22/**
23
24
25template wrapped class for adapting to FCNBase signature a IGradFunction
26
27@author Lorenzo Moneta
28
29@ingroup Minuit
30
31*/
32
33template <class Function>
35
36public:
37 FCNGradAdapter(const Function &f, double up = 1.) : fFunc(f), fUp(up), fGrad(std::vector<double>(fFunc.NDim())) {}
38
40
41 double operator()(const std::vector<double> &v) const override { return fFunc.operator()(&v[0]); }
42 double operator()(const double *v) const { return fFunc.operator()(v); }
43
44 double Up() const override { return fUp; }
45
46 std::vector<double> Gradient(const std::vector<double> &v) const override
47 {
48 fFunc.Gradient(&v[0], &fGrad[0]);
49
50 MnPrint("FCNGradAdapter").Debug([&](std::ostream &os) {
51 os << "gradient in FCNAdapter = {";
52 for (unsigned int i = 0; i < fGrad.size(); ++i)
53 os << fGrad[i] << (i == fGrad.size() - 1 ? '}' : '\t');
54 });
55 return fGrad;
56 }
57 std::vector<double> GradientWithPrevResult(const std::vector<double> &v, double *previous_grad, double *previous_g2,
58 double *previous_gstep) const override
59 {
60 fFunc.GradientWithPrevResult(&v[0], &fGrad[0], previous_grad, previous_g2, previous_gstep);
61
62 MnPrint("FCNGradAdapter").Debug([&](std::ostream &os) {
63 os << "gradient in FCNAdapter = {";
64 for (unsigned int i = 0; i < fGrad.size(); ++i)
65 os << fGrad[i] << (i == fGrad.size() - 1 ? '}' : '\t');
66 });
67 return fGrad;
68 }
69 // forward interface
70 // virtual double operator()(int npar, double* params,int iflag = 4) const;
71 bool CheckGradient() const override { return false; }
72
74 if (fFunc.returnsInMinuit2ParameterSpace()) {
76 } else {
78 }
79 }
80
81private:
83 double fUp;
84 mutable std::vector<double> fGrad;
85};
86
87} // end namespace Minuit2
88
89} // end namespace ROOT
90
91#endif // ROOT_Minuit2_FCNGradAdapter
double
#define f(i)
Definition RSha256.hxx:104
Double_t(* Function)(Double_t)
Definition Functor.C:4
template wrapped class for adapting to FCNBase signature a IGradFunction
double Up() const override
Error definition of the function.
FCNGradAdapter(const Function &f, double up=1.)
GradientParameterSpace gradParameterSpace() const override
double operator()(const double *v) const
std::vector< double > Gradient(const std::vector< double > &v) const override
bool CheckGradient() const override
std::vector< double > GradientWithPrevResult(const std::vector< double > &v, double *previous_grad, double *previous_g2, double *previous_gstep) const override
double operator()(const std::vector< double > &v) const override
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
std::vector< double > fGrad
void Debug(const Ts &... args)
Definition MnPrint.h:138
GradientParameterSpace
Extension of the FCNBase for providing the analytical Gradient of the function.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...