|
||||
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_FumiliMaximumLikelihoodFCN 0011 #define ROOT_Minuit2_FumiliMaximumLikelihoodFCN 0012 0013 #include "FumiliFCNBase.h" 0014 #include "Minuit2/ParametricFunction.h" 0015 #include "Math/Util.h" 0016 #include <vector> 0017 #include <cassert> 0018 0019 namespace ROOT { 0020 0021 namespace Minuit2 { 0022 0023 /** 0024 0025 Extension of the FCNBase for the Fumili method. Fumili applies only to 0026 minimization problems used for fitting. The method is based on a 0027 linearization of the model function negleting second derivatives. 0028 User needs to provide the model function. In this cased the function 0029 to be minimized is the sum of the logarithms of the model function 0030 for the different measurements times -1. 0031 0032 0033 @author Andras Zsenei and Lorenzo Moneta, Creation date: 3 Sep 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 FumiliStandardMaximumLikelihoodFCN 0039 0040 @ingroup Minuit 0041 0042 \todo Insert a nice latex formula... 0043 0044 */ 0045 0046 class FumiliMaximumLikelihoodFCN : public FumiliFCNBase { 0047 0048 public: 0049 FumiliMaximumLikelihoodFCN() {} 0050 0051 ~FumiliMaximumLikelihoodFCN() override {} 0052 0053 /** 0054 0055 Sets the model function for the data (for example gaussian+linear for a peak) 0056 0057 @param modelFCN a reference to the model function. 0058 0059 */ 0060 0061 void SetModelFunction(const ParametricFunction &modelFCN) { fModelFunction = &modelFCN; } 0062 0063 /** 0064 0065 Returns the model function used for the data. 0066 0067 @return Returns a pointer to the model function. 0068 0069 */ 0070 0071 const ParametricFunction *ModelFunction() const { return fModelFunction; } 0072 0073 /** 0074 0075 Evaluates the model function for the different measurement points and 0076 the Parameter values supplied, calculates a figure-of-merit for each 0077 measurement and returns a vector containing the result of this 0078 evaluation. 0079 0080 @param par vector of Parameter values to feed to the model function. 0081 0082 @return A vector containing the figures-of-merit for the model function evaluated 0083 for each set of measurements. 0084 0085 */ 0086 0087 virtual std::vector<double> Elements(const std::vector<double> &par) const = 0; 0088 0089 /** 0090 0091 Accessor to the parameters of a given measurement. For example in the 0092 case of a chi-square fit with a one-dimensional Gaussian, the Parameter 0093 characterizing the measurement will be the position. It is the Parameter 0094 that is passed to the model function. 0095 0096 @param Index Index of the measueremnt the parameters of which to return 0097 @return A vector containing the values characterizing a measurement 0098 0099 */ 0100 0101 virtual const std::vector<double> &GetMeasurement(int Index) const = 0; 0102 0103 /** 0104 0105 Accessor to the number of measurements used for calculating the 0106 present figure of merit. 0107 0108 @return the number of measurements 0109 0110 */ 0111 0112 virtual int GetNumberOfMeasurements() const = 0; 0113 0114 /** 0115 0116 Calculates the function for the maximum likelihood method. The user must 0117 implement in a class which inherits from FumiliChi2FCN the member function 0118 Elements() which will supply the Elements for the sum. 0119 0120 0121 @param par vector containing the Parameter values for the model function 0122 0123 @return The sum of the natural logarithm of the Elements multiplied by -1 0124 0125 @see FumiliFCNBase#elements 0126 0127 */ 0128 0129 double operator()(const std::vector<double> &par) const override 0130 { 0131 0132 double sumoflogs = 0.0; 0133 std::vector<double> vecElements = Elements(par); 0134 unsigned int vecElementsSize = vecElements.size(); 0135 0136 for (unsigned int i = 0; i < vecElementsSize; ++i) { 0137 double tmp = vecElements[i]; 0138 // for max likelihood probability have to be positive 0139 assert(tmp >= 0); 0140 sumoflogs -= ROOT::Math::Util::EvalLog(tmp); 0141 // std::cout << " i " << tmp << " likelihood " << sumoflogs << std::endl; 0142 } 0143 0144 return sumoflogs; 0145 } 0146 0147 /** 0148 0149 !!!!!!!!!!!! to be commented 0150 0151 */ 0152 0153 double Up() const override { return 0.5; } 0154 0155 private: 0156 // A pointer to the model function which describes the data 0157 const ParametricFunction *fModelFunction; 0158 }; 0159 0160 } // namespace Minuit2 0161 0162 } // namespace ROOT 0163 0164 #endif // ROOT_Minuit2_FumiliMaximumLikelihoodFCN
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |