Logo ROOT   6.08/07
Reference Guide
FumiliFCNBase.h
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 
10 #ifndef ROOT_Minuit2_FumiliFCNBase
11 #define ROOT_Minuit2_FumiliFCNBase
12 
13 #include "Minuit2/FCNBase.h"
14 #include <cassert>
15 
16 namespace ROOT {
17 
18  namespace Minuit2 {
19 
20 
21 //____________________________________________________________________________________________
22 /**
23 
24 Extension of the FCNBase for the Fumili method. Fumili applies only to
25 minimization problems used for fitting. The method is based on a
26 linearization of the model function negleting second derivatives.
27 User needs to provide the model function. The figure-of-merit describing
28 the difference between the model function and the actual measurements
29 has to be implemented by the user in a subclass of FumiliFCNBase.
30 For an example see the FumiliChi2FCN and FumiliStandardChi2FCN classes.
31 
32 
33 @author Andras Zsenei and Lorenzo Moneta, Creation date: 23 Aug 2004
34 
35 @see <A HREF="http://www.cern.ch/winkler/minuit/tutorial/mntutorial.pdf">MINUIT Tutorial</A> on function minimization, section 5
36 
37 @see FumiliChi2FCN
38 
39 @see FumiliStandardChi2FCN
40 
41 @ingroup Minuit
42 
43  */
44 
45 
46 
47 class FumiliFCNBase : public FCNBase {
48 
49 public:
50 
51  /**
52  Default Constructor. Need in this case to create when implementing EvaluateAll the Gradient and Hessian vectors with the right size
53  */
54 
57  fValue(0)
58  {}
59 
60  /**
61 
62  Constructor which initializes the class with the function provided by the
63  user for modeling the data.
64 
65  @param npar the number of parameters
66 
67  */
68 
69 
70  FumiliFCNBase(unsigned int npar) :
71  fNumberOfParameters(npar),
72  fValue(0),
73  fGradient(std::vector<double>(npar)),
74  fHessian(std::vector<double>(static_cast<int>( 0.5*npar*(npar+1) )) )
75  {}
76 
77 
78 
79 // FumiliFCNBase(const ParametricFunction& modelFCN) { fModelFunction = &modelFCN; }
80 
81 
82 
83  virtual ~FumiliFCNBase() {}
84 
85 
86 
87 
88  /**
89 
90  Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p
91  The resul is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and
92  FumiliFCNBase::Hessian methods
93 
94  @param par vector of parameters
95 
96  **/
97 
98  virtual void EvaluateAll( const std::vector<double> & par ) = 0;
99 
100 
101  /**
102  Return cached Value of objective function estimated previously using the FumiliFCNBase::EvaluateAll method
103 
104  **/
105 
106  virtual double Value() const { return fValue; }
107 
108  /**
109  Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll method
110  **/
111 
112  virtual const std::vector<double> & Gradient() const { return fGradient; }
113 
114  /**
115  Return Value of the i-th j-th element of the Hessian matrix estimated previously using the FumiliFCNBase::EvaluateAll method
116  @param row row Index of the matrix
117  @param col col Index of the matrix
118  **/
119 
120  virtual double Hessian(unsigned int row, unsigned int col) const {
121  assert( row < fGradient.size() && col < fGradient.size() );
122  if(row > col)
123  return fHessian[col+row*(row+1)/2];
124  else
125  return fHessian[row+col*(col+1)/2];
126  }
127 
128  /**
129  return number of function variable (parameters) , i.e. function dimension
130  */
131 
132  virtual unsigned int Dimension() { return fNumberOfParameters; }
133 
134 protected :
135 
136  /**
137  initialize and reset values of gradien and Hessian
138  */
139 
140  virtual void InitAndReset(unsigned int npar) {
141  fNumberOfParameters = npar;
142  fGradient = std::vector<double>(npar);
143  fHessian = std::vector<double>(static_cast<int>( 0.5*npar*(npar+1) ));
144  }
145 
146  // methods to be used by the derived classes to set the values
147  void SetFCNValue(double value) { fValue = value; }
148 
149  std::vector<double> & Gradient() { return fGradient; }
150 
151  std::vector<double> & Hessian() { return fHessian; }
152 
153 
154 
155 
156 private:
157 
158  unsigned int fNumberOfParameters;
159  double fValue;
160  std::vector<double> fGradient;
161  std::vector<double> fHessian;
162 
163 
164 };
165 
166  } // namespace Minuit2
167 
168 } // namespace ROOT
169 
170 #endif // ROOT_Minuit2_FumiliFCNBase
virtual void InitAndReset(unsigned int npar)
initialize and reset values of gradien and Hessian
double par[1]
Definition: unuranDistr.cxx:38
FumiliFCNBase(unsigned int npar)
Constructor which initializes the class with the function provided by the user for modeling the data...
Definition: FumiliFCNBase.h:70
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
void SetFCNValue(double value)
STL namespace.
FumiliFCNBase()
Default Constructor.
Definition: FumiliFCNBase.h:55
std::vector< double > & Gradient()
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...
virtual double Value() const
Return cached Value of objective function estimated previously using the FumiliFCNBase::EvaluateAll m...
std::vector< double > & Hessian()
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:47
std::vector< double > fHessian
virtual void EvaluateAll(const std::vector< double > &par)=0
Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p ...
virtual unsigned int Dimension()
return number of function variable (parameters) , i.e.
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.
Definition: FumiliFCNBase.h:47
std::vector< double > fGradient