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 = 0);
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 virtual ~MCMCInterval();
49
50 /// determine whether this point is in the confidence interval
51 virtual Bool_t IsInInterval(const RooArgSet& point) const;
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 virtual void SetConfidenceLevel(Double_t cl);
60
61 /// get the desired confidence level (see GetActualConfidenceLevel())
62 virtual Double_t ConfidenceLevel() const {return fConfidenceLevel;}
63
64 /// return a set containing the parameters of this interval
65 /// the caller owns the returned RooArgSet*
66 virtual RooArgSet* GetParameters() const;
67
68 /// get the cutoff bin height for being considered in the
69 /// confidence interval
70 virtual Double_t GetHistCutoff();
71
72 /// get the cutoff RooNDKeysPdf value for being considered in the
73 /// confidence interval
74 virtual Double_t GetKeysPdfCutoff();
75 ///virtual Double_t GetKeysPdfCutoff() { return fKeysCutoff; }
76
77 /// get the actual value of the confidence level for this interval.
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_t isHistStrict)
83 { fIsHistStrict = isHistStrict; }
84
85 /// check if parameters are correct. (dummy implementation to start)
86 Bool_t CheckParameters(const RooArgSet& point) const;
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_t LowerLimit(RooRealVar& param);
112
113 /// determine lower limit of the lower confidence interval
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_t LowerLimitShortest(RooRealVar& param);
120
121 /// determine lower limit in the shortest interval by using keys pdf
122 virtual Double_t LowerLimitByKeys(RooRealVar& param);
123
124 /// determine lower limit using histogram
125 virtual Double_t LowerLimitByHist(RooRealVar& param);
126
127 /// determine lower limit using histogram
129
130 /// determine lower limit using histogram
132
133 /// get the highest value of param that is within the confidence interval
134 virtual Double_t UpperLimit(RooRealVar& param);
135
136 /// determine upper limit of the lower confidence interval
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_t UpperLimitShortest(RooRealVar& param);
143
144 /// determine upper limit in the shortest interval by using keys pdf
145 virtual Double_t UpperLimitByKeys(RooRealVar& param);
146
147 /// determine upper limit using histogram
148 virtual Double_t UpperLimitByHist(RooRealVar& param);
149
150 /// determine upper limit using histogram
152
153 /// determine upper limit using histogram
155
156 /// Determine the approximate maximum value of the Keys PDF
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_t useKeys) { fUseKeys = useKeys; }
166
167 /// set whether to use a sparse histogram. you MUST also call
168 /// SetUseKeys(kFALSE) to use a histogram.
169 virtual void SetUseSparseHist(Bool_t useSparseHist)
170 { fUseSparseHist = useSparseHist; }
171
172 /// get whether we used kernel estimation to determine the interval
173 virtual Bool_t 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 = NULL)
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 = NULL)
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 = NULL)
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
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
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_t 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_t AcceptableConfLevel(Double_t confLevel);
275
276 protected:
277 // data members
278 RooArgSet fParameters; // parameters of interest for this interval
279 MarkovChain* fChain; // the markov chain
280 Double_t 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_t fHistConfLevel; // the actual conf level determined by hist
285 Double_t 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_t fKeysConfLevel; // the actual conf level determined by keys
293 Double_t fKeysCutoff; // cutoff keys pdf value to be in interval
294 Double_t fFull; // Value of intergral of fProduct
295
296 Double_t fLeftSideTF; // left side tail-fraction for interval
297 Double_t fTFConfLevel; // the actual conf level of tail-fraction interval
298 std::vector<Int_t> fVector; // vector containing the Markov chain data
299 Double_t fVecWeight; // sum of weights of all entries in fVector
300 Double_t fTFLower; // lower limit of the tail-fraction interval
301 Double_t fTFUpper; // upper limit of the tail-fraction interval
302
303 TH1* fHist; // the binned Markov Chain data
304
305 Bool_t fUseKeys; // whether to use kernel estimation
306 Bool_t fUseSparseHist; // whether to use sparse hist (vs. RooDataHist)
307 Bool_t 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 // LM (not used) Double_t fIntervalSum; // sum of heights of bins in the interval
315 RooRealVar** fAxes; // array of pointers to RooRealVars representing
316 // the axes of the histogram
317 // fAxes[0] represents x-axis, [1] y, [2] z, etc
318
319 Double_t fEpsilon; // acceptable error for Keys interval determination
320
321 Double_t fDelta; // topCutoff (a) considered == bottomCutoff (b) iff
322 // (TMath::Abs(a - b) < TMath::Abs(fDelta * (a + b)/2));
323 // Theoretically, the Abs is not needed here, but
324 // floating-point arithmetic does not always work
325 // perfectly, and the Abs doesn't hurt
327
328
329 // functions
330 virtual void DetermineInterval();
331 virtual void DetermineShortestInterval();
332 virtual void DetermineTailFractionInterval();
333 virtual void DetermineByHist();
334 virtual void DetermineBySparseHist();
335 virtual void DetermineByDataHist();
336 virtual void DetermineByKeys();
337 virtual void CreateHist();
338 virtual void CreateSparseHist();
339 virtual void CreateDataHist();
340 virtual void CreateKeysPdf();
341 virtual void CreateKeysDataHist();
342 virtual void CreateVector(RooRealVar* param);
343 inline virtual Double_t CalcConfLevel(Double_t cutoff, Double_t full);
344
345 ClassDef(MCMCInterval,1) // Concrete implementation of a ConfInterval based on MCMC calculation
346
347 };
348}
349
350#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define coutE(a)
double Double_t
Definition RtypesCore.h:59
#define ClassDef(name, id)
Definition Rtypes.h:325
char name[80]
Definition TGX11.cxx:110
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
The RooDataHist is a container class to hold N-dimensional binned data.
Definition RooDataHist.h:37
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:33
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:39
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 Double_t LowerLimitBySparseHist(RooRealVar &param)
determine lower limit using histogram
virtual void DetermineByDataHist()
virtual Double_t UpperLimitByKeys(RooRealVar &param)
determine upper limit in the shortest interval by using keys pdf
virtual void DetermineShortestInterval()
virtual void CreateVector(RooRealVar *param)
virtual Double_t UpperLimit(RooRealVar &param)
get the highest value of param that is within the confidence interval
RooDataHist * fDataHist
virtual Bool_t IsInInterval(const RooArgSet &point) const
determine whether this point is in the confidence interval
Bool_t CheckParameters(const RooArgSet &point) const
check if parameters are correct. (dummy implementation to start)
virtual RooDataSet * GetChainAsDataSet(RooArgSet *whichVars=NULL)
Get a clone of the markov chain on which this interval is based as a RooDataSet.
virtual Double_t UpperLimitShortest(RooRealVar &param)
get the upper limit of param in the confidence interval Note that this works better for some distribu...
enum IntervalType fIntervalType
virtual Double_t UpperLimitBySparseHist(RooRealVar &param)
determine upper limit using histogram
virtual Bool_t GetUseKeys()
get whether we used kernel estimation to determine the interval
virtual Double_t ConfidenceLevel() const
get the desired confidence level (see GetActualConfidenceLevel())
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()
virtual void DetermineBySparseHist()
virtual TH1 * GetPosteriorHist()
set the number of bins to use (same for all axes, for now) virtual void SetNumBins(Int_t numBins);
virtual Double_t LowerLimitByKeys(RooRealVar &param)
determine lower limit in the shortest interval by using keys pdf
virtual void SetHistStrict(Bool_t isHistStrict)
whether the specified confidence level is a floor for the actual confidence level (strict),...
virtual Double_t GetHistCutoff()
get the cutoff bin height for being considered in the confidence interval
virtual Double_t UpperLimitTailFraction(RooRealVar &param)
determine upper limit of the lower confidence interval
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()
virtual void CreateSparseHist()
virtual Int_t GetNumBurnInSteps()
get the number of steps in the chain to discard as burn-in,
virtual RooDataHist * GetChainAsDataHist(RooArgSet *whichVars=NULL)
Get a clone of the markov chain on which this interval is based as a RooDataHist.
virtual void DetermineInterval()
virtual RooRealVar * GetNLLVar() const
Get a clone of the NLL variable from the markov chain.
Bool_t AcceptableConfLevel(Double_t confLevel)
virtual const MarkovChain * GetChain()
Get the markov chain on which this interval is based You do not own the returned MarkovChain*.
virtual Double_t GetActualConfidenceLevel()
virtual Double_t GetKeysPdfCutoff() { return fKeysCutoff; }
virtual void SetDelta(Double_t delta)
kbelasco: The inner-workings of the class really should not be exposed like this in a comment,...
virtual void SetLeftSideTailFraction(Double_t a)
set the left-side tail fraction for a tail-fraction interval
virtual void SetConfidenceLevel(Double_t cl)
set the desired confidence level (see GetActualConfidenceLevel()) Note: calling this function trigger...
virtual THnSparse * GetChainAsSparseHist(RooArgSet *whichVars=NULL)
Get a clone of the markov chain on which this interval is based as a THnSparse.
virtual Double_t LowerLimitShortest(RooRealVar &param)
get the lower limit of param in the shortest confidence interval Note that this works better for some...
virtual Double_t LowerLimit(RooRealVar &param)
get the lowest value of param that is within the confidence interval
virtual void SetIntervalType(enum IntervalType intervalType)
Set the type of interval to find.
virtual Double_t GetKeysPdfCutoff()
get the cutoff RooNDKeysPdf value for being considered in the confidence interval
std::vector< Int_t > fVector
virtual void SetEpsilon(Double_t epsilon)
set the acceptable level or error for Keys interval determination
virtual Double_t LowerLimitTailFraction(RooRealVar &param)
determine lower limit of the lower confidence interval
virtual RooProduct * GetPosteriorKeysProduct()
Get a clone of the (keyspdf * heaviside) product of the posterior.
virtual Double_t UpperLimitByHist(RooRealVar &param)
determine upper limit using histogram
virtual Double_t UpperLimitByDataHist(RooRealVar &param)
determine upper limit using histogram
virtual Double_t LowerLimitByHist(RooRealVar &param)
determine lower limit using histogram
virtual RooNDKeysPdf * GetPosteriorKeysPdf()
Get a clone of the keys pdf of the posterior.
virtual void CreateKeysPdf()
virtual Double_t LowerLimitByDataHist(RooRealVar &param)
determine lower limit using histogram
virtual void CreateHist()
RooDataHist * fKeysDataHist
virtual void SetShortestInterval()
virtual Double_t CalcConfLevel(Double_t cutoff, Double_t full)
virtual void SetUseKeys(Bool_t useKeys)
set whether to use kernel estimation to determine the interval
virtual void DetermineByHist()
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 void SetUseSparseHist(Bool_t useSparseHist)
set whether to use a sparse histogram.
virtual Int_t GetDimension() const
Get the number of parameters of interest in this interval.
virtual void CreateKeysDataHist()
RooNDKeysPdf * fKeysPdf
Double_t GetKeysMax()
Determine the approximate maximum value of the Keys PDF.
Bool_t WithinDeltaFraction(Double_t a, Double_t b)
virtual RooArgSet * GetParameters() const
return a set containing the parameters of this interval the caller owns the returned RooArgSet*
Stores the steps in a Markov Chain of points.
Definition MarkovChain.h:30
virtual RooRealVar * GetWeightVar() const
get a clone of the weight variable
virtual RooDataHist * GetAsDataHist(RooArgSet *whichVars=NULL) const
get this MarkovChain as a RooDataHist whose entries contain the values of whichVars.
virtual RooRealVar * GetNLLVar() const
get a clone of the NLL variable
virtual const RooDataSet * GetAsConstDataSet() const
Definition MarkovChain.h:77
virtual THnSparse * GetAsSparseHist(RooAbsCollection *whichVars=NULL) const
Get a clone of the markov chain on which this interval is based as a sparse histogram.
virtual RooDataSet * GetAsDataSet(RooArgSet *whichVars=NULL) const
get this MarkovChain as a RooDataSet whose entries contain the values of whichVars.
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
REAL epsilon
Definition triangle.c:617