Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
16#include "Rtypes.h"
17#include "TObject.h"
18#include "RooArgSet.h"
21
22namespace RooStats {
23
24 class MetropolisHastings : public TObject {
25
26
27 public:
30
31 /// default constructor
32 MetropolisHastings() = default;
33
34 /// alternate constructor
35 MetropolisHastings(RooAbsReal& function, const RooArgSet& paramsOfInterest,
36 ProposalFunction& proposalFunction, Int_t numIters);
37
38 /// main purpose of MetropolisHastings - run Metropolis-Hastings
39 /// algorithm to generate Markov Chain of points in the parameter space
40 virtual MarkovChain* ConstructChain();
41
42 /// specify the parameters to store in the chain
43 /// if not specified all of them will be stored
46 /// specify all the parameters of interest in the interval
47 virtual void SetParameters(const RooArgSet& set)
49 /// set the proposal function for suggesting new points for the MCMC
50 virtual void SetProposalFunction(ProposalFunction& proposalFunction)
51 { fPropFunc = &proposalFunction; }
52 /// set the number of iterations to run the metropolis algorithm
53 virtual void SetNumIters(Int_t numIters)
54 { fNumIters = numIters; }
55 /// set the number of steps in the chain to discard as burn-in,
56 /// starting from the first
57 virtual void SetNumBurnInSteps(Int_t numBurnInSteps)
58 { fNumBurnInSteps = numBurnInSteps; }
59 /// set the (likelihood) function
60 virtual void SetFunction(RooAbsReal& function) { fFunction = &function; }
61 /// set the sign of the function
62 virtual void SetSign(enum FunctionSign sign) { fSign = sign; }
63 /// set the type of the function
64 virtual void SetType(enum FunctionType type) { fType = type; }
65
66
67 protected:
68 RooAbsReal *fFunction = nullptr; ///< function that will generate likelihood values
69 RooArgSet fParameters; ///< RooRealVars that define all parameter space
70 RooArgSet fChainParams; ///< RooRealVars that are stored in the chain
71 ProposalFunction *fPropFunc = nullptr; ///< Proposal function for MCMC integration
72 Int_t fNumIters = 0; ///< number of iterations to run metropolis algorithm
73 Int_t fNumBurnInSteps = 0; ///< number of iterations to discard as burn-in, starting from the first
74 enum FunctionSign fSign = kSignUnset; ///< whether the likelihood is negative (like NLL) or positive
75 enum FunctionType fType = kTypeUnset; ///< whether the likelihood is on a regular, log, (or other) scale
76
77 // whether we should take the step, based on the value of d, fSign, fType
78 virtual bool ShouldTakeStep(double d);
79 virtual double CalcNLL(double xL);
80
81 ClassDefOverride(MetropolisHastings,2) // Markov Chain Monte Carlo calculator for Bayesian credible intervals
82 };
83}
84
85
86#endif
#define d(i)
Definition RSha256.hxx:102
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
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
Stores the steps in a Markov Chain of points.
Definition MarkovChain.h:26
RooArgSet fParameters
RooRealVars that define all parameter space.
virtual void SetProposalFunction(ProposalFunction &proposalFunction)
set the proposal function for suggesting new points for the MCMC
Int_t fNumIters
number of iterations to run metropolis algorithm
virtual void SetChainParameters(const RooArgSet &set)
specify the parameters to store in the chain if not specified all of them will be stored
MetropolisHastings()=default
default constructor
RooAbsReal * fFunction
function that will generate likelihood values
virtual void SetParameters(const RooArgSet &set)
specify all the parameters of interest in the interval
virtual MarkovChain * ConstructChain()
main purpose of MetropolisHastings - run Metropolis-Hastings algorithm to generate Markov Chain of po...
virtual void SetNumIters(Int_t numIters)
set the number of iterations to run the metropolis algorithm
virtual void SetType(enum FunctionType type)
set the type of the function
enum FunctionType fType
whether the likelihood is on a regular, log, (or other) scale
enum FunctionSign fSign
whether the likelihood is negative (like NLL) or positive
RooArgSet fChainParams
RooRealVars that are stored in the chain.
virtual bool ShouldTakeStep(double d)
virtual double CalcNLL(double xL)
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 SetFunction(RooAbsReal &function)
set the (likelihood) function
Int_t fNumBurnInSteps
number of iterations to discard as burn-in, starting from the first
ProposalFunction * fPropFunc
Proposal function for MCMC integration.
virtual void SetSign(enum FunctionSign sign)
set the sign of the function
ProposalFunction is an interface for all proposal functions that would be used with a Markov Chain Mo...
TObject()
TObject constructor.
Definition TObject.h:259
STL class.
Namespace for the RooStats classes.
Definition CodegenImpl.h:66
void RemoveConstantParameters(RooArgSet *set)