Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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/MnFcn.h"
21
22namespace ROOT {
23
24namespace Minuit2 {
25
32
33
35{
36
37 // Calculate gradient and Hessian for Fumili using the gradient and Hessian provided
38 // by the FCN Fumili function
39 // Need to apply internal to external for parameters and the external to int transformation
40 // for the return gradient and Hessian
41
42 MnPrint print("FumiliGradientCalculator");
43
44 int nvar = par.Vec().size();
45 std::vector<double> extParam = fTransformation(par.Vec());
46
47 // eval Gradient
48 FumiliFCNBase &fcn = const_cast<FumiliFCNBase &>(fFcn);
49
50 fcn.EvaluateAll(extParam);
51
52 MnAlgebraicVector v(nvar);
54
55 const std::vector<double> &fcn_gradient = fFcn.Gradient();
56 assert(fcn_gradient.size() == extParam.size());
57
58 // transform gradient and Hessian from external to internal
59 std::vector<double> deriv(nvar);
60 std::vector<unsigned int> extIndex(nvar);
61 for (int i = 0; i < nvar; ++i) {
62 extIndex[i] = fTransformation.ExtOfInt(i);
63 deriv[i] = 1;
64 if (fTransformation.Parameter(extIndex[i]).HasLimits())
65 deriv[i] = fTransformation.DInt2Ext(i, par.Vec()(i));
66
67 v(i) = fcn_gradient[extIndex[i]] * deriv[i];
68
69 for (int j = 0; j <= i; ++j) {
70 h(i, j) = deriv[i] * deriv[j] * fFcn.Hessian(extIndex[i], extIndex[j]);
71 }
72 }
73
74
75 print.Debug([&](std::ostream &os) {
76 // compare Fumili with Minuit gradient
77 os << "Comparison of Fumili Gradient and standard (numerical) Minuit Gradient (done only when debugging enabled)" << std::endl;
81 os << "Fumili Gradient:" << v << std::endl;
82 os << "Minuit Gradient" << grd2.Vec() << std::endl;
83 os << "Fumili Hessian: " << h << std::endl;
84 os << "Numerical g2 " << grd2.G2() << std::endl;
86 });
87
88 // store calculated Hessian
89 fHessian = h;
90 // compute also g2 from diagonal Hessian
92 G2(par,g2);
93
94 return FunctionGradient(v,g2);
95}
96
98
99{
100 // Needed for interface of base class.
101 return this->operator()(par);
102}
104{
105 unsigned int n = par.Vec().size();
106 if (fHessian.Nrow() != n || g2.size() != n) {
107 assert(false);
108 return false;
109 }
110 for (unsigned int i = 0; i < n ; i++) {
111 g2(i) = fHessian(i,i);
112 }
113 return true;
114}
115
117{
118 unsigned int n = par.Vec().size();
119 if (fHessian.Nrow() != n ) {
120 assert(false);
121 return false;
122 }
123 h = fHessian;
124 return true;
125}
126
127} // namespace Minuit2
128
129} // namespace ROOT
#define h(i)
Definition RSha256.hxx:106
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Extension of the FCNBase for the Fumili method.
bool G2(const MinimumParameters &, MnAlgebraicVector &) const override
compute second derivatives (diagonal of Hessian)
FumiliGradientCalculator(const FumiliFCNBase &fcn, const MnUserTransformation &trafo, int n)
FunctionGradient operator()(const MinimumParameters &) const override
bool Hessian(const MinimumParameters &, MnAlgebraicSymMatrix &) const override
compute Hessian matrix
Class describing a symmetric matrix of size n.
Definition MnMatrix.h:438
unsigned int Nrow() const
Definition MnMatrix.h:683
const MnAlgebraicVector & Vec() const
Wrapper class to FCNBase interface used internally by Minuit.
Definition MnFcn.h:34
void Debug(const Ts &... args)
Definition MnPrint.h:135
static int GlobalLevel()
Definition MnPrint.cxx:118
static int SetGlobalLevel(int level)
Definition MnPrint.cxx:111
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
Definition MnStrategy.h:27
class dealing with the transformation between user specified parameters (external) and internal param...
class performing the numerical gradient calculation
const Int_t n
Definition legend1.C:16
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...