Logo ROOT  
Reference Guide
MetropolisHastings.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_MetropolisHastings
13 #define ROOSTATS_MetropolisHastings
14 
15 #include "RooStats/RooStatsUtils.h"
16 #include "Rtypes.h"
17 #include "TObject.h"
18 #include "RooArgSet.h"
20 #include "RooStats/MarkovChain.h"
21 
22 namespace RooStats {
23 
24  class MetropolisHastings : public TObject {
25 
26 
27  public:
30 
31  // default constructor
33 
34  // alternate constructor
35  MetropolisHastings(RooAbsReal& function, const RooArgSet& paramsOfInterest,
36  ProposalFunction& proposalFunction, Int_t numIters);
37 
38  virtual ~MetropolisHastings() {}
39 
40  // main purpose of MetropolisHastings - run Metropolis-Hastings
41  // algorithm to generate Markov Chain of points in the parameter space
42  virtual MarkovChain* ConstructChain();
43 
44  // specify the parameters to store in the chain
45  // if not specified all of them will be stored
46  virtual void SetChainParameters(const RooArgSet& set)
48  // specify all the parameters of interest in the interval
49  virtual void SetParameters(const RooArgSet& set)
51  // set the proposal function for suggesting new points for the MCMC
52  virtual void SetProposalFunction(ProposalFunction& proposalFunction)
53  { fPropFunc = &proposalFunction; }
54  // set the number of iterations to run the metropolis algorithm
55  virtual void SetNumIters(Int_t numIters)
56  { fNumIters = numIters; }
57  // set the number of steps in the chain to discard as burn-in,
58  // starting from the first
59  virtual void SetNumBurnInSteps(Int_t numBurnInSteps)
60  { fNumBurnInSteps = numBurnInSteps; }
61  // set the (likelihood) function
62  virtual void SetFunction(RooAbsReal& function) { fFunction = &function; }
63  // set the sign of the function
64  virtual void SetSign(enum FunctionSign sign) { fSign = sign; }
65  // set the type of the function
66  virtual void SetType(enum FunctionType type) { fType = type; }
67 
68 
69  protected:
70  RooAbsReal* fFunction; // function that will generate likelihood values
71  RooArgSet fParameters; // RooRealVars that define all parameter space
72  RooArgSet fChainParams; // RooRealVars that are stored in the chain
73  ProposalFunction* fPropFunc; // Proposal function for MCMC integration
74  Int_t fNumIters; // number of iterations to run metropolis algorithm
75  Int_t fNumBurnInSteps; // number of iterations to discard as burn-in, starting from the first
76  enum FunctionSign fSign; // whether the likelihood is negative (like NLL) or positive
77  enum FunctionType fType; // whether the likelihood is on a regular, log, (or other) scale
78 
79  // whether we should take the step, based on the value of d, fSign, fType
81  virtual Double_t CalcNLL(Double_t xL);
82 
83  ClassDef(MetropolisHastings,2) // Markov Chain Monte Carlo calculator for Bayesian credible intervals
84  };
85 }
86 
87 
88 #endif
RooStats::MetropolisHastings::SetNumBurnInSteps
virtual void SetNumBurnInSteps(Int_t numBurnInSteps)
Definition: MetropolisHastings.h:71
RooStats::MetropolisHastings::SetType
virtual void SetType(enum FunctionType type)
Definition: MetropolisHastings.h:78
RooStats::MetropolisHastings::FunctionType
FunctionType
Definition: MetropolisHastings.h:41
RooStats::MetropolisHastings::ShouldTakeStep
virtual Bool_t ShouldTakeStep(Double_t d)
Definition: MetropolisHastings.cxx:264
RooStats::MetropolisHastings::kSignUnset
@ kSignUnset
Definition: MetropolisHastings.h:46
RooArgSet.h
RooStats::MetropolisHastings::MetropolisHastings
MetropolisHastings()
Definition: MetropolisHastings.cxx:70
RooStats::MetropolisHastings::FunctionSign
FunctionSign
Definition: MetropolisHastings.h:40
RooStats::MetropolisHastings::SetParameters
virtual void SetParameters(const RooArgSet &set)
Definition: MetropolisHastings.h:61
RooStats::MarkovChain
Definition: MarkovChain.h:36
RooStats::MetropolisHastings::fNumBurnInSteps
Int_t fNumBurnInSteps
Definition: MetropolisHastings.h:87
RooStats::MetropolisHastings::SetSign
virtual void SetSign(enum FunctionSign sign)
Definition: MetropolisHastings.h:76
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooAbsReal
Definition: RooAbsReal.h:61
RooStats::MetropolisHastings::fChainParams
RooArgSet fChainParams
Definition: MetropolisHastings.h:84
RooStats::MetropolisHastings::ConstructChain
virtual MarkovChain * ConstructChain()
Definition: MetropolisHastings.cxx:97
RooStats::MetropolisHastings::~MetropolisHastings
virtual ~MetropolisHastings()
Definition: MetropolisHastings.h:50
bool
RooStats::MetropolisHastings::fSign
enum FunctionSign fSign
Definition: MetropolisHastings.h:88
RooStats::MetropolisHastings::kPositive
@ kPositive
Definition: MetropolisHastings.h:46
RooStats::MetropolisHastings::kTypeUnset
@ kTypeUnset
Definition: MetropolisHastings.h:41
RooStats::MetropolisHastings::fPropFunc
ProposalFunction * fPropFunc
Definition: MetropolisHastings.h:85
RooStats::MetropolisHastings
Definition: MetropolisHastings.h:30
MarkovChain.h
RooStats::MetropolisHastings::fFunction
RooAbsReal * fFunction
Definition: MetropolisHastings.h:82
RooStats::MetropolisHastings::SetNumIters
virtual void SetNumIters(Int_t numIters)
Definition: MetropolisHastings.h:67
RooStats::MetropolisHastings::fNumIters
Int_t fNumIters
Definition: MetropolisHastings.h:86
RooStats::MetropolisHastings::SetFunction
virtual void SetFunction(RooAbsReal &function)
Definition: MetropolisHastings.h:74
RooStats::MetropolisHastings::SetChainParameters
virtual void SetChainParameters(const RooArgSet &set)
Definition: MetropolisHastings.h:58
RooStats::MetropolisHastings::CalcNLL
virtual Double_t CalcNLL(Double_t xL)
Definition: MetropolisHastings.cxx:299
RooStatsUtils.h
RooStats::MetropolisHastings::fType
enum FunctionType fType
Definition: MetropolisHastings.h:89
Double_t
double Double_t
Definition: RtypesCore.h:59
TObject.h
RooStats::MetropolisHastings::kLog
@ kLog
Definition: MetropolisHastings.h:41
RooStats
Definition: Asimov.h:19
RooStats::MetropolisHastings::SetProposalFunction
virtual void SetProposalFunction(ProposalFunction &proposalFunction)
Definition: MetropolisHastings.h:64
ProposalFunction.h
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
RooStats::RemoveConstantParameters
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:69
RooStats::ProposalFunction
Definition: ProposalFunction.h:48
d
#define d(i)
Definition: RSha256.hxx:120
RooStats::MetropolisHastings::kNegative
@ kNegative
Definition: MetropolisHastings.h:46
RooStats::MetropolisHastings::kRegular
@ kRegular
Definition: MetropolisHastings.h:41
type
int type
Definition: TGX11.cxx:121
RooStats::MetropolisHastings::fParameters
RooArgSet fParameters
Definition: MetropolisHastings.h:83
RooAbsCollection::removeAll
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Definition: RooAbsCollection.cxx:643
Rtypes.h
RooArgSet
Definition: RooArgSet.h:28
int