00001 // @(#)root/minuit2:$Id: FumiliFCNBase.h 34992 2010-08-25 10:36:11Z moneta $ 00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * 00007 * * 00008 **********************************************************************/ 00009 00010 #ifndef ROOT_Minuit2_FumiliFCNBase 00011 #define ROOT_Minuit2_FumiliFCNBase 00012 00013 #include "Minuit2/FCNBase.h" 00014 #include <cassert> 00015 00016 namespace ROOT { 00017 00018 namespace Minuit2 { 00019 00020 00021 //____________________________________________________________________________________________ 00022 /** 00023 00024 Extension of the FCNBase for the Fumili method. Fumili applies only to 00025 minimization problems used for fitting. The method is based on a 00026 linearization of the model function negleting second derivatives. 00027 User needs to provide the model function. The figure-of-merit describing 00028 the difference between the model function and the actual measurements 00029 has to be implemented by the user in a subclass of FumiliFCNBase. 00030 For an example see the FumiliChi2FCN and FumiliStandardChi2FCN classes. 00031 00032 00033 @author Andras Zsenei and Lorenzo Moneta, Creation date: 23 Aug 2004 00034 00035 @see <A HREF="http://www.cern.ch/winkler/minuit/tutorial/mntutorial.pdf">MINUIT Tutorial</A> on function minimization, section 5 00036 00037 @see FumiliChi2FCN 00038 00039 @see FumiliStandardChi2FCN 00040 00041 @ingroup Minuit 00042 00043 */ 00044 00045 00046 00047 class FumiliFCNBase : public FCNBase { 00048 00049 public: 00050 00051 /** 00052 Default Constructor. Need in this case to create when implementing EvaluateAll the Gradient and Hessian vectors with the right size 00053 */ 00054 00055 FumiliFCNBase() : 00056 fNumberOfParameters(0), 00057 fValue(0) 00058 {} 00059 00060 /** 00061 00062 Constructor which initializes the class with the function provided by the 00063 user for modeling the data. 00064 00065 @param npar the number of parameters 00066 00067 */ 00068 00069 00070 FumiliFCNBase(unsigned int npar) : 00071 fNumberOfParameters(npar), 00072 fValue(0), 00073 fGradient(std::vector<double>(npar)), 00074 fHessian(std::vector<double>(static_cast<int>( 0.5*npar*(npar+1) )) ) 00075 {} 00076 00077 00078 00079 // FumiliFCNBase(const ParametricFunction& modelFCN) { fModelFunction = &modelFCN; } 00080 00081 00082 00083 virtual ~FumiliFCNBase() {} 00084 00085 00086 00087 00088 /** 00089 00090 Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p 00091 The resul is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and 00092 FumiliFCNBase::Hessian methods 00093 00094 @param par vector of parameters 00095 00096 **/ 00097 00098 virtual void EvaluateAll( const std::vector<double> & par ) = 0; 00099 00100 00101 /** 00102 Return cached Value of objective function estimated previously using the FumiliFCNBase::EvaluateAll method 00103 00104 **/ 00105 00106 virtual double Value() const { return fValue; } 00107 00108 /** 00109 Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll method 00110 **/ 00111 00112 virtual const std::vector<double> & Gradient() const { return fGradient; } 00113 00114 /** 00115 Return Value of the i-th j-th element of the Hessian matrix estimated previously using the FumiliFCNBase::EvaluateAll method 00116 @param row row Index of the matrix 00117 @param col col Index of the matrix 00118 **/ 00119 00120 virtual double Hessian(unsigned int row, unsigned int col) const { 00121 assert( row < fGradient.size() && col < fGradient.size() ); 00122 if(row > col) 00123 return fHessian[col+row*(row+1)/2]; 00124 else 00125 return fHessian[row+col*(col+1)/2]; 00126 } 00127 00128 /** 00129 return number of function variable (parameters) , i.e. function dimension 00130 */ 00131 00132 virtual unsigned int Dimension() { return fNumberOfParameters; } 00133 00134 protected : 00135 00136 /** 00137 initialize and reset values of gradien and Hessian 00138 */ 00139 00140 virtual void InitAndReset(unsigned int npar) { 00141 fNumberOfParameters = npar; 00142 fGradient = std::vector<double>(npar); 00143 fHessian = std::vector<double>(static_cast<int>( 0.5*npar*(npar+1) )); 00144 } 00145 00146 // methods to be used by the derived classes to set the values 00147 void SetFCNValue(double value) { fValue = value; } 00148 00149 std::vector<double> & Gradient() { return fGradient; } 00150 00151 std::vector<double> & Hessian() { return fHessian; } 00152 00153 00154 00155 00156 private: 00157 00158 unsigned int fNumberOfParameters; 00159 double fValue; 00160 std::vector<double> fGradient; 00161 std::vector<double> fHessian; 00162 00163 00164 }; 00165 00166 } // namespace Minuit2 00167 00168 } // namespace ROOT 00169 00170 #endif // ROOT_Minuit2_FumiliFCNBase