![]() |
|
|||
File indexing completed on 2025-09-17 09:14:06
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/FCNBase.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 FCNBase { 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 bool HasGradient() const override { return true; } 0057 0058 /** 0059 0060 Constructor which initializes the class with the function provided by the 0061 user for modeling the data. 0062 0063 @param npar the number of parameters 0064 0065 */ 0066 0067 FumiliFCNBase(unsigned int npar) 0068 : fNumberOfParameters(npar), fValue(0), fGradient(std::vector<double>(npar)), 0069 fHessian(std::vector<double>(static_cast<int>(0.5 * npar * (npar + 1)))) 0070 { 0071 } 0072 0073 0074 /** 0075 0076 Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p 0077 The result is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and 0078 FumiliFCNBase::Hessian methods 0079 0080 @param par vector of parameters 0081 0082 **/ 0083 0084 virtual void EvaluateAll(std::vector<double> const& par) = 0; 0085 0086 /** 0087 Return cached Value of objective function estimated previously using the FumiliFCNBase::EvaluateAll method 0088 0089 **/ 0090 0091 virtual double Value() const { return fValue; } 0092 0093 /** 0094 Return cached Value of function Gradient estimated previously using the FumiliFCNBase::EvaluateAll method 0095 **/ 0096 0097 virtual const std::vector<double> &Gradient() const { return fGradient; } 0098 std::vector<double> Gradient(std::vector<double> const&) const override { return fGradient;} 0099 0100 /** 0101 Return Value of the i-th j-th element of the Hessian matrix estimated previously using the 0102 FumiliFCNBase::EvaluateAll method 0103 @param row row Index of the matrix 0104 @param col col Index of the matrix 0105 **/ 0106 0107 std::vector<double> Hessian(std::vector<double> const&) const override { return fHessian;} 0108 virtual double Hessian(unsigned int row, unsigned int col) const 0109 { 0110 assert(row < fGradient.size() && col < fGradient.size()); 0111 if (row > col) 0112 return fHessian[col + row * (row + 1) / 2]; 0113 else 0114 return fHessian[row + col * (col + 1) / 2]; 0115 } 0116 0117 /** 0118 return number of function variable (parameters) , i.e. function dimension 0119 */ 0120 0121 virtual unsigned int Dimension() { return fNumberOfParameters; } 0122 0123 protected: 0124 /** 0125 initialize and reset values of gradien and Hessian 0126 */ 0127 0128 virtual void InitAndReset(unsigned int npar) 0129 { 0130 fNumberOfParameters = npar; 0131 fGradient = std::vector<double>(npar); 0132 fHessian = std::vector<double>(static_cast<int>(0.5 * npar * (npar + 1))); 0133 } 0134 0135 // methods to be used by the derived classes to set the values 0136 void SetFCNValue(double value) { fValue = value; } 0137 0138 std::vector<double> &Gradient() { return fGradient; } 0139 0140 std::vector<double> &Hessian() { return fHessian; } 0141 0142 private: 0143 unsigned int fNumberOfParameters; 0144 double fValue; 0145 std::vector<double> fGradient; 0146 std::vector<double> fHessian; 0147 }; 0148 0149 } // namespace Minuit2 0150 0151 } // namespace ROOT 0152 0153 #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 |
![]() ![]() |