FumiliMaximumLikelihoodFCN.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: FumiliMaximumLikelihoodFCN.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_FumiliMaximumLikelihoodFCN
00011 #define ROOT_Minuit2_FumiliMaximumLikelihoodFCN
00012 
00013 #include "FumiliFCNBase.h"
00014 #include <vector>
00015 #include <cmath>
00016 #include <float.h>
00017 #include "Minuit2/ParametricFunction.h"
00018 
00019 namespace ROOT {
00020 
00021    namespace Minuit2 {
00022 
00023 
00024 //#include <iostream>
00025 
00026 /** 
00027 
00028 Extension of the FCNBase for the Fumili method. Fumili applies only to 
00029 minimization problems used for fitting. The method is based on a 
00030 linearization of the model function negleting second derivatives. 
00031 User needs to provide the model function. In this cased the function
00032 to be minimized is the sum of the logarithms of the model function
00033 for the different measurements times -1.
00034 
00035 
00036 @author Andras Zsenei and Lorenzo Moneta, Creation date: 3 Sep 2004
00037 
00038 @see <A HREF="http://www.cern.ch/winkler/minuit/tutorial/mntutorial.pdf">MINUIT Tutorial</A> on function minimization, section 5
00039 
00040 @see FumiliStandardMaximumLikelihoodFCN
00041 
00042 @ingroup Minuit
00043 
00044 \todo Insert a nice latex formula...
00045 
00046 */
00047 
00048 
00049 
00050 class FumiliMaximumLikelihoodFCN : public FumiliFCNBase {
00051 
00052 public:
00053 
00054   FumiliMaximumLikelihoodFCN() {}
00055 
00056   virtual ~FumiliMaximumLikelihoodFCN() {}
00057 
00058 
00059   /**
00060 
00061   Sets the model function for the data (for example gaussian+linear for a peak)
00062 
00063   @param modelFunction a reference to the model function.
00064 
00065   */
00066 
00067   void SetModelFunction(const ParametricFunction& modelFCN) { fModelFunction = &modelFCN; }
00068 
00069 
00070 
00071   /**
00072 
00073   Returns the model function used for the data.
00074 
00075   @return Returns a pointer to the model function.
00076 
00077   */
00078 
00079   const ParametricFunction*  ModelFunction() const { return fModelFunction; }
00080 
00081 
00082 
00083   /**
00084      
00085   Evaluates the model function for the different measurement points and 
00086   the Parameter values supplied, calculates a figure-of-merit for each
00087   measurement and returns a vector containing the result of this
00088   evaluation.
00089 
00090   @param par vector of Parameter values to feed to the model function.
00091 
00092   @return A vector containing the figures-of-merit for the model function evaluated 
00093   for each set of measurements.
00094 
00095   */
00096 
00097   virtual std::vector<double> Elements(const std::vector<double>& par) const = 0;
00098 
00099 
00100 
00101   /**
00102      
00103   Accessor to the parameters of a given measurement. For example in the
00104   case of a chi-square fit with a one-dimensional Gaussian, the Parameter 
00105   characterizing the measurement will be the position. It is the Parameter
00106   that is feeded to the model function.
00107 
00108   @param Index Index of the measueremnt the parameters of which to return
00109   @return A vector containing the values characterizing a measurement
00110 
00111   */
00112 
00113   virtual const std::vector<double> & GetMeasurement(int Index) const = 0;
00114 
00115 
00116   /**
00117 
00118   Accessor to the number of measurements used for calculating the 
00119   present figure of merit.
00120 
00121   @return the number of measurements
00122 
00123   */
00124 
00125   virtual int GetNumberOfMeasurements() const = 0;
00126 
00127 
00128   /**
00129  
00130   Calculates the function for the maximum likelihood method. The user must 
00131   implement in a class which inherits from FumiliChi2FCN the member function
00132   Elements() which will supply the Elements for the sum.
00133 
00134 
00135   @param par vector containing the Parameter values for the model function
00136   
00137   @return The sum of the natural logarithm of the Elements multiplied by -1
00138 
00139   @see FumiliFCNBase#elements
00140 
00141   */
00142   
00143   double operator()(const std::vector<double>& par) const {
00144 
00145     double sumoflogs = 0.0; 
00146     std::vector<double> vecElements =  Elements(par);
00147     unsigned int vecElementsSize = vecElements.size();
00148 
00149     for (unsigned int i = 0; i < vecElementsSize; ++i) { 
00150       double tmp = vecElements[i]; 
00151       //for max likelihood probability have to be positive
00152       assert(tmp >= 0);
00153       if ( tmp < FLT_MIN*5 )
00154         tmp = FLT_MIN*5; 
00155 
00156       sumoflogs -= std::log(tmp);
00157       //std::cout << " i " << tmp << " lik " << sumoflogs << std::endl;
00158     }
00159       
00160 
00161     return sumoflogs; 
00162   }
00163   
00164 
00165 
00166   /**
00167      
00168   !!!!!!!!!!!! to be commented
00169 
00170   */
00171 
00172   virtual double Up() const { return 0.5; }  
00173    
00174  private: 
00175 
00176   // A pointer to the model function which describes the data
00177   const ParametricFunction *fModelFunction;
00178 
00179 };
00180 
00181   }  // namespace Minuit2
00182 
00183 }  // namespace ROOT
00184 
00185 #endif  // ROOT_Minuit2_FumiliMaximumLikelihoodFCN

Generated on Tue Jul 5 14:25:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1