Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FumiliGradientCalculator.cxx
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
17#include "Minuit2/MnPrint.h"
19#include "Minuit2/MnStrategy.h"
20#include "Minuit2/MnUserFcn.h"
21
22namespace ROOT {
23
24namespace Minuit2 {
25
27{
28
29 // Calculate gradient for Fumili using the gradient and Hessian provided by the FCN Fumili function
30 // applying the external to int trasformation.
31
32 int nvar = par.Vec().size();
33 std::vector<double> extParam = fTransformation(par.Vec());
34 // std::vector<double> deriv;
35 // deriv.reserve( nvar );
36 // for (int i = 0; i < nvar; ++i) {
37 // unsigned int ext = fTransformation.ExtOfInt(i);
38 // if ( fTransformation.Parameter(ext).HasLimits())
39 // deriv.push_back( fTransformation.DInt2Ext( i, par.Vec()(i) ) );
40 // else
41 // deriv.push_back(1.0);
42 // }
43
44 // eval Gradient
45 FumiliFCNBase &fcn = const_cast<FumiliFCNBase &>(fFcn);
46
47 fcn.EvaluateAll(extParam);
48
49 MnAlgebraicVector v(nvar);
51
52 const std::vector<double> &fcn_gradient = fFcn.Gradient();
53 assert(fcn_gradient.size() == extParam.size());
54
55 // for (int i = 0; i < nvar; ++i) {
56 // unsigned int iext = fTransformation.ExtOfInt(i);
57 // double ideriv = 1.0;
58 // if ( fTransformation.Parameter(iext).HasLimits())
59 // ideriv = fTransformation.DInt2Ext( i, par.Vec()(i) ) ;
60
61 // // v(i) = fcn_gradient[iext]*deriv;
62 // v(i) = ideriv*fcn_gradient[iext];
63
64 // for (int j = i; j < nvar; ++j) {
65 // unsigned int jext = fTransformation.ExtOfInt(j);
66 // double jderiv = 1.0;
67 // if ( fTransformation.Parameter(jext).HasLimits())
68 // jderiv = fTransformation.DInt2Ext( j, par.Vec()(j) ) ;
69
70 // // h(i,j) = deriv[i]*deriv[j]*fFcn.Hessian(iext,jext);
71 // h(i,j) = ideriv*jderiv*fFcn.Hessian(iext,jext);
72 // }
73 // }
74
75 // cache deriv and Index values .
76 // in large Parameter limit then need to re-optimize and see if better not caching
77
78 std::vector<double> deriv(nvar);
79 std::vector<unsigned int> extIndex(nvar);
80 for (int i = 0; i < nvar; ++i) {
81 extIndex[i] = fTransformation.ExtOfInt(i);
82 deriv[i] = 1;
83 if (fTransformation.Parameter(extIndex[i]).HasLimits())
84 deriv[i] = fTransformation.DInt2Ext(i, par.Vec()(i));
85
86 v(i) = fcn_gradient[extIndex[i]] * deriv[i];
87
88 for (int j = 0; j <= i; ++j) {
89 h(i, j) = deriv[i] * deriv[j] * fFcn.Hessian(extIndex[i], extIndex[j]);
90 }
91 }
92
93 MnPrint print("FumiliGradientCalculator");
94 print.Debug([&](std::ostream &os) {
95 // compare Fumili with Minuit gradient
96
98 FunctionGradient g2 = gc(par);
99
100 os << "Fumili Gradient" << v << "\nMinuit Gradient" << g2.Vec();
101 });
102
103 // store calculated Hessian
104 fHessian = h;
105 return FunctionGradient(v);
106}
107
109
110{
111 // Needed for interface of base class.
112 return this->operator()(par);
113}
114
115} // namespace Minuit2
116
117} // namespace ROOT
#define h(i)
Definition RSha256.hxx:106
Extension of the FCNBase for the Fumili method.
virtual void EvaluateAll(const std::vector< double > &par)=0
Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p ...
virtual const std::vector< double > & Gradient() const
Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll me...
virtual double Hessian(unsigned int row, unsigned int col) const
Return Value of the i-th j-th element of the Hessian matrix estimated previously using the FumiliFCNB...
FunctionGradient operator()(const MinimumParameters &) const
const MnAlgebraicVector & Vec() const
Class describing a symmetric matrix of size n.
Definition LASymMatrix.h:45
unsigned int size() const
Definition LAVector.h:227
const MnAlgebraicVector & Vec() const
void Debug(const Ts &... args)
Definition MnPrint.h:138
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition MnStrategy.h:27
Wrapper used by Minuit of FCN interface containing a reference to the transformation object.
Definition MnUserFcn.h:25
unsigned int ExtOfInt(unsigned int internal) const
double DInt2Ext(unsigned int, double) const
const MinuitParameter & Parameter(unsigned int) const
class performing the numerical gradient calculation
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...