Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
BayesianCalculator.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOSTATS_BayesianCalculator
12#define ROOSTATS_BayesianCalculator
13
14#include "TNamed.h"
15
16#include "Math/IFunctionfwd.h"
17
18#include "RooArgSet.h"
19
21
23
24class RooAbsData;
25class RooAbsPdf;
26class RooPlot;
27class RooAbsReal;
28class TF1;
29class TH1;
30
31
32namespace RooStats {
33
34 class ModelConfig;
35 class SimpleInterval;
36
38
39 public:
40
41 /// constructor
43
45 RooAbsPdf& pdf,
46 const RooArgSet& POI,
47 RooAbsPdf& priorPdf,
48 const RooArgSet* nuisanceParameters = nullptr );
49
51 ModelConfig& model );
52
53 /// destructor
54 ~BayesianCalculator() override;
55
56 /// get the plot with option to get it normalized
57 RooPlot* GetPosteriorPlot(bool norm = false, double precision = 0.01) const;
58
59 /// return posterior pdf (object is managed by the user)
61 /// return posterior function (object is managed by the BayesianCalculator class)
63
64 /// return the approximate posterior as histogram (TH1 object). Note the object is managed by the BayesianCalculator class
65 TH1 * GetPosteriorHistogram() const;
66
67 /// compute the interval. By Default a central interval is computed
68 /// By using SetLeftTileFraction can control if central/ upper/lower interval
69 /// For shortest interval use SetShortestInterval(true)
70 SimpleInterval* GetInterval() const override ;
71
72 void SetData( RooAbsData & data ) override {
73 fData = &data;
74 ClearAll();
75 }
76
77
78 /// set the model via the ModelConfig
79 void SetModel( const ModelConfig& model ) override;
80
81 /// specify the parameters of interest in the interval
82 virtual void SetParameters(const RooArgSet& set) { fPOI.removeAll(); fPOI.add(set); }
83
84 /// specify the nuisance parameters (eg. the rest of the parameters)
86
87 /// Set only the Prior Pdf
88 virtual void SetPriorPdf(RooAbsPdf& pdf) { fPriorPdf = &pdf; }
89
90 /// set the conditional observables which will be used when creating the NLL
91 /// so the pdf's will not be normalized on the conditional observables when computing the NLL
93
94 /// set the global observables which will be used when creating the NLL
95 /// so the constraint pdf's will be normalized correctly on the global observables when computing the NLL
96 virtual void SetGlobalObservables(const RooArgSet& set) {fGlobalObs.removeAll(); fGlobalObs.add(set);}
97
98 /// set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
99 void SetTestSize( double size ) override {
100 fSize = size;
101 fValidInterval = false;
102 }
103 /// set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
104 void SetConfidenceLevel( double cl ) override { SetTestSize(1.-cl); }
105 /// Get the size of the test (eg. rate of Type I error)
106 double Size() const override { return fSize; }
107 /// Get the Confidence level for the test
108 double ConfidenceLevel() const override { return 1.-fSize; }
109
110 /// set the fraction of probability content on the left tail
111 /// Central limits use 0.5 (default case)
112 /// for upper limits it is 0 and 1 for lower limit
113 /// For shortest intervals a negative value (i.e. -1) must be given
114 void SetLeftSideTailFraction(double leftSideFraction ) {fLeftSideFraction = leftSideFraction;}
115
116 /// set the Bayesian calculator to compute the shortest interval (default is central interval)
117 /// to switch off SetLeftSideTailFraction to the right value
119
120 /// set the precision of the Root Finder
121 void SetBrfPrecision( double precision ) { fBrfPrecision = precision; }
122
123 /// use directly the approximate posterior function obtained by binning it in nbins
124 /// by default the cdf is used by integrating the posterior
125 /// if a value of nbin <= 0 the cdf function will be used
126 void SetScanOfPosterior(int nbin = 100) { fNScanBins = nbin; }
127
128 /// set the number of iterations when running a MC integration algorithm
129 /// If not set use default algorithmic values
130 /// In case of ToyMC sampling of the nuisance the value is 100
131 /// In case of using the GSL MCintegrations types the default value is
132 /// defined in ROOT::Math::IntegratorMultiDimOptions::DefaultNCalls()
133 virtual void SetNumIters(Int_t numIters) { fNumIterations = numIters; }
134
135 /// set the integration type (possible type are) :
136 void SetIntegrationType(const char * type);
137
138 /// return the mode (most probable value of the posterior function)
139 double GetMode() const;
140
141 // force the nuisance pdf when using the toy mc sampling
143
144 protected:
145
146 void ClearAll() const;
147
148 void ApproximatePosterior() const;
149
150 void ComputeIntervalFromApproxPosterior(double c1, double c2) const;
151
152 void ComputeIntervalFromCdf(double c1, double c2) const;
153
154 void ComputeShortestInterval() const;
155
156 private:
157
158 // plan to replace the above: return a SimpleInterval integrating
159 // over all other parameters except the one specified as argument
160 // virtual SimpleInterval* GetInterval( RooRealVar* parameter ) const { return 0; }
161
162 RooAbsData* fData; ///< data set
163 RooAbsPdf* fPdf; ///< model pdf (could contain the nuisance pdf as constraint term)
164 RooArgSet fPOI; ///< POI
165 RooAbsPdf* fPriorPdf; ///< prior pdf (typically for the POI)
166 RooAbsPdf* fNuisancePdf; ///< nuisance pdf (needed when using nuisance sampling technique)
167 RooArgSet fNuisanceParameters; ///< nuisance parameters
168 RooArgSet fConditionalObs ; ///< conditional observables
169 RooArgSet fGlobalObs; ///< global observables
170
171 mutable RooAbsPdf* fProductPdf; ///< internal pointer to model * prior
172 mutable std::unique_ptr<RooAbsReal> fLogLike; ///< internal pointer to log likelihood function
173 mutable RooAbsReal* fLikelihood; ///< internal pointer to likelihood function
174 mutable RooAbsReal* fIntegratedLikelihood; ///< integrated likelihood function, i.e - unnormalized posterior function
175 mutable RooAbsPdf* fPosteriorPdf; ///< normalized (on the poi) posterior pdf
176 mutable ROOT::Math::IGenFunction * fPosteriorFunction; ///< function representing the posterior
177 mutable TF1 * fApproxPosterior; ///< TF1 representing the scanned posterior function
178 mutable double fLower; ///< computer lower interval bound
179 mutable double fUpper; ///< upper interval bound
180 mutable double fNLLMin; ///< minimum value of Nll
181 double fSize; ///< size used for getting the interval
182 double fLeftSideFraction; ///< fraction of probability content on left side of interval
183 double fBrfPrecision; ///< root finder precision
184 mutable int fNScanBins; ///< number of bins to scan, if = -1 no scan is done (default)
185 int fNumIterations; ///< number of iterations (when using ToyMC)
186 mutable bool fValidInterval;
187
189
190 protected:
191
192 ClassDefOverride(BayesianCalculator,3) // BayesianCalculator class
193
194 };
195}
196
197#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:56
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
void SetShortestInterval()
set the Bayesian calculator to compute the shortest interval (default is central interval) to switch ...
void SetTestSize(double size) override
set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
void SetBrfPrecision(double precision)
set the precision of the Root Finder
void ForceNuisancePdf(RooAbsPdf &pdf)
void SetConfidenceLevel(double cl) override
set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
ROOT::Math::IGenFunction * fPosteriorFunction
function representing the posterior
RooAbsReal * fLikelihood
internal pointer to likelihood function
virtual void SetConditionalObservables(const RooArgSet &set)
set the conditional observables which will be used when creating the NLL so the pdf's will not be nor...
double fNLLMin
minimum value of Nll
int fNumIterations
number of iterations (when using ToyMC)
RooAbsPdf * GetPosteriorPdf() const
return posterior pdf (object is managed by the user)
RooPlot * GetPosteriorPlot(bool norm=false, double precision=0.01) const
get the plot with option to get it normalized
int fNScanBins
number of bins to scan, if = -1 no scan is done (default)
void ClearAll() const
clear all cached pdf objects
void SetScanOfPosterior(int nbin=100)
use directly the approximate posterior function obtained by binning it in nbins by default the cdf is...
void ComputeShortestInterval() const
compute the shortest interval from the histogram representing the posterior
RooAbsPdf * fNuisancePdf
nuisance pdf (needed when using nuisance sampling technique)
RooArgSet fConditionalObs
conditional observables
double fBrfPrecision
root finder precision
RooAbsReal * fIntegratedLikelihood
integrated likelihood function, i.e - unnormalized posterior function
void ApproximatePosterior() const
approximate posterior in nbins using a TF1 scan the poi values and evaluate the posterior at each poi...
double fSize
size used for getting the interval
void SetData(RooAbsData &data) override
Set the DataSet ( add to the workspace if not already there ?).
RooArgSet fNuisanceParameters
nuisance parameters
double fLeftSideFraction
fraction of probability content on left side of interval
RooArgSet fGlobalObs
global observables
virtual void SetNuisanceParameters(const RooArgSet &set)
specify the nuisance parameters (eg. the rest of the parameters)
double GetMode() const
return the mode (most probable value of the posterior function)
void SetLeftSideTailFraction(double leftSideFraction)
set the fraction of probability content on the left tail Central limits use 0.5 (default case) for up...
RooAbsPdf * fPdf
model pdf (could contain the nuisance pdf as constraint term)
virtual void SetGlobalObservables(const RooArgSet &set)
set the global observables which will be used when creating the NLL so the constraint pdf's will be n...
virtual void SetNumIters(Int_t numIters)
set the number of iterations when running a MC integration algorithm If not set use default algorithm...
double Size() const override
Get the size of the test (eg. rate of Type I error).
SimpleInterval * GetInterval() const override
compute the interval.
RooAbsPdf * fProductPdf
internal pointer to model * prior
virtual void SetPriorPdf(RooAbsPdf &pdf)
Set only the Prior Pdf.
TF1 * fApproxPosterior
TF1 representing the scanned posterior function.
RooAbsReal * GetPosteriorFunction() const
return posterior function (object is managed by the BayesianCalculator class)
virtual void SetParameters(const RooArgSet &set)
specify the parameters of interest in the interval
void SetIntegrationType(const char *type)
set the integration type (possible type are) :
RooAbsPdf * fPosteriorPdf
normalized (on the poi) posterior pdf
double fUpper
upper interval bound
double fLower
computer lower interval bound
TH1 * GetPosteriorHistogram() const
return the approximate posterior as histogram (TH1 object). Note the object is managed by the Bayesia...
void ComputeIntervalFromApproxPosterior(double c1, double c2) const
compute the interval using the approximate posterior function
void SetModel(const ModelConfig &model) override
set the model via the ModelConfig
RooAbsPdf * fPriorPdf
prior pdf (typically for the POI)
std::unique_ptr< RooAbsReal > fLogLike
internal pointer to log likelihood function
double ConfidenceLevel() const override
Get the Confidence level for the test.
~BayesianCalculator() override
destructor
void ComputeIntervalFromCdf(double c1, double c2) const
internal function compute the interval using Cdf integration
IntervalCalculator is an interface class for a tools which produce RooStats ConfIntervals.
< A class that holds configuration information for a model using a workspace as a store
Definition ModelConfig.h:34
SimpleInterval is a concrete implementation of the ConfInterval interface.
Definition TF1.h:182
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:109
TNamed()
Definition TNamed.h:38
Basic string class.
Definition TString.h:138
STL class.
return c1
Definition legend1.C:41
return c2
Definition legend2.C:14
IBaseFunctionOneDim IGenFunction
Namespace for the RooStats classes.
Definition CodegenImpl.h:66