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)
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 /// \note The MCMCInterval object takes ownership of the passed MarkovChain.
94 virtual void SetChain(MarkovChain& chain) { fChain.reset(&chain); }
95
96 /// Set which parameters go on which axis. The first list element
97 /// goes on the x axis, second (if it exists) on y, third (if it
98 /// exists) on z, etc
99 virtual void SetAxes(RooArgList& axes);
100
101 /// return a list of RooRealVars representing the axes
102 /// you own the returned RooArgList
104 {
105 RooArgList* axes = new RooArgList();
106 for (Int_t i = 0; i < fDimension; i++)
107 axes->addClone(*fAxes[i]);
108 return axes;
109 }
110
111 /// get the lowest value of param that is within the confidence interval
112 virtual double LowerLimit(RooRealVar& param);
113
114 /// determine lower limit of the lower confidence interval
115 virtual double LowerLimitTailFraction(RooRealVar& param);
116
117 /// get the lower limit of param in the shortest confidence interval
118 /// Note that this works better for some distributions (ones with exactly
119 /// one maximum) than others, and sometimes has little value.
120 virtual double LowerLimitShortest(RooRealVar& param);
121
122 /// determine lower limit in the shortest interval by using keys pdf
123 virtual double LowerLimitByKeys(RooRealVar& param);
124
125 /// determine lower limit using histogram
126 virtual double LowerLimitByHist(RooRealVar& param);
127
128 /// determine lower limit using histogram
129 virtual double LowerLimitBySparseHist(RooRealVar& param);
130
131 /// determine lower limit using histogram
132 virtual double LowerLimitByDataHist(RooRealVar& param);
133
134 /// get the highest value of param that is within the confidence interval
135 virtual double UpperLimit(RooRealVar& param);
136
137 /// determine upper limit of the lower confidence interval
138 virtual double UpperLimitTailFraction(RooRealVar& param);
139
140 /// get the upper limit of param in the confidence interval
141 /// Note that this works better for some distributions (ones with exactly
142 /// one maximum) than others, and sometimes has little value.
143 virtual double UpperLimitShortest(RooRealVar& param);
144
145 /// determine upper limit in the shortest interval by using keys pdf
146 virtual double UpperLimitByKeys(RooRealVar& param);
147
148 /// determine upper limit using histogram
149 virtual double UpperLimitByHist(RooRealVar& param);
150
151 /// determine upper limit using histogram
152 virtual double UpperLimitBySparseHist(RooRealVar& param);
153
154 /// determine upper limit using histogram
155 virtual double UpperLimitByDataHist(RooRealVar& param);
156
157 /// Determine the approximate maximum value of the Keys PDF
158 double GetKeysMax();
159
160 /// set the number of steps in the chain to discard as burn-in,
161 /// starting from the first
164
165 /// set whether to use kernel estimation to determine the interval
166 virtual void SetUseKeys(bool useKeys) { fUseKeys = useKeys; }
167
168 /// set whether to use a sparse histogram. you MUST also call
169 /// SetUseKeys(false) to use a histogram.
172
173 /// get whether we used kernel estimation to determine the interval
174 virtual bool GetUseKeys() { return fUseKeys; }
175
176 /// get the number of steps in the chain to discard as burn-in,
177
178 /// get the number of steps in the chain to discard as burn-in,
179 /// starting from the first
181
182 /// set the number of bins to use (same for all axes, for now)
183 ///virtual void SetNumBins(Int_t numBins);
184
185 /// Get a clone of the histogram of the posterior
186 virtual TH1* GetPosteriorHist();
187
188 /// Get a clone of the keys pdf of the posterior
190
191 /// Get a clone of the (keyspdf * heaviside) product of the posterior
193
194 /// Get the number of parameters of interest in this interval
195 virtual Int_t GetDimension() const { return fDimension; }
196
197 /// Get the markov chain on which this interval is based
198 /// You do not own the returned MarkovChain*
199 virtual const MarkovChain* GetChain() { return fChain.get(); }
200
201 /// Get a clone of the markov chain on which this interval is based
202 /// as a RooDataSet. You own the returned RooDataSet*
204 { return fChain->GetAsDataSet(whichVars); }
205
206 /// Get the markov chain on which this interval is based
207 /// as a RooDataSet. You do not own the returned RooDataSet*
209 { return fChain->GetAsConstDataSet(); }
210
211 /// Get a clone of the markov chain on which this interval is based
212 /// as a RooDataHist. You own the returned RooDataHist*
214 { return fChain->GetAsDataHist(whichVars); }
215
216 /// Get a clone of the markov chain on which this interval is based
217 /// as a THnSparse. You own the returned THnSparse*
219 { return fChain->GetAsSparseHist(whichVars); }
220
221 /// Get a clone of the NLL variable from the markov chain
222 virtual RooRealVar* GetNLLVar() const
223 { return fChain->GetNLLVar(); }
224
225 /// Get a clone of the weight variable from the markov chain
226 virtual RooRealVar* GetWeightVar() const
227 { return fChain->GetWeightVar(); }
228
229 /// set the acceptable level or error for Keys interval determination
230 virtual void SetEpsilon(double epsilon)
231 {
232 if (epsilon < 0) {
233 coutE(InputArguments) << "MCMCInterval::SetEpsilon will not allow "
234 << "negative epsilon value" << std::endl;
235 } else {
236 fEpsilon = epsilon;
237 }
238 }
239
240 /// Set the type of interval to find. This will only have an effect for
241 /// 1-D intervals. If is more than 1 parameter of interest, then a
242 /// "shortest" interval will always be used, since it generalizes directly
243 /// to N dimensions
247
248 /// Return the type of this interval
249 virtual enum IntervalType GetIntervalType() { return fIntervalType; }
250
251 /// set the left-side tail fraction for a tail-fraction interval
252 virtual void SetLeftSideTailFraction(double a) {
254 fLeftSideTF = a;
255 }
256
257 /// kbelasco: The inner-workings of the class really should not be exposed
258 /// like this in a comment, but it seems to be the only way to give
259 /// the user any control over this process, if they desire it
260 ///
261 /// Set the fraction delta such that
262 /// topCutoff (a) is considered == bottomCutoff (b) iff
263 /// (std::abs(a - b) < std::abs(fDelta * (a + b)/2))
264 /// when determining the confidence interval by Keys
265 virtual void SetDelta(double delta)
266 {
267 if (delta < 0.) {
268 coutE(InputArguments) << "MCMCInterval::SetDelta will not allow "
269 << "negative delta value" << std::endl;
270 } else {
271 fDelta = delta;
272 }
273 }
274
275 private:
276 inline bool AcceptableConfLevel(double confLevel);
277 inline bool WithinDeltaFraction(double a, double b);
278
279 constexpr static const double DEFAULT_EPSILON = 0.01;
280 constexpr static const double DEFAULT_DELTA = 10e-6;
281
282 protected:
283 RooArgSet fParameters; ///< parameters of interest for this interval
284 std::unique_ptr<MarkovChain> fChain; ///< the markov chain
285 double fConfidenceLevel = 0.0; ///< Requested confidence level (eg. 0.95 for 95% CL)
286
287 std::unique_ptr<RooDataHist> fDataHist; ///< the binned Markov Chain data
288 std::unique_ptr<THnSparse> fSparseHist; ///< the binned Markov Chain data
289 double fHistConfLevel = 0.0; ///< the actual conf level determined by hist
290 double fHistCutoff = -1; ///< cutoff bin size to be in interval
291
292 std::unique_ptr<RooNDKeysPdf> fKeysPdf; ///< the kernel estimation pdf
293 std::unique_ptr<RooProduct> fProduct; ///< the (keysPdf * heaviside) product
294 std::unique_ptr<Heaviside> fHeaviside; ///< the Heaviside function
295 std::unique_ptr<RooDataHist> fKeysDataHist; ///< data hist representing product
296 std::unique_ptr<RooRealVar> fCutoffVar; ///< cutoff variable to use for integrating keys pdf
297 double fKeysConfLevel = 0.0; ///< the actual conf level determined by keys
298 double fKeysCutoff = -1; ///< cutoff keys pdf value to be in interval
299 double fFull = 0.0; ///< Value of intergral of fProduct
300
301 double fLeftSideTF = -1; ///< left side tail-fraction for interval
302 double fTFConfLevel = 0.0; ///< the actual conf level of tail-fraction interval
303 std::vector<Int_t> fVector; ///< vector containing the Markov chain data
304 double fVecWeight = 0; ///< sum of weights of all entries in fVector
305 double fTFLower; ///< lower limit of the tail-fraction interval
306 double fTFUpper; ///< upper limit of the tail-fraction interval
307
308 std::unique_ptr<TH1> fHist; ///< the binned Markov Chain data
309
310 bool fUseKeys = false; ///< whether to use kernel estimation
311 bool fUseSparseHist = false; ///< whether to use sparse hist (vs. RooDataHist)
312 bool fIsHistStrict = true; ///< whether the specified confidence level is a
313 ///< floor for the actual confidence level (strict),
314 ///< or a ceiling (not strict) for determination by
315 ///< histogram
316 Int_t fDimension = 1; ///< number of variables
317 Int_t fNumBurnInSteps = 0; ///< number of steps to discard as burn in, starting
318 ///< from the first
319 std::vector<RooRealVar*> fAxes; ///< array of pointers to RooRealVars representing
320 ///< the axes of the histogram
321 ///< fAxes[0] represents x-axis, [1] y, [2] z, etc
322
323 double fEpsilon = DEFAULT_EPSILON; ///< acceptable error for Keys interval determination
324
325 double fDelta = DEFAULT_DELTA; ///< topCutoff (a) considered == bottomCutoff (b) iff
326 ///< (std::abs(a - b) < std::abs(fDelta * (a + b)/2));
327 ///< Theoretically, the Abs is not needed here, but
328 ///< floating-point arithmetic does not always work
329 ///< perfectly, and the Abs doesn't hurt
331
332 // functions
333 virtual void DetermineInterval();
334 virtual void DetermineShortestInterval();
335 virtual void DetermineTailFractionInterval();
336 virtual void DetermineByHist();
337 virtual void DetermineBySparseHist();
338 virtual void DetermineByDataHist();
339 virtual void DetermineByKeys();
340 virtual void CreateHist();
341 virtual void CreateSparseHist();
342 virtual void CreateDataHist();
343 virtual void CreateKeysPdf();
344 virtual void CreateKeysDataHist();
345 virtual void CreateVector(RooRealVar* param);
346 inline virtual double CalcConfLevel(double cutoff, double full);
347
348 ClassDefOverride(MCMCInterval,2) // Concrete implementation of a ConfInterval based on MCMC calculation
349
350 };
351}
352
353#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
#define coutE(a)
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:24
Container class to hold unbinned data.
Definition RooDataSet.h:32
Generic N-dimensional implementation of a kernel estimation p.d.f.
Represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
Variable that can be changed from the outside.
Definition RooRealVar.h:37
ConfInterval is an interface class for a generic interval in the RooStats framework.
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)
static constexpr const double DEFAULT_EPSILON
std::unique_ptr< Heaviside > fHeaviside
the Heaviside function
virtual double LowerLimitByDataHist(RooRealVar &param)
determine lower limit using histogram
double fDelta
topCutoff (a) considered == bottomCutoff (b) iff (std::abs(a - b) < std::abs(fDelta * (a + b)/2)); Th...
double fConfidenceLevel
Requested confidence level (eg. 0.95 for 95% CL)
virtual double UpperLimitBySparseHist(RooRealVar &param)
determine upper limit using histogram
std::unique_ptr< MarkovChain > fChain
the markov chain
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
std::unique_ptr< RooDataHist > fDataHist
the binned Markov Chain data
virtual void SetDelta(double delta)
kbelasco: The inner-workings of the class really should not be exposed like this in a comment,...
virtual RooFit::OwningPtr< RooDataSet > GetChainAsDataSet(RooArgSet *whichVars=nullptr)
Get a clone of the markov chain on which this interval is based as a RooDataSet.
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.
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);
std::unique_ptr< RooRealVar > fCutoffVar
cutoff variable to use for integrating keys pdf
Int_t fDimension
number of variables
void SetConfidenceLevel(double cl) override
set the desired confidence level (see GetActualConfidenceLevel()) Note: calling this function trigger...
MCMCInterval(const char *name=nullptr)
default constructor
std::unique_ptr< RooProduct > fProduct
the (keysPdf * heaviside) product
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
std::vector< RooRealVar * > fAxes
array of pointers to RooRealVars representing
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()
double fFull
Value of intergral of fProduct.
std::unique_ptr< RooDataHist > fKeysDataHist
data hist representing product
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()
std::unique_ptr< TH1 > fHist
the binned Markov Chain data
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
static constexpr const double DEFAULT_DELTA
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...
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
RooArgSet * GetParameters() const override
return a set containing the parameters of this interval the caller owns the returned RooArgSet*
std::unique_ptr< RooNDKeysPdf > fKeysPdf
the kernel estimation pdf
virtual double UpperLimitTailFraction(RooRealVar &param)
determine upper limit of the lower confidence interval
bool fIsHistStrict
whether the specified confidence level is a floor for the actual confidence level (strict),...
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
std::unique_ptr< THnSparse > fSparseHist
the binned Markov Chain data
virtual void CreateHist()
bool fUseKeys
whether to use kernel estimation
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 Int_t GetDimension() const
Get the number of parameters of interest in this interval.
virtual void CreateKeysDataHist()
virtual THnSparse * GetChainAsSparseHist(RooArgSet *whichVars=nullptr)
Get a clone of the markov chain on which this interval is based as a THnSparse.
virtual RooFit::OwningPtr< RooDataHist > GetChainAsDataHist(RooArgSet *whichVars=nullptr)
Get a clone of the markov chain on which this interval is based as a RooDataHist.
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:26
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Efficient multidimensional histogram.
Definition THnSparse.h:37
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35
Namespace for the RooStats classes.
Definition CodegenImpl.h:58