ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROO_ARG_SET
19 #include "RooArgSet.h"
20 #endif
21 
22 #ifndef ROOSTATS_IntervalCalculator
24 #endif
25 
26 #ifndef ROOSTATS_SimpleInterval
28 #endif
29 
30 class RooAbsData;
31 class RooAbsPdf;
32 class RooPlot;
33 class RooAbsReal;
34 class TF1;
35 
36 
37 namespace RooStats {
38 
39  class ModelConfig;
40  class SimpleInterval;
41 
42 
43 /**
44 
45  BayesianCalculator is a concrete implementation of IntervalCalculator, providing the computation
46  of a credible interval using a Bayesian method.
47  The class works only for one single parameter of interest and it integrates the likelihood function with the given prior
48  probability density function to compute the posterior probability. The result of the class is a one dimensional interval
49  (class SimpleInterval ), which is obtained from inverting the cumulative posterior distribution.
50  This calculator works then only for model with a single parameter of interest.
51  The model can instead have several nuisance parameters which are integrated (marginalized) in the computation of the posterior function.
52  The intergration and normalization of the posterior is computed using numerical integration methods provided by ROOT.
53  See the MCMCCalculator for model with multiple parameters of interest.
54 
55  The interface allows one to construct the class by passing the data set, probability density function for the model, the prior
56  functions and then the parameter of interest to scan. The nuisance parameters can also be passed to be marginalized when
57  computing the posterior. Alternatively, the class can be constructed by passing the data and the ModelConfig containing
58  all the needed information (model pdf, prior pdf, parameter of interest, nuisance parameters, etc..)
59 
60  After configuring the calculator, one only needs to ask GetInterval(), which
61  will return an SimpleInterval object. By default the extrem of the integral are obtained by inverting directly the
62  cumulative posterior distribution. By using the method SetScanOfPosterior(nbins) the interval is then obtained by
63  scanning the posterior function in the given number of points. The firts method is in general faster but it requires an
64  integration one extra dimension ( in the poi in addition to the nuisance parameters), therefore in some case it can be
65  less robust.
66 
67  The class can also return the posterior function (method GetPosteriorFunction) or if needed the normalized
68  posterior function (the posterior pdf) (method GetPosteriorPdf). A posterior plot is also obtained using
69  the GetPosteriorPlot method.
70 
71  The class allows to use different integration methods for integrating in (marginalizing) the nuisances and in the poi. All the numerical
72  integration methods of ROOT can be used via the method SetIntegrationType (see more in the documentation of
73  this method).
74 
75  Calculator estimating a credible interval using the Bayesian procedure.
76  The calculator computes given the model the posterior distribution and estimates the
77  credible interval from the given function.
78 
79 
80  \ingroup Roostats
81 
82 */
83 
84  class BayesianCalculator : public IntervalCalculator, public TNamed {
85 
86  public:
87 
88  /// constructor
90 
92  RooAbsPdf& pdf,
93  const RooArgSet& POI,
94  RooAbsPdf& priorPdf,
95  const RooArgSet* nuisanceParameters = 0 );
96 
98  ModelConfig& model );
99 
100  /// destructor
101  virtual ~BayesianCalculator();
102 
103  /// get the plot with option to get it normalized
104  RooPlot* GetPosteriorPlot(bool norm = false, double precision = 0.01) const;
105 
106  /// return posterior pdf (object is managed by the BayesianCalculator class)
107  RooAbsPdf* GetPosteriorPdf() const;
108  /// return posterior function (object is managed by the BayesianCalculator class)
110 
111  /// compute the interval. By Default a central interval is computed
112  /// By using SetLeftTileFraction can control if central/ upper/lower interval
113  /// For shortest interval use SetShortestInterval(true)
114  virtual SimpleInterval* GetInterval() const ;
115 
116  virtual void SetData( RooAbsData & data ) {
117  fData = &data;
118  ClearAll();
119  }
120 
121 
122  /// set the model via the ModelConfig
123  virtual void SetModel( const ModelConfig& model );
124 
125  /// specify the parameters of interest in the interval
126  virtual void SetParameters(const RooArgSet& set) { fPOI.removeAll(); fPOI.add(set); }
127 
128  /// specify the nuisance parameters (eg. the rest of the parameters)
130 
131  /// Set only the Prior Pdf
132  virtual void SetPriorPdf(RooAbsPdf& pdf) { fPriorPdf = &pdf; }
133 
134  /// set the conditional observables which will be used when creating the NLL
135  /// so the pdf's will not be normalized on the conditional observables when computing the NLL
137 
138  /// set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval)
139  virtual void SetTestSize( Double_t size ) {
140  fSize = size;
141  fValidInterval = false;
142  }
143  /// set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval)
144  virtual void SetConfidenceLevel( Double_t cl ) { SetTestSize(1.-cl); }
145  /// Get the size of the test (eg. rate of Type I error)
146  virtual Double_t Size() const { return fSize; }
147  /// Get the Confidence level for the test
148  virtual Double_t ConfidenceLevel() const { return 1.-fSize; }
149 
150  /// set the fraction of probability content on the left tail
151  /// Central limits use 0.5 (default case)
152  /// for upper limits it is 0 and 1 for lower limit
153  /// For shortest intervals a negative value (i.e. -1) must be given
154  void SetLeftSideTailFraction(Double_t leftSideFraction ) {fLeftSideFraction = leftSideFraction;}
155 
156  /// set the Bayesian calculator to compute the shorest interval (default is central interval)
157  /// to switch off SetLeftSideTailFraction to the rght value
159 
160  /// set the precision of the Root Finder
161  void SetBrfPrecision( double precision ) { fBrfPrecision = precision; }
162 
163  /// use directly the approximate posterior function obtained by binning it in nbins
164  /// by default the cdf is used by integrating the posterior
165  /// if a value of nbin <= 0 the cdf function will be used
166  void SetScanOfPosterior(int nbin = 100) { fNScanBins = nbin; }
167 
168  /// set the number of iterations when running a MC integration algorithm
169  /// If not set use default algorithmic values
170  /// In case of ToyMC sampling of the nuisance the value is 100
171  /// In case of using the GSL MCintegrations types the default value is
172  /// defined in ROOT::Math::IntegratorMultiDimOptions::DefaultNCalls()
173  virtual void SetNumIters(Int_t numIters) { fNumIterations = numIters; }
174 
175  /// set the integration type (possible type are) :
176  void SetIntegrationType(const char * type);
177 
178  /// return the mode (most probable value of the posterior function)
179  double GetMode() const;
180 
181  /// force the nuisance pdf when using the toy mc sampling
182  void ForceNuisancePdf(RooAbsPdf & pdf) { fNuisancePdf = &pdf; }
183 
184  protected:
185 
186  void ClearAll() const;
187 
188  void ApproximatePosterior() const;
189 
190  void ComputeIntervalFromApproxPosterior(double c1, double c2) const;
191 
192  void ComputeIntervalFromCdf(double c1, double c2) const;
193 
194  void ComputeIntervalUsingRooFit(double c1, double c2) const;
195 
196  void ComputeShortestInterval() const;
197 
198  private:
199 
200  // plan to replace the above: return a SimpleInterval integrating
201  // over all other parameters except the one specified as argument
202  //virtual SimpleInterval* GetInterval( RooRealVar* parameter ) const { return 0; }
203 
204  RooAbsData* fData; // data set
205  RooAbsPdf* fPdf; // model pdf (could contain the nuisance pdf as constraint term)
206  RooArgSet fPOI; // POI
207  RooAbsPdf* fPriorPdf; // prior pdf (typically for the POI)
208  RooAbsPdf* fNuisancePdf; // nuisance pdf (needed when using nuisance sampling technique)
209  RooArgSet fNuisanceParameters; // nuisance parameters
210  RooArgSet fConditionalObs ; // conditional observables
211 
212  mutable RooAbsPdf* fProductPdf; // internal pointer to model * prior
213  mutable RooAbsReal* fLogLike; // internal pointer to log likelihood function
214  mutable RooAbsReal* fLikelihood; // internal pointer to likelihood function
215  mutable RooAbsReal* fIntegratedLikelihood; // integrated likelihood function, i.e - unnormalized posterior function
216  mutable RooAbsPdf* fPosteriorPdf; // normalized (on the poi) posterior pdf
217  mutable ROOT::Math::IGenFunction * fPosteriorFunction; // function representing the posterior
218  mutable TF1 * fApproxPosterior; // TF1 representing the scanned posterior function
219  mutable Double_t fLower; // computer lower interval bound
220  mutable Double_t fUpper; // upper interval bound
221  mutable Double_t fNLLMin; // minimum value of Nll
222  double fSize; // size used for getting the interval
223  double fLeftSideFraction; // fraction of probability content on left side of interval
224  double fBrfPrecision; // root finder precision
225  mutable int fNScanBins; // number of bins to scan, if = -1 no scan is done (default)
226  int fNumIterations; // number of iterations (when using ToyMC)
228 
229 
230 
232 
233  protected:
234 
235  ClassDef(BayesianCalculator,2) // BayesianCalculator class
236 
237  };
238 }
239 
240 #endif
virtual void SetData(RooAbsData &data)
Set the DataSet ( add to the the workspace if not already there ?)
RooPlot * GetPosteriorPlot(bool norm=false, double precision=0.01) const
get the plot with option to get it normalized
ROOT::Math::IGenFunction * fPosteriorFunction
RooAbsPdf * GetPosteriorPdf() const
return posterior pdf (object is managed by the BayesianCalculator class)
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:133
IntervalCalculator is an interface class for a tools which produce RooStats ConfIntervals.
void SetScanOfPosterior(int nbin=100)
use directly the approximate posterior function obtained by binning it in nbins by default the cdf is...
TCanvas * c1
Definition: legend1.C:2
void SetIntegrationType(const char *type)
set the integration type (possible type are) :
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void SetBrfPrecision(double precision)
set the precision of the Root Finder
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)
virtual SimpleInterval * GetInterval() const
compute the interval.
virtual void SetParameters(const RooArgSet &set)
specify the parameters of interest in the interval
RooAbsReal * GetPosteriorFunction() const
return posterior function (object is managed by the BayesianCalculator class)
void ComputeIntervalUsingRooFit(double c1, double c2) const
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual Double_t Size() const
Get the size of the test (eg. rate of Type I error)
virtual void SetNumIters(Int_t numIters)
set the number of iterations when running a MC integration algorithm If not set use default algorithm...
void ComputeIntervalFromApproxPosterior(double c1, double c2) const
virtual void SetConfidenceLevel(Double_t cl)
set the confidence level for the interval (eg. 0.95 for a 95% Confidence Interval) ...
void SetShortestInterval()
set the Bayesian calculator to compute the shorest interval (default is central interval) to switch o...
void ComputeIntervalFromCdf(double c1, double c2) const
void SetLeftSideTailFraction(Double_t leftSideFraction)
set the fraction of probability content on the left tail Central limits use 0.5 (default case) for up...
virtual Double_t ConfidenceLevel() const
Get the Confidence level for the test.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
virtual void SetModel(const ModelConfig &model)
set the model via the ModelConfig
return c2
Definition: legend2.C:14
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual void SetPriorPdf(RooAbsPdf &pdf)
Set only the Prior Pdf.
int type
Definition: TGX11.cxx:120
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...
virtual void SetTestSize(Double_t size)
set the size of the test (rate of Type I error) ( Eg. 0.05 for a 95% Confidence Interval) ...
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
1-Dim function class
Definition: TF1.h:149
virtual ~BayesianCalculator()
destructor
void ForceNuisancePdf(RooAbsPdf &pdf)
force the nuisance pdf when using the toy mc sampling
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
BayesianCalculator is a concrete implementation of IntervalCalculator, providing the computation of a...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448