FitMethodFunction.h

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: FitMethodFunction.h 31763 2009-12-10 10:40:21Z moneta $
00002 // Author: L. Moneta Thu Aug 16 15:40:28 2007
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2007  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 // Header file for class FitMethodFunction
00012 
00013 #ifndef ROOT_Math_FitMethodFunction
00014 #define ROOT_Math_FitMethodFunction
00015 
00016 #ifndef ROOT_Math_IFunction
00017 #include "Math/IFunction.h"
00018 #endif
00019 
00020 namespace ROOT { 
00021 
00022    namespace Math { 
00023 
00024 //______________________________________________________________________________________
00025 /** 
00026    FitMethodFunction class 
00027    Interface for objective functions (like chi2 and likelihood used in the fit)
00028    In addition to normal function interface provide interface for calculating each 
00029    data contrinution to the function which is required by some algorithm (like Fumili)
00030 
00031    @ingroup  FitMethodFunc
00032 */ 
00033 template<class FunctionType>
00034 class BasicFitMethodFunction : public FunctionType {
00035 
00036 public:
00037 
00038 
00039    typedef  typename FunctionType::BaseFunc BaseFunction; 
00040 
00041    /// enumeration specyfing the possible fit method types
00042    enum Type_t { kUndefined , kLeastSquare, kLogLikelihood }; 
00043 
00044 
00045    BasicFitMethodFunction(int dim, int npoint) : 
00046       fNDim(dim), 
00047       fNPoints(npoint),
00048       fNCalls(0)
00049    {}
00050 
00051    /** 
00052       Virtual Destructor (no operations)
00053    */ 
00054    virtual ~BasicFitMethodFunction ()  {}  
00055 
00056    /**
00057       Number of dimension (parameters) . From IGenMultiFunction interface
00058     */
00059    virtual unsigned int NDim() const { return fNDim; }
00060 
00061    /**
00062       method returning the data i-th contribution to the fit objective function
00063       For example the residual for the least square functions or the pdf element for the 
00064       likelihood functions. 
00065       Estimating eventually also the gradient of the data element if the passed pointer  is not null
00066     */
00067    virtual double DataElement(const double *x, unsigned int i, double *g = 0) const = 0; 
00068 
00069 
00070    /**
00071       return the number of data points used in evaluating the function
00072     */
00073    virtual unsigned int NPoints() const { return fNPoints; }
00074 
00075    /**
00076       return the type of method, override if needed
00077     */
00078    virtual Type_t Type() const { return kUndefined; }
00079 
00080    /**
00081       return the total number of function calls (overrided if needed)
00082     */
00083    virtual unsigned int NCalls() const { return fNCalls; }
00084 
00085    /**
00086       update number of calls 
00087     */
00088    virtual void UpdateNCalls() const { fNCalls++; }
00089 
00090    /**
00091       reset number of function calls
00092     */
00093    virtual void ResetNCalls() { fNCalls = 0; }
00094 
00095 
00096 
00097 public: 
00098 
00099 
00100 protected: 
00101 
00102 
00103 private: 
00104 
00105    unsigned int fNDim;      // function dimension 
00106    unsigned int fNPoints;   // size of the data
00107    mutable unsigned int fNCalls; // number of function calls
00108 
00109 
00110 }; 
00111 
00112       // define the normal and gradient function
00113       typedef BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>  FitMethodFunction;      
00114       typedef BasicFitMethodFunction<ROOT::Math::IMultiGradFunction> FitMethodGradFunction;
00115 
00116 
00117    } // end namespace Math
00118 
00119 } // end namespace ROOT
00120 
00121 
00122 #endif /* ROOT_Math_FitMethodFunction */

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