Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PoissonLikelihoodFCN.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Fri Aug 17 14:29:24 2007
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2007 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class PoissonLikelihoodFCN
12
13#ifndef ROOT_Fit_PoissonLikelihoodFCN
14#define ROOT_Fit_PoissonLikelihoodFCN
15
17#include "Fit/BasicFCN.h"
18#include "Fit/BinData.h"
19#include "Fit/FitUtil.h"
20#include "Math/IParamFunction.h"
21
22#include <memory>
23#include <vector>
24
25//#define PARALLEL
26// #ifdef PARALLEL
27// #ifndef ROOT_Fit_FitUtilParallel
28// #include "Fit/FitUtilParallel.h"
29// #endif
30// #endif
31
32namespace ROOT {
33
34 namespace Fit {
35
36
37//___________________________________________________________________________________
38/**
39 class evaluating the log likelihood
40 for binned Poisson likelihood fits
41 it is template to distinguish gradient and non-gradient case
42
43 @ingroup FitMethodFunc
44*/
45template<class DerivFunType, class ModelFunType = ROOT::Math::IParamMultiFunction>
46class PoissonLikelihoodFCN : public BasicFCN<DerivFunType,ModelFunType,BinData> {
47
48public:
49 typedef typename ModelFunType::BackendType T;
51
52 typedef ::ROOT::Math::BasicFitMethodFunction<DerivFunType> BaseObjFunction;
54
55 typedef ::ROOT::Math::IParamMultiFunctionTempl<T> IModelFunction;
57
58 /**
59 Constructor from unbin data set and model function (pdf)
60 */
61 PoissonLikelihoodFCN (const std::shared_ptr<BinData> & data, const std::shared_ptr<IModelFunction> & func, int weight = 0, bool extended = true, const ::ROOT::EExecutionPolicy &executionPolicy = ::ROOT::EExecutionPolicy::kSequential ) :
62 BaseFCN( data, func),
63 fIsExtended(extended),
64 fWeight(weight),
65 fNEffPoints(0),
66 fGrad ( std::vector<double> ( func->NPar() ) ),
67 fExecutionPolicy(executionPolicy)
68 { }
69
70 /**
71 Constructor from unbin data set and model function (pdf) managed by the users
72 */
73 PoissonLikelihoodFCN (const BinData & data, const IModelFunction & func, int weight = 0, bool extended = true, const ::ROOT::EExecutionPolicy &executionPolicy = ::ROOT::EExecutionPolicy::kSequential ) :
74 BaseFCN(std::shared_ptr<BinData>(const_cast<BinData*>(&data), DummyDeleter<BinData>()), std::shared_ptr<IModelFunction>(dynamic_cast<IModelFunction*>(func.Clone() ) ) ),
75 fIsExtended(extended),
76 fWeight(weight),
77 fNEffPoints(0),
78 fGrad ( std::vector<double> ( func.NPar() ) ),
79 fExecutionPolicy(executionPolicy)
80 { }
81
82
83 /**
84 Destructor (no operations)
85 */
87
88 /**
89 Copy constructor
90 */
94 fWeight( f.fWeight ),
96 fGrad( f.fGrad),
98 { }
99
100 /**
101 Assignment operator
102 */
104 SetData(rhs.DataPtr() );
107 fGrad = rhs.fGrad;
109 fWeight = rhs.fWeight;
111 }
112
113
114 /// clone the function (need to return Base for Windows)
115 virtual BaseFunction * Clone() const { return new PoissonLikelihoodFCN(*this); }
116
117 // effective points used in the fit
118 virtual unsigned int NFitPoints() const { return fNEffPoints; }
119
120 /// i-th likelihood element and its gradient
121 virtual double DataElement(const double * x, unsigned int i, double * g) const {
122 if (i==0) this->UpdateNCalls();
124 }
125
126 /// evaluate gradient
127 virtual void Gradient(const double *x, double *g) const
128 {
129 // evaluate the Poisson gradient
132 }
133
134 /// get type of fit method function
136
137 bool IsWeighted() const { return (fWeight != 0); }
138
139 // Use the weights in evaluating the likelihood
141 if (fWeight == 0) return; // do nothing if it was not weighted
142 fWeight = 1;
143 }
144
145 // Use sum of the weight squared in evaluating the likelihood
146 // (this is needed for calculating the errors)
147 void UseSumOfWeightSquare(bool on = true) {
148 if (fWeight == 0) return; // do nothing if it was not weighted
149 if (on) fWeight = 2;
150 else fWeight = 1;
151 }
152
153
154protected:
155
156
157private:
158
159 /**
160 Evaluation of the function (required by interface)
161 */
162 virtual double DoEval (const double * x) const {
163 this->UpdateNCalls();
166 }
167
168 // for derivatives
169 virtual double DoDerivative(const double * x, unsigned int icoord ) const {
170 Gradient(x, &fGrad[0]);
171 return fGrad[icoord];
172 }
173
174
175 //data member
176
177 bool fIsExtended; // flag to indicate if is extended (when false is a Multinomial lieklihood), default is true
178 int fWeight; // flag to indicate if needs to evaluate using weight or weight squared (default weight = 0)
179
180 mutable unsigned int fNEffPoints; // number of effective points used in the fit
181
182 mutable std::vector<double> fGrad; // for derivatives
183
185};
186
187 // define useful typedef's
190
191
192 } // end namespace Fit
193
194} // end namespace ROOT
195
196
197#endif /* ROOT_Fit_PoissonLikelihoodFCN */
double
#define f(i)
Definition RSha256.hxx:104
#define g(i)
Definition RSha256.hxx:105
BasicFCN class: base class for the objective functions used in the fits It has a reference to the dat...
Definition BasicFCN.h:40
void SetData(const std::shared_ptr< DataType > &data)
Set the data pointer.
Definition BasicFCN.h:88
std::shared_ptr< IModelFunction > ModelFunctionPtr() const
access to function pointer
Definition BasicFCN.h:80
void SetModelFunction(const std::shared_ptr< IModelFunction > &func)
Set the function pointer.
Definition BasicFCN.h:91
virtual const DataType & Data() const
access to const reference to the data
Definition BasicFCN.h:71
std::shared_ptr< DataType > DataPtr() const
access to data pointer
Definition BasicFCN.h:74
virtual const IModelFunction & ModelFunction() const
access to const reference to the model function
Definition BasicFCN.h:77
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition BinData.h:52
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
virtual unsigned int NFitPoints() const
::ROOT::Math::IParamMultiFunctionTempl< T > IModelFunction
PoissonLikelihoodFCN(const BinData &data, const IModelFunction &func, int weight=0, bool extended=true, const ::ROOT::EExecutionPolicy &executionPolicy=::ROOT::EExecutionPolicy::kSequential)
Constructor from unbin data set and model function (pdf) managed by the users.
virtual double DoDerivative(const double *x, unsigned int icoord) const
virtual double DataElement(const double *x, unsigned int i, double *g) const
i-th likelihood element and its gradient
::ROOT::Math::BasicFitMethodFunction< DerivFunType > BaseObjFunction
PoissonLikelihoodFCN(const PoissonLikelihoodFCN &f)
Copy constructor.
virtual BaseFunction * Clone() const
clone the function (need to return Base for Windows)
virtual ~PoissonLikelihoodFCN()
Destructor (no operations)
virtual double DoEval(const double *x) const
Evaluation of the function (required by interface)
::ROOT::EExecutionPolicy fExecutionPolicy
BaseObjFunction::BaseFunction BaseFunction
virtual void Gradient(const double *x, double *g) const
evaluate gradient
PoissonLikelihoodFCN & operator=(const PoissonLikelihoodFCN &rhs)
Assignment operator.
PoissonLikelihoodFCN(const std::shared_ptr< BinData > &data, const std::shared_ptr< IModelFunction > &func, int weight=0, bool extended=true, const ::ROOT::EExecutionPolicy &executionPolicy=::ROOT::EExecutionPolicy::kSequential)
Constructor from unbin data set and model function (pdf)
BasicFCN< DerivFunType, ModelFunType, BinData > BaseFCN
virtual BaseObjFunction::Type_t Type() const
get type of fit method function
Type_t
enumeration specyfing the possible fit method types
virtual void UpdateNCalls() const
update number of calls
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
Double_t x[n]
Definition legend1.C:17
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition HFitImpl.cxx:133
PoissonLikelihoodFCN< ROOT::Math::IMultiGradFunction, ROOT::Math::IParamMultiFunction > PoissonLLGradFunction
PoissonLikelihoodFCN< ROOT::Math::IMultiGenFunction, ROOT::Math::IParamMultiFunction > PoissonLLFunction
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static double EvalPoissonBinPdf(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int i, double *g)
evaluate the pdf (Poisson) contribution to the logl (return actually log of pdf) and its gradient
Definition FitUtil.h:1439
static void EvalPoissonLogLGradient(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
Definition FitUtil.h:1444
static double EvalPoissonLogL(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
Definition FitUtil.h:1414