PoissonLikelihoodFCN.h

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: PoissonLikelihoodFCN.h 37232 2010-12-03 18:09:43Z moneta $
00002 // Author: L. Moneta Fri Aug 17 14:29:24 2007
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2007  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class PoissonLikelihoodFCN
00012 
00013 #ifndef ROOT_Fit_PoissonLikelihoodFCN
00014 #define ROOT_Fit_PoissonLikelihoodFCN
00015 
00016 #ifndef ROOT_Math_FitMethodunction
00017 #include "Math/FitMethodFunction.h"
00018 #endif
00019 
00020 #ifndef ROOT_Math_IParamFunction
00021 #include "Math/IParamFunction.h"
00022 #endif
00023 
00024 #ifndef ROOT_Fit_BinData
00025 #include "Fit/BinData.h"
00026 #endif
00027 
00028 #ifndef ROOT_Fit_FitUtil
00029 #include "Fit/FitUtil.h"
00030 #endif
00031 
00032 //#define PARALLEL
00033 // #ifdef PARALLEL
00034 // #ifndef ROOT_Fit_FitUtilParallel
00035 // #include "Fit/FitUtilParallel.h"
00036 // #endif
00037 // #endif
00038 
00039 namespace ROOT {
00040 
00041    namespace Fit {
00042 
00043 
00044 //___________________________________________________________________________________
00045 /**
00046    class evaluating the log likelihood
00047    for binned Poisson likelihood fits
00048    it is template to distinguish gradient and non-gradient case
00049 
00050    @ingroup  FitMethodFunc
00051 */
00052 template<class FunType>
00053 class PoissonLikelihoodFCN : public ::ROOT::Math::BasicFitMethodFunction<FunType>  {
00054 
00055 public:
00056 
00057 
00058    typedef  ::ROOT::Math::BasicFitMethodFunction<FunType> BaseObjFunction;
00059    typedef typename  BaseObjFunction::BaseFunction BaseFunction;
00060 
00061    typedef  ::ROOT::Math::IParamMultiFunction IModelFunction;
00062 
00063 
00064    /**
00065       Constructor from unbin data set and model function (pdf)
00066    */
00067    PoissonLikelihoodFCN (const BinData & data, const IModelFunction & func) :
00068       BaseObjFunction(func.NPar(), data.Size() ),
00069       fData(data),
00070       fFunc(func),
00071       fNEffPoints(0),
00072       fGrad ( std::vector<double> ( func.NPar() ) )
00073    { }
00074 
00075 
00076    /**
00077       Destructor (no operations)
00078    */
00079    ~PoissonLikelihoodFCN () {}
00080 
00081 private:
00082    // usually copying is non trivial, so we declare but don't implement them
00083 
00084    /**
00085       Copy constructor
00086    */
00087    PoissonLikelihoodFCN(const PoissonLikelihoodFCN &);
00088 
00089    /**
00090       Assignment operator
00091    */
00092    PoissonLikelihoodFCN & operator = (const PoissonLikelihoodFCN &);
00093 
00094 public:
00095 
00096    /// clone the function (need to return Base for Windows)
00097    virtual BaseFunction * Clone() const { return new  PoissonLikelihoodFCN(fData,fFunc); }
00098 
00099    // effective points used in the fit
00100    virtual unsigned int NFitPoints() const { return fNEffPoints; }
00101 
00102    /// i-th likelihood element and its gradient
00103    virtual double DataElement(const double * x, unsigned int i, double * g) const {
00104       if (i==0) this->UpdateNCalls();
00105       return FitUtil::EvaluatePoissonBinPdf(fFunc, fData, x, i, g);
00106    }
00107 
00108    /// evaluate gradient
00109    virtual void Gradient(const double *x, double *g) const {
00110       // evaluate the chi2 gradient
00111       FitUtil::EvaluatePoissonLogLGradient(fFunc, fData, x, g );
00112    }
00113 
00114    /// get type of fit method function
00115    virtual  typename BaseObjFunction::Type_t Type() const { return BaseObjFunction::kLogLikelihood; }
00116 
00117    /// access to const reference to the data
00118    virtual const BinData & Data() const { return fData; }
00119 
00120    /// access to const reference to the model function
00121    virtual const IModelFunction & ModelFunction() const { return fFunc; }
00122 
00123 
00124 protected:
00125 
00126 
00127 private:
00128 
00129    /**
00130       Evaluation of the  function (required by interface)
00131     */
00132    virtual double DoEval (const double * x) const {
00133       this->UpdateNCalls();
00134       return FitUtil::EvaluatePoissonLogL(fFunc, fData, x, fNEffPoints);
00135    }
00136 
00137    // for derivatives
00138    virtual double  DoDerivative(const double * x, unsigned int icoord ) const {
00139       Gradient(x, &fGrad[0]);
00140       return fGrad[icoord];
00141    }
00142 
00143 
00144       //data member
00145 
00146    const BinData & fData;
00147    const IModelFunction & fFunc;
00148 
00149    mutable unsigned int fNEffPoints;  // number of effective points used in the fit
00150 
00151    mutable std::vector<double> fGrad; // for derivatives
00152 
00153 };
00154 
00155       // define useful typedef's
00156       typedef PoissonLikelihoodFCN<ROOT::Math::IMultiGenFunction> PoissonLLFunction;
00157       typedef PoissonLikelihoodFCN<ROOT::Math::IMultiGradFunction> PoissonLLGradFunction;
00158 
00159 
00160    } // end namespace Fit
00161 
00162 } // end namespace ROOT
00163 
00164 
00165 #endif /* ROOT_Fit_PoissonLikelihoodFCN */

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