ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PdfProposal.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_PdfProposal
13 #define ROOSTATS_PdfProposal
14 
15 #ifndef ROOT_Rtypes
16 #include "Rtypes.h"
17 #endif
18 
19 #ifndef ROOSTATS_ProposalFunction
21 #endif
22 
23 #ifndef ROO_ARG_SET
24 #include "RooArgSet.h"
25 #endif
26 #ifndef ROO_MSG_SERVICE
27 #include "RooMsgService.h"
28 #endif
29 #ifndef ROO_REAL_VAR
30 #include "RooRealVar.h"
31 #endif
32 #ifndef ROO_DATA_SET
33 #include "RooDataSet.h"
34 #endif
35 #ifndef ROO_ABS_PDF
36 #include "RooAbsPdf.h"
37 #endif
38 
39 #include <map>
40 
41 
42 namespace RooStats {
43 
44 /**
45 
46 
47  \ingroup Roostats
48 
49 PdfProposal is a concrete implementation of the ProposalFunction interface.
50 It proposes points across the parameter space in the distribution of the
51 given PDF.
52 
53 To make Propose(xPrime, x) dependent on x, configure with
54 PdfProposal::AddMapping(varToUpdate, valueToUse). For example, suppose we have:
55 
56 ````{.cpp}
57 // our parameter
58 RooRealVar p("p", "p", 5, 0, 10);
59 
60 // create mean and sigma for gaussian proposal function
61 RooRealVar meanP("meanP", "meanP", 0, 10);
62 RooRealVar sigma("sigma", "sigma", 1, 0, 5);
63 RooGaussian pGaussian("pGaussian", "pGaussian", p, meanP, sigma);
64 
65 // configure proposal function
66 PdfProposal pdfProposal(pGaussian);
67 pdfProposal.AddMapping(meanP, p); // each call of Propose(xPrime, x), meanP in
68  // the proposal function will be updated to
69  // the value of p in x. this will center the
70  // proposal function about x's p when
71  // proposing for xPrime
72 
73 // To improve performance, PdfProposal has the ability to cache a specified
74 // number of proposals. If you don't call this function, the default cache size
75 // is 1, which can be slow.
76 pdfProposal.SetCacheSize(desiredCacheSize);
77 ````
78 
79 PdfProposal currently uses a fixed cache size. Adaptive caching methods are in the works
80 for future versions.
81 
82 */
83 
84 
85  class PdfProposal : public ProposalFunction {
86 
87  public:
88  PdfProposal();
89  PdfProposal(RooAbsPdf& pdf);
90 
91  /// Populate xPrime with a new proposed point
92  virtual void Propose(RooArgSet& xPrime, RooArgSet& x);
93 
94  /// Determine whether or not the proposal density is symmetric for
95  /// points x1 and x2 - that is, whether the probabilty of reaching x2
96  /// from x1 is equal to the probability of reaching x1 from x2
98 
99  /// Return the probability of proposing the point x1 given the starting
100  /// point x2
102 
103  /// Set the PDF to be the proposal density function
104  virtual void SetPdf(RooAbsPdf& pdf) { fPdf = &pdf; }
105 
106  /// Get the PDF is the proposal density function
107  virtual const RooAbsPdf* GetPdf() const { return fPdf; }
108 
109  /// specify a mapping between a parameter of the proposal function and
110  /// a parameter of interest. this mapping is used to set the value of
111  /// proposalParam equal to the value of update to determine the
112  /// proposal function.
113  /// proposalParam is a parameter of the proposal function that must
114  /// be set to the value of update (from the current point) in order to
115  /// propose a new point.
116  virtual void AddMapping(RooRealVar& proposalParam, RooAbsReal& update);
117 
118  virtual void Reset()
119  {
120  delete fCache;
121  fCache = NULL;
122  fCachePosition = 0;
123  fLastX.removeAll();
124  }
125 
126  virtual void printMappings()
127  {
128  std::map<RooRealVar*, RooAbsReal*>::iterator it;
129  for (it = fMap.begin(); it != fMap.end(); it++)
130  std::cout << it->first->GetName() << " => " << it->second->GetName() << std::endl;
131  }
132 
133  /// Set how many points to generate each time we propose from a new point
134  /// Default (and minimum) is 1
135  virtual void SetCacheSize(Int_t size)
136  {
137  if (size > 0)
138  fCacheSize = size;
139  else
140  coutE(Eval) << "Warning: Requested non-positive cache size: " <<
141  size << ". Cache size unchanged." << std::endl;
142  }
143 
144  /// set whether we own the PDF that serves as the proposal density function
145  /// By default, when constructed, PdfProposal does NOT own the PDF.
146  virtual void SetOwnsPdf(Bool_t ownsPdf) { fOwnsPdf = ownsPdf; }
147 
148  //virtual void SetIsAlwaysSymmetric(Bool_t isAlwaysSymmetric)
149  //{ fIsAlwaysSymmetric = isAlwaysSymmetric; }
150 
151  virtual ~PdfProposal()
152  {
153  delete fCache;
154  if (fOwnsPdf)
155  delete fPdf;
156  }
157 
158  protected:
159  RooAbsPdf* fPdf; /// the proposal density function
160  std::map<RooRealVar*, RooAbsReal*> fMap; /// map of values in pdf to update
161  std::map<RooRealVar*, RooAbsReal*>::iterator fIt; /// pdf iterator
162  RooArgSet fLastX; /// the last point we were at
163  Int_t fCacheSize; /// how many points to generate each time
164  Int_t fCachePosition; /// our position in the cached proposal data set
165  RooDataSet* fCache; /// the cached proposal data set
166  RooArgSet fMaster; /// pointers to master variables needed for updates
167  Bool_t fOwnsPdf; /// whether we own the proposal density function
168  //Bool_t fIsAlwaysSymmetric; // does Q(x1 | x2) == Q(x2 | x1) for all x1, x2
169 
170  /// determine whether these two RooArgSets represent the same point
171  virtual Bool_t Equals(RooArgSet& x1, RooArgSet& x2);
172 
173  /// Interface for tools setting limits (producing confidence intervals)
175  };
176 }
177 
178 #endif
ProposalFunction is an interface for all proposal functions that would be used with a Markov Chain Mo...
#define coutE(a)
Definition: RooMsgService.h:35
virtual Bool_t Equals(RooArgSet &x1, RooArgSet &x2)
whether we own the proposal density function
Definition: PdfProposal.cxx:75
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void printMappings()
Definition: PdfProposal.h:126
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
virtual Double_t GetProposalDensity(RooArgSet &x1, RooArgSet &x2)
Return the probability of proposing the point x1 given the starting point x2.
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual void Reset()
Definition: PdfProposal.h:118
virtual void SetOwnsPdf(Bool_t ownsPdf)
set whether we own the PDF that serves as the proposal density function By default, when constructed, PdfProposal does NOT own the PDF.
Definition: PdfProposal.h:146
virtual void AddMapping(RooRealVar &proposalParam, RooAbsReal &update)
specify a mapping between a parameter of the proposal function and a parameter of interest...
Int_t fCacheSize
the last point we were at
Definition: PdfProposal.h:163
std::map< RooRealVar *, RooAbsReal * >::iterator fIt
map of values in pdf to update
Definition: PdfProposal.h:161
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooDataSet * fCache
our position in the cached proposal data set
Definition: PdfProposal.h:165
virtual void SetCacheSize(Int_t size)
Set how many points to generate each time we propose from a new point Default (and minimum) is 1...
Definition: PdfProposal.h:135
RooArgSet fLastX
pdf iterator
Definition: PdfProposal.h:162
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
Bool_t fOwnsPdf
pointers to master variables needed for updates
Definition: PdfProposal.h:167
virtual void Propose(RooArgSet &xPrime, RooArgSet &x)
Populate xPrime with a new proposed point.
Definition: PdfProposal.cxx:92
static const double x1[5]
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
RooArgSet fMaster
the cached proposal data set
Definition: PdfProposal.h:166
PdfProposal is a concrete implementation of the ProposalFunction interface.
Definition: PdfProposal.h:85
std::map< RooRealVar *, RooAbsReal * > fMap
the proposal density function
Definition: PdfProposal.h:160
virtual void SetPdf(RooAbsPdf &pdf)
Set the PDF to be the proposal density function.
Definition: PdfProposal.h:104
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
#define NULL
Definition: Rtypes.h:82
virtual Bool_t IsSymmetric(RooArgSet &x1, RooArgSet &x2)
Determine whether or not the proposal density is symmetric for points x1 and x2 - that is...
virtual const RooAbsPdf * GetPdf() const
Get the PDF is the proposal density function.
Definition: PdfProposal.h:107
Int_t fCachePosition
how many points to generate each time
Definition: PdfProposal.h:164