Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MCMCInterval.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Authors: Kevin Belasco 17/06/2009
3// Authors: Kyle Cranmer 17/06/2009
4/*************************************************************************
5 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef RooStats_MCMCInterval
13#define RooStats_MCMCInterval
14
15#include "Rtypes.h"
16
18#include "RooArgSet.h"
19#include "RooArgList.h"
20#include "RooMsgService.h"
22
23#include <vector>
24
25class RooNDKeysPdf;
26class RooProduct;
27
28
29namespace RooStats {
30
31 class Heaviside;
32
33 class MCMCInterval : public ConfInterval {
34
35
36 public:
37
38 /// default constructor
39 explicit MCMCInterval(const char *name = nullptr);
40
41 /// constructor from parameter of interest and Markov chain object
42 MCMCInterval(const char* name, const RooArgSet& parameters,
43 MarkovChain& chain);
44
45 enum {DEFAULT_NUM_BINS = 50};
47
48 ~MCMCInterval() override;
49
50 /// determine whether this point is in the confidence interval
51 bool IsInInterval(const RooArgSet& point) const override;
52
53 /// set the desired confidence level (see GetActualConfidenceLevel())
54 /// Note: calling this function triggers the algorithm that determines
55 /// the interval, so call this after initializing all other aspects
56 /// of this IntervalCalculator
57 /// Also, calling this function again with a different confidence level
58 /// re-triggers the calculation of the interval
59 void SetConfidenceLevel(double cl) override;
60
61 /// get the desired confidence level (see GetActualConfidenceLevel())
62 double ConfidenceLevel() const override {return fConfidenceLevel;}
63
64 /// return a set containing the parameters of this interval
65 /// the caller owns the returned RooArgSet*
66 RooArgSet* GetParameters() const override;
67
68 /// get the cutoff bin height for being considered in the
69 /// confidence interval
70 virtual double GetHistCutoff();
71
72 /// get the cutoff RooNDKeysPdf value for being considered in the
73 /// confidence interval
74 virtual double GetKeysPdfCutoff();
75 ///virtual double GetKeysPdfCutoff() { return fKeysCutoff; }
76
77 /// get the actual value of the confidence level for this interval.
78 virtual double GetActualConfidenceLevel();
79
80 /// whether the specified confidence level is a floor for the actual
81 /// confidence level (strict), or a ceiling (not strict)
82 virtual void SetHistStrict(bool isHistStrict)
83 { fIsHistStrict = isHistStrict; }
84
85 /// check if parameters are correct. (dummy implementation to start)
86 bool CheckParameters(const RooArgSet& point) const override;
87
88 /// Set the parameters of interest for this interval
89 /// and change other internal data members accordingly
90 virtual void SetParameters(const RooArgSet& parameters);
91
92 /// Set the MarkovChain that this interval is based on
93 virtual void SetChain(MarkovChain& chain) { fChain = &chain; }
94
95 /// Set which parameters go on which axis. The first list element
96 /// goes on the x axis, second (if it exists) on y, third (if it
97 /// exists) on z, etc
98 virtual void SetAxes(RooArgList& axes);
99
100 /// return a list of RooRealVars representing the axes
101 /// you own the returned RooArgList
103 {
104 RooArgList* axes = new RooArgList();
105 for (Int_t i = 0; i < fDimension; i++)
106 axes->addClone(*fAxes[i]);
107 return axes;
108 }
109
110 /// get the lowest value of param that is within the confidence interval
111 virtual double LowerLimit(RooRealVar& param);
112
113 /// determine lower limit of the lower confidence interval
114 virtual double LowerLimitTailFraction(RooRealVar& param);
115
116 /// get the lower limit of param in the shortest confidence interval
117 /// Note that this works better for some distributions (ones with exactly
118 /// one maximum) than others, and sometimes has little value.
119 virtual double LowerLimitShortest(RooRealVar& param);
120
121 /// determine lower limit in the shortest interval by using keys pdf
122 virtual double LowerLimitByKeys(RooRealVar& param);
123
124 /// determine lower limit using histogram
125 virtual double LowerLimitByHist(RooRealVar& param);
126
127 /// determine lower limit using histogram
128 virtual double LowerLimitBySparseHist(RooRealVar& param);
129
130 /// determine lower limit using histogram
131 virtual double LowerLimitByDataHist(RooRealVar& param);
132
133 /// get the highest value of param that is within the confidence interval
134 virtual double UpperLimit(RooRealVar& param);
135
136 /// determine upper limit of the lower confidence interval
137 virtual double UpperLimitTailFraction(RooRealVar& param);
138
139 /// get the upper limit of param in the confidence interval
140 /// Note that this works better for some distributions (ones with exactly
141 /// one maximum) than others, and sometimes has little value.
142 virtual double UpperLimitShortest(RooRealVar& param);
143
144 /// determine upper limit in the shortest interval by using keys pdf
145 virtual double UpperLimitByKeys(RooRealVar& param);
146
147 /// determine upper limit using histogram
148 virtual double UpperLimitByHist(RooRealVar& param);
149
150 /// determine upper limit using histogram
151 virtual double UpperLimitBySparseHist(RooRealVar& param);
152
153 /// determine upper limit using histogram
154 virtual double UpperLimitByDataHist(RooRealVar& param);
155
156 /// Determine the approximate maximum value of the Keys PDF
157 double GetKeysMax();
158
159 /// set the number of steps in the chain to discard as burn-in,
160 /// starting from the first
161 virtual void SetNumBurnInSteps(Int_t numBurnInSteps)
162 { fNumBurnInSteps = numBurnInSteps; }
163
164 /// set whether to use kernel estimation to determine the interval
165 virtual void SetUseKeys(bool useKeys) { fUseKeys = useKeys; }
166
167 /// set whether to use a sparse histogram. you MUST also call
168 /// SetUseKeys(false) to use a histogram.
169 virtual void SetUseSparseHist(bool useSparseHist)
170 { fUseSparseHist = useSparseHist; }
171
172 /// get whether we used kernel estimation to determine the interval
173 virtual bool GetUseKeys() { return fUseKeys; }
174
175 /// get the number of steps in the chain to discard as burn-in,
176
177 /// get the number of steps in the chain to discard as burn-in,
178 /// starting from the first
180
181 /// set the number of bins to use (same for all axes, for now)
182 ///virtual void SetNumBins(Int_t numBins);
183
184 /// Get a clone of the histogram of the posterior
185 virtual TH1* GetPosteriorHist();
186
187 /// Get a clone of the keys pdf of the posterior
189
190 /// Get a clone of the (keyspdf * heaviside) product of the posterior
192
193 /// Get the number of parameters of interest in this interval
194 virtual Int_t GetDimension() const { return fDimension; }
195
196 /// Get the markov chain on which this interval is based
197 /// You do not own the returned MarkovChain*
198 virtual const MarkovChain* GetChain() { return fChain; }
199
200 /// Get a clone of the markov chain on which this interval is based
201 /// as a RooDataSet. You own the returned RooDataSet*
202 virtual RooDataSet* GetChainAsDataSet(RooArgSet* whichVars = nullptr)
203 { return fChain->GetAsDataSet(whichVars); }
204
205 /// Get the markov chain on which this interval is based
206 /// as a RooDataSet. You do not own the returned RooDataSet*
208 { return fChain->GetAsConstDataSet(); }
209
210 /// Get a clone of the markov chain on which this interval is based
211 /// as a RooDataHist. You own the returned RooDataHist*
212 virtual RooDataHist* GetChainAsDataHist(RooArgSet* whichVars = nullptr)
213 { return fChain->GetAsDataHist(whichVars); }
214
215 /// Get a clone of the markov chain on which this interval is based
216 /// as a THnSparse. You own the returned THnSparse*
217 virtual THnSparse* GetChainAsSparseHist(RooArgSet* whichVars = nullptr)
218 { return fChain->GetAsSparseHist(whichVars); }
219
220 /// Get a clone of the NLL variable from the markov chain
221 virtual RooRealVar* GetNLLVar() const
222 { return fChain->GetNLLVar(); }
223
224 /// Get a clone of the weight variable from the markov chain
225 virtual RooRealVar* GetWeightVar() const
226 { return fChain->GetWeightVar(); }
227
228 /// set the acceptable level or error for Keys interval determination
229 virtual void SetEpsilon(double epsilon)
230 {
231 if (epsilon < 0)
232 coutE(InputArguments) << "MCMCInterval::SetEpsilon will not allow "
233 << "negative epsilon value" << std::endl;
234 else
236 }
237
238 /// Set the type of interval to find. This will only have an effect for
239 /// 1-D intervals. If is more than 1 parameter of interest, then a
240 /// "shortest" interval will always be used, since it generalizes directly
241 /// to N dimensions
242 virtual void SetIntervalType(enum IntervalType intervalType)
243 { fIntervalType = intervalType; }
245
246 /// Return the type of this interval
247 virtual enum IntervalType GetIntervalType() { return fIntervalType; }
248
249 /// set the left-side tail fraction for a tail-fraction interval
250 virtual void SetLeftSideTailFraction(double a) {
252 fLeftSideTF = a;
253 }
254
255 /// kbelasco: The inner-workings of the class really should not be exposed
256 /// like this in a comment, but it seems to be the only way to give
257 /// the user any control over this process, if they desire it
258 ///
259 /// Set the fraction delta such that
260 /// topCutoff (a) is considered == bottomCutoff (b) iff
261 /// (TMath::Abs(a - b) < TMath::Abs(fDelta * (a + b)/2))
262 /// when determining the confidence interval by Keys
263 virtual void SetDelta(double delta)
264 {
265 if (delta < 0.)
266 coutE(InputArguments) << "MCMCInterval::SetDelta will not allow "
267 << "negative delta value" << std::endl;
268 else
269 fDelta = delta;
270 }
271
272 private:
273 inline bool AcceptableConfLevel(double confLevel);
274 inline bool WithinDeltaFraction(double a, double b);
275
276 protected:
277 // data members
278 RooArgSet fParameters; ///< parameters of interest for this interval
279 MarkovChain* fChain; ///< the markov chain
280 double fConfidenceLevel; ///< Requested confidence level (eg. 0.95 for 95% CL)
281
282 RooDataHist* fDataHist; ///< the binned Markov Chain data
283 THnSparse* fSparseHist; ///< the binned Markov Chain data
284 double fHistConfLevel; ///< the actual conf level determined by hist
285 double fHistCutoff; ///< cutoff bin size to be in interval
286
287 RooNDKeysPdf* fKeysPdf; ///< the kernel estimation pdf
288 RooProduct* fProduct; ///< the (keysPdf * heaviside) product
289 Heaviside* fHeaviside; ///< the Heaviside function
290 RooDataHist* fKeysDataHist; ///< data hist representing product
291 RooRealVar* fCutoffVar; ///< cutoff variable to use for integrating keys pdf
292 double fKeysConfLevel; ///< the actual conf level determined by keys
293 double fKeysCutoff; ///< cutoff keys pdf value to be in interval
294 double fFull; ///< Value of intergral of fProduct
295
296 double fLeftSideTF; ///< left side tail-fraction for interval
297 double fTFConfLevel; ///< the actual conf level of tail-fraction interval
298 std::vector<Int_t> fVector; ///< vector containing the Markov chain data
299 double fVecWeight; ///< sum of weights of all entries in fVector
300 double fTFLower; ///< lower limit of the tail-fraction interval
301 double fTFUpper; ///< upper limit of the tail-fraction interval
302
303 TH1* fHist; ///< the binned Markov Chain data
304
305 bool fUseKeys; ///< whether to use kernel estimation
306 bool fUseSparseHist; ///< whether to use sparse hist (vs. RooDataHist)
307 bool fIsHistStrict; ///< whether the specified confidence level is a
308 ///< floor for the actual confidence level (strict),
309 ///< or a ceiling (not strict) for determination by
310 ///< histogram
311 Int_t fDimension; ///< number of variables
312 Int_t fNumBurnInSteps; ///< number of steps to discard as burn in, starting
313 ///< from the first
314 RooRealVar** fAxes; ///< array of pointers to RooRealVars representing
315 ///< the axes of the histogram
316 ///< fAxes[0] represents x-axis, [1] y, [2] z, etc
317
318 double fEpsilon; ///< acceptable error for Keys interval determination
319
320 double fDelta; ///< topCutoff (a) considered == bottomCutoff (b) iff
321 ///< (TMath::Abs(a - b) < TMath::Abs(fDelta * (a + b)/2));
322 ///< Theoretically, the Abs is not needed here, but
323 ///< floating-point arithmetic does not always work
324 ///< perfectly, and the Abs doesn't hurt
326
327
328 // functions
329 virtual void DetermineInterval();
330 virtual void DetermineShortestInterval();
331 virtual void DetermineTailFractionInterval();
332 virtual void DetermineByHist();
333 virtual void DetermineBySparseHist();
334 virtual void DetermineByDataHist();
335 virtual void DetermineByKeys();
336 virtual void CreateHist();
337 virtual void CreateSparseHist();
338 virtual void CreateDataHist();
339 virtual void CreateKeysPdf();
340 virtual void CreateKeysDataHist();
341 virtual void CreateVector(RooRealVar* param);
342 inline virtual double CalcConfLevel(double cutoff, double full);
343
344 ClassDefOverride(MCMCInterval,1) // Concrete implementation of a ConfInterval based on MCMC calculation
345
346 };
347}
348
349#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define coutE(a)
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
char name[80]
Definition TGX11.cxx:110
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:39
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
Generic N-dimensional implementation of a kernel estimation p.d.f.
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
ConfInterval is an interface class for a generic interval in the RooStats framework.
Represents the Heaviside function.
Definition Heaviside.h:18
MCMCInterval is a concrete implementation of the RooStats::ConfInterval interface.
virtual void CreateDataHist()
virtual bool GetUseKeys()
get whether we used kernel estimation to determine the interval
virtual void DetermineByDataHist()
virtual void DetermineShortestInterval()
virtual double GetActualConfidenceLevel()
virtual double GetKeysPdfCutoff() { return fKeysCutoff; }
double fKeysConfLevel
the actual conf level determined by keys
virtual void CreateVector(RooRealVar *param)
RooDataHist * fDataHist
the binned Markov Chain data
virtual double LowerLimitByDataHist(RooRealVar &param)
determine lower limit using histogram
double fDelta
topCutoff (a) considered == bottomCutoff (b) iff
double fConfidenceLevel
Requested confidence level (eg. 0.95 for 95% CL)
virtual RooDataHist * GetChainAsDataHist(RooArgSet *whichVars=nullptr)
Get a clone of the markov chain on which this interval is based as a RooDataHist.
TH1 * fHist
the binned Markov Chain data
virtual double UpperLimitBySparseHist(RooRealVar &param)
determine upper limit using histogram
virtual void SetUseSparseHist(bool useSparseHist)
set whether to use a sparse histogram.
enum IntervalType fIntervalType
virtual double UpperLimit(RooRealVar &param)
get the highest value of param that is within the confidence interval
RooRealVar * fCutoffVar
cutoff variable to use for integrating keys pdf
virtual void SetDelta(double delta)
kbelasco: The inner-workings of the class really should not be exposed like this in a comment,...
virtual const RooDataSet * GetChainAsConstDataSet()
Get the markov chain on which this interval is based as a RooDataSet.
virtual enum IntervalType GetIntervalType()
Return the type of this interval.
virtual void SetAxes(RooArgList &axes)
Set which parameters go on which axis.
virtual void DetermineByKeys()
double fTFLower
lower limit of the tail-fraction interval
bool fUseSparseHist
whether to use sparse hist (vs. RooDataHist)
double fVecWeight
sum of weights of all entries in fVector
double fLeftSideTF
left side tail-fraction for interval
bool AcceptableConfLevel(double confLevel)
virtual void DetermineBySparseHist()
double GetKeysMax()
Determine the approximate maximum value of the Keys PDF.
RooProduct * fProduct
the (keysPdf * heaviside) product
virtual double LowerLimitBySparseHist(RooRealVar &param)
determine lower limit using histogram
bool WithinDeltaFraction(double a, double b)
double fKeysCutoff
cutoff keys pdf value to be in interval
virtual double LowerLimitShortest(RooRealVar &param)
get the lower limit of param in the shortest confidence interval Note that this works better for some...
virtual double LowerLimitTailFraction(RooRealVar &param)
determine lower limit of the lower confidence interval
virtual TH1 * GetPosteriorHist()
set the number of bins to use (same for all axes, for now) virtual void SetNumBins(Int_t numBins);
Int_t fDimension
number of variables
void SetConfidenceLevel(double cl) override
set the desired confidence level (see GetActualConfidenceLevel()) Note: calling this function trigger...
RooRealVar ** fAxes
array of pointers to RooRealVars representing the axes of the histogram fAxes[0] represents x-axis,...
virtual RooArgList * GetAxes()
return a list of RooRealVars representing the axes you own the returned RooArgList
virtual RooRealVar * GetWeightVar() const
Get a clone of the weight variable from the markov chain.
virtual void SetNumBurnInSteps(Int_t numBurnInSteps)
set the number of steps in the chain to discard as burn-in, starting from the first
virtual void DetermineTailFractionInterval()
double fTFConfLevel
the actual conf level of tail-fraction interval
double fHistConfLevel
the actual conf level determined by hist
virtual void CreateSparseHist()
Heaviside * fHeaviside
the Heaviside function
double fFull
Value of intergral of fProduct.
virtual Int_t GetNumBurnInSteps()
get the number of steps in the chain to discard as burn-in,
virtual double UpperLimitByDataHist(RooRealVar &param)
determine upper limit using histogram
virtual void DetermineInterval()
virtual RooRealVar * GetNLLVar() const
Get a clone of the NLL variable from the markov chain.
virtual void SetUseKeys(bool useKeys)
set whether to use kernel estimation to determine the interval
virtual void SetEpsilon(double epsilon)
set the acceptable level or error for Keys interval determination
virtual const MarkovChain * GetChain()
Get the markov chain on which this interval is based You do not own the returned MarkovChain*.
virtual double CalcConfLevel(double cutoff, double full)
virtual double LowerLimitByHist(RooRealVar &param)
determine lower limit using histogram
virtual double LowerLimit(RooRealVar &param)
get the lowest value of param that is within the confidence interval
virtual double UpperLimitShortest(RooRealVar &param)
get the upper limit of param in the confidence interval Note that this works better for some distribu...
THnSparse * fSparseHist
the binned Markov Chain data
virtual void SetIntervalType(enum IntervalType intervalType)
Set the type of interval to find.
virtual void SetHistStrict(bool isHistStrict)
whether the specified confidence level is a floor for the actual confidence level (strict),...
bool CheckParameters(const RooArgSet &point) const override
check if parameters are correct. (dummy implementation to start)
std::vector< Int_t > fVector
vector containing the Markov chain data
virtual double LowerLimitByKeys(RooRealVar &param)
determine lower limit in the shortest interval by using keys pdf
virtual RooProduct * GetPosteriorKeysProduct()
Get a clone of the (keyspdf * heaviside) product of the posterior.
double fTFUpper
upper limit of the tail-fraction interval
double fHistCutoff
cutoff bin size to be in interval
virtual void SetLeftSideTailFraction(double a)
set the left-side tail fraction for a tail-fraction interval
MarkovChain * fChain
the markov chain
RooArgSet * GetParameters() const override
return a set containing the parameters of this interval the caller owns the returned RooArgSet*
virtual double UpperLimitTailFraction(RooRealVar &param)
determine upper limit of the lower confidence interval
bool fIsHistStrict
whether the specified confidence level is a
virtual RooNDKeysPdf * GetPosteriorKeysPdf()
Get a clone of the keys pdf of the posterior.
virtual double UpperLimitByHist(RooRealVar &param)
determine upper limit using histogram
virtual void CreateKeysPdf()
virtual double UpperLimitByKeys(RooRealVar &param)
determine upper limit in the shortest interval by using keys pdf
Int_t fNumBurnInSteps
number of steps to discard as burn in, starting from the first
virtual void CreateHist()
bool fUseKeys
whether to use kernel estimation
RooDataHist * fKeysDataHist
data hist representing product
virtual void SetShortestInterval()
RooArgSet fParameters
parameters of interest for this interval
bool IsInInterval(const RooArgSet &point) const override
determine whether this point is in the confidence interval
virtual void DetermineByHist()
double ConfidenceLevel() const override
get the desired confidence level (see GetActualConfidenceLevel())
virtual void SetChain(MarkovChain &chain)
Set the MarkovChain that this interval is based on.
virtual void SetParameters(const RooArgSet &parameters)
Set the parameters of interest for this interval and change other internal data members accordingly.
virtual RooDataSet * GetChainAsDataSet(RooArgSet *whichVars=nullptr)
Get a clone of the markov chain on which this interval is based as a RooDataSet.
virtual Int_t GetDimension() const
Get the number of parameters of interest in this interval.
virtual void CreateKeysDataHist()
RooNDKeysPdf * fKeysPdf
the kernel estimation pdf
virtual THnSparse * GetChainAsSparseHist(RooArgSet *whichVars=nullptr)
Get a clone of the markov chain on which this interval is based as a THnSparse.
double fEpsilon
acceptable error for Keys interval determination
virtual double GetKeysPdfCutoff()
get the cutoff RooNDKeysPdf value for being considered in the confidence interval
virtual double GetHistCutoff()
get the cutoff bin height for being considered in the confidence interval
Stores the steps in a Markov Chain of points.
Definition MarkovChain.h:30
virtual RooDataHist * GetAsDataHist(RooArgSet *whichVars=nullptr) const
get this MarkovChain as a RooDataHist whose entries contain the values of whichVars.
virtual RooRealVar * GetWeightVar() const
get a clone of the weight variable
virtual THnSparse * GetAsSparseHist(RooAbsCollection *whichVars=nullptr) const
Get a clone of the markov chain on which this interval is based as a sparse histogram.
virtual RooRealVar * GetNLLVar() const
get a clone of the NLL variable
virtual RooDataSet * GetAsDataSet(RooArgSet *whichVars=nullptr) const
get this MarkovChain as a RooDataSet whose entries contain the values of whichVars.
virtual const RooDataSet * GetAsConstDataSet() const
Definition MarkovChain.h:77
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:58
Efficient multidimensional histogram.
Definition THnSparse.h:36
Namespace for the RooStats classes.
Definition Asimov.h:19
double epsilon
Definition triangle.c:618