Logo ROOT  
Reference Guide
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 
11 #include "Minuit2/FumiliFCNBase.h"
15 #include "Minuit2/FumiliChi2FCN.h"
17 #include "Minuit2/MnPrint.h"
19 #include "Minuit2/MnStrategy.h"
20 #include "Minuit2/MnUserFcn.h"
21 
22 namespace ROOT {
23 
24 namespace 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);
50  MnAlgebraicSymMatrix h(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
ROOT::Minuit2::LAVector
Definition: LAVector.h:32
ROOT::Minuit2::MnPrint::Debug
void Debug(const Ts &... args)
Definition: MnPrint.h:138
ROOT::Minuit2::FumiliFCNBase
Extension of the FCNBase for the Fumili method.
Definition: FumiliFCNBase.h:46
MnStrategy.h
MnUserTransformation.h
ROOT::Minuit2::FumiliFCNBase::Gradient
virtual const std::vector< double > & Gradient() const
Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll me...
Definition: FumiliFCNBase.h:98
ROOT::Minuit2::LASymMatrix
Class describing a symmetric matrix of size n.
Definition: LASymMatrix.h:45
ROOT::Minuit2::MinimumParameters::Vec
const MnAlgebraicVector & Vec() const
Definition: MinimumParameters.h:38
ROOT::Minuit2::FunctionGradient::Vec
const MnAlgebraicVector & Vec() const
Definition: FunctionGradient.h:41
ROOT::Minuit2::FunctionGradient
Definition: FunctionGradient.h:21
ROOT::Minuit2::FumiliGradientCalculator::fFcn
const FumiliFCNBase & fFcn
Definition: FumiliGradientCalculator.h:42
v
@ v
Definition: rootcling_impl.cxx:3664
Numerical2PGradientCalculator.h
FumiliChi2FCN.h
ROOT::Minuit2::Numerical2PGradientCalculator
class performing the numerical gradient calculation
Definition: Numerical2PGradientCalculator.h:32
ROOT::Minuit2::MinimumParameters
Definition: MinimumParameters.h:21
ROOT::Minuit2::FumiliFCNBase::Hessian
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...
Definition: FumiliFCNBase.h:107
FunctionGradient.h
ROOT::Minuit2::FumiliGradientCalculator::fHessian
MnAlgebraicSymMatrix fHessian
Definition: FumiliGradientCalculator.h:44
h
#define h(i)
Definition: RSha256.hxx:106
ROOT::Minuit2::FumiliGradientCalculator::fTransformation
const MnUserTransformation & fTransformation
Definition: FumiliGradientCalculator.h:43
FumiliGradientCalculator.h
ROOT::Minuit2::MnUserTransformation::Parameter
const MinuitParameter & Parameter(unsigned int) const
Definition: MnUserTransformation.cxx:263
ROOT::Minuit2::MinuitParameter::HasLimits
bool HasLimits() const
Definition: MinuitParameter.h:154
ROOT::Minuit2::MnUserFcn
Wrapper used by Minuit of FCN interface containing a reference to the transformation object.
Definition: MnUserFcn.h:25
ROOT::Minuit2::LAVector::size
unsigned int size() const
Definition: LAVector.h:227
FumiliMaximumLikelihoodFCN.h
ROOT::Minuit2::MnStrategy
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
Definition: MnStrategy.h:27
MnUserFcn.h
ROOT::Minuit2::FumiliGradientCalculator::operator()
FunctionGradient operator()(const MinimumParameters &) const
Definition: FumiliGradientCalculator.cxx:26
ROOT::Minuit2::FumiliFCNBase::EvaluateAll
virtual void EvaluateAll(const std::vector< double > &par)=0
Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p ...
ROOT::Minuit2::MnUserTransformation::DInt2Ext
double DInt2Ext(unsigned int, double) const
Definition: MnUserTransformation.cxx:190
MinimumParameters.h
FumiliFCNBase.h
MnPrint.h
ROOT::Minuit2::MnUserTransformation::ExtOfInt
unsigned int ExtOfInt(unsigned int internal) const
Definition: MnUserTransformation.h:102
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MnPrint
Definition: MnPrint.h:73