|
||||
File indexing completed on 2025-01-18 10:10:23
0001 // @(#)root/minuit2:$Id$ 0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 0003 0004 /********************************************************************** 0005 * * 0006 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * 0007 * * 0008 **********************************************************************/ 0009 0010 #ifndef ROOT_Minuit2_FumiliFCNBase 0011 #define ROOT_Minuit2_FumiliFCNBase 0012 0013 #include "Minuit2/FCNGradientBase.h" 0014 #include <cassert> 0015 #include <vector> 0016 0017 namespace ROOT { 0018 0019 namespace Minuit2 { 0020 0021 //____________________________________________________________________________________________ 0022 /** 0023 0024 Extension of the FCNBase for the Fumili method. Fumili applies only to 0025 minimization problems used for fitting. The method is based on a 0026 linearization of the model function negleting second derivatives. 0027 User needs to provide the model function. The figure-of-merit describing 0028 the difference between the model function and the actual measurements 0029 has to be implemented by the user in a subclass of FumiliFCNBase. 0030 For an example see the FumiliChi2FCN and FumiliStandardChi2FCN classes. 0031 0032 0033 @author Andras Zsenei and Lorenzo Moneta, Creation date: 23 Aug 2004 0034 0035 @see <A HREF="http://www.cern.ch/winkler/minuit/tutorial/mntutorial.pdf">MINUIT Tutorial</A> on function minimization, 0036 section 5 0037 0038 @see FumiliChi2FCN 0039 0040 @see FumiliStandardChi2FCN 0041 0042 @ingroup Minuit 0043 0044 */ 0045 0046 class FumiliFCNBase : public FCNGradientBase { 0047 0048 public: 0049 /** 0050 Default Constructor. Need in this case to create when implementing EvaluateAll the Gradient and Hessian vectors 0051 with the right size 0052 */ 0053 0054 FumiliFCNBase() : fNumberOfParameters(0), fValue(0) {} 0055 0056 /** 0057 0058 Constructor which initializes the class with the function provided by the 0059 user for modeling the data. 0060 0061 @param npar the number of parameters 0062 0063 */ 0064 0065 FumiliFCNBase(unsigned int npar) 0066 : fNumberOfParameters(npar), fValue(0), fGradient(std::vector<double>(npar)), 0067 fHessian(std::vector<double>(static_cast<int>(0.5 * npar * (npar + 1)))) 0068 { 0069 } 0070 0071 // FumiliFCNBase(const ParametricFunction& modelFCN) { fModelFunction = &modelFCN; } 0072 0073 ~FumiliFCNBase() override {} 0074 0075 /** 0076 0077 Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p 0078 The result is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and 0079 FumiliFCNBase::Hessian methods 0080 0081 @param par vector of parameters 0082 0083 **/ 0084 0085 virtual void EvaluateAll(const std::vector<double> &par) = 0; 0086 0087 /** 0088 Return cached Value of objective function estimated previously using the FumiliFCNBase::EvaluateAll method 0089 0090 **/ 0091 0092 virtual double Value() const { return fValue; } 0093 0094 /** 0095 Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll method 0096 **/ 0097 0098 virtual const std::vector<double> &Gradient() const { return fGradient; } 0099 std::vector<double> Gradient(const std::vector<double> &) const override { return fGradient;} 0100 0101 /** 0102 Return Value of the i-th j-th element of the Hessian matrix estimated previously using the 0103 FumiliFCNBase::EvaluateAll method 0104 @param row row Index of the matrix 0105 @param col col Index of the matrix 0106 **/ 0107 0108 std::vector<double> Hessian(const std::vector<double> &) const override { return fHessian;} 0109 virtual double Hessian(unsigned int row, unsigned int col) const 0110 { 0111 assert(row < fGradient.size() && col < fGradient.size()); 0112 if (row > col) 0113 return fHessian[col + row * (row + 1) / 2]; 0114 else 0115 return fHessian[row + col * (col + 1) / 2]; 0116 } 0117 0118 /** 0119 return number of function variable (parameters) , i.e. function dimension 0120 */ 0121 0122 virtual unsigned int Dimension() { return fNumberOfParameters; } 0123 0124 protected: 0125 /** 0126 initialize and reset values of gradien and Hessian 0127 */ 0128 0129 virtual void InitAndReset(unsigned int npar) 0130 { 0131 fNumberOfParameters = npar; 0132 fGradient = std::vector<double>(npar); 0133 fHessian = std::vector<double>(static_cast<int>(0.5 * npar * (npar + 1))); 0134 } 0135 0136 // methods to be used by the derived classes to set the values 0137 void SetFCNValue(double value) { fValue = value; } 0138 0139 std::vector<double> &Gradient() { return fGradient; } 0140 0141 std::vector<double> &Hessian() { return fHessian; } 0142 0143 private: 0144 unsigned int fNumberOfParameters; 0145 double fValue; 0146 std::vector<double> fGradient; 0147 std::vector<double> fHessian; 0148 }; 0149 0150 } // namespace Minuit2 0151 0152 } // namespace ROOT 0153 0154 #endif // ROOT_Minuit2_FumiliFCNBase
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |