MUQ  0.4.3
muq::SamplingAlgorithms::DRKernel Class Reference

An implementation of the delayed rejection kernel. More...

#include <DRKernel.h>

Inheritance diagram for muq::SamplingAlgorithms::DRKernel:

Detailed Description

An implementation of the delayed rejection kernel.

This class provides an implementation the delayed rejection kernel described in "On Metropolis-Hastings algorithms with delayed rejection" by Antonietta Mira. This algorithm uses a sequence of proposal stages to increase the probability of accepting a move. In the first stage, a normal Metropolis-Hastings step is attempted with a proposal \(q_0\). However, if the proposed point is rejected, a second proposed move is generated with a proposal \(q_1\). This proposed point is accepted or rejected with an acceptance probability that has been adjusted to maintain detailed balance. The process continues for subsequent stages until either (1) a proposal is accepted, at which point the proposal is immediately returned as the next state in the Markov chain or (2) the maximum number of delayed rejection stages is met, at which point the current state is repeated in the Markov chain.

The delayed rejection implementation in MUQ allows the proposal sequence to be defined in two ways: either by specifying the proposals for each stage individually, or by specifying a single proposal that is then scaled at each stage. The latter approach is more restrictive, but can yield slightly more efficient implementations of standard methods like DRAM.

More precisely, a scaling \(a_i\) of some base proposal density \(q(x)\) defines a new proposal density \(q_{a_i}(y) = a_i q\left(a_iy\right)\), where the new variable \(y\) is equal in distribution to a scaling of \(x\), i.e., \(y=\frac{x}{a_i}\). We assume the scale \(a_i\) for stage \(i\) is given by one of two functions of the stage index \(i\). Either the linear scaling

\[ a_i = \frac{b}{i+1}, \]

or the power scaling

\[ a_i = \frac{b}{2^i}. \]

Note that in both cases, \(i\in\{0,1,...,N-1\}\), where \(N\) is the number of stages.

Configuration Parameters:

Parameter Key Type Default Value Description
"Proposal" string - Either the name of another block in the ptree that defines the base proposal \(q\) that will be scaled for each stage, or a comma separated list of blocks that define the proposals for each stage.
"NumStages" integer - Number of stages to use if scalings of a single proposal are to be used. If a list of proposals is specified, then this option does nothing.
"ScaleFunction" string "Power" Either "Linear" or "Power" to dictate the type of scaling function to use.
"Scale" double 2.0 Value of \(b\) in scaling equation. Value must be positive and will generally be greater than 1 to ensure the proposal shrinks with increasing stage \(i\).

Definition at line 63 of file DRKernel.h.

Public Member Functions

 DRKernel (boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem)
 
 DRKernel (boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem, std::vector< std::shared_ptr< MCMCProposal >> proposalsIn, std::vector< double > scales)
 
 DRKernel (boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem, std::vector< std::shared_ptr< MCMCProposal >> proposalsIn)
 
virtual ~DRKernel ()=default
 
virtual std::vector< std::shared_ptr< MCMCProposal > > Proposals ()
 
virtual void PostStep (unsigned int const t, std::vector< std::shared_ptr< SamplingState >> const &state) override
 Allow the kernel to adapt given a new state. More...
 
virtual std::vector< std::shared_ptr< SamplingState > > Step (unsigned int const t, std::shared_ptr< SamplingState > prevState) override
 
virtual void PrintStatus (std::string prefix) const override
 
virtual Eigen::VectorXd AcceptanceRates () const
 
std::shared_ptr< SamplingStateSampleProposal (unsigned int stage, std::shared_ptr< SamplingState > const &state) const
 
double EvaluateProposal (unsigned int stage, std::shared_ptr< SamplingState > const &x, std::shared_ptr< SamplingState > const &y) const
 
std::vector< double > GetScales () const
 
virtual void SetBlockInd (int newBlockInd) override
 
- Public Member Functions inherited from muq::SamplingAlgorithms::TransitionKernel
 TransitionKernel (boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem)
 
virtual ~TransitionKernel ()=default
 
virtual void SetCommunicator (std::shared_ptr< parcer::Communicator > newcomm)
 
virtual void PreStep (unsigned int const t, std::shared_ptr< SamplingState > state)
 Allow the kernel to preprocess the current step. More...
 
virtual void PrintStatus () const
 
virtual int GetBlockInd () const
 
virtual std::shared_ptr< AbstractSamplingProblem > const & Problem () const
 

Additional Inherited Members

- Public Types inherited from muq::SamplingAlgorithms::TransitionKernel
typedef boost::function< std::shared_ptr< TransitionKernel >boost::property_tree::ptree, std::shared_ptr< AbstractSamplingProblem >)> TransitionKernelConstructor
 
typedef std::map< std::string, TransitionKernelConstructorTransitionKernelMap
 
- Static Public Member Functions inherited from muq::SamplingAlgorithms::TransitionKernel
static std::shared_ptr< TransitionKernelConstruct (boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem)
 Static constructor for the transition kernel. More...
 
static std::shared_ptr< TransitionKernelMapGetTransitionKernelMap ()
 

Constructor & Destructor Documentation

◆ DRKernel() [1/3]

muq::SamplingAlgorithms::DRKernel::DRKernel ( boost::property_tree::ptree const &  pt,
std::shared_ptr< AbstractSamplingProblem problem 
)

◆ DRKernel() [2/3]

muq::SamplingAlgorithms::DRKernel::DRKernel ( boost::property_tree::ptree const &  pt,
std::shared_ptr< AbstractSamplingProblem problem,
std::vector< std::shared_ptr< MCMCProposal >>  proposalsIn,
std::vector< double >  scales 
)

◆ DRKernel() [3/3]

DRKernel::DRKernel ( boost::property_tree::ptree const &  pt,
std::shared_ptr< AbstractSamplingProblem problem,
std::vector< std::shared_ptr< MCMCProposal >>  proposalsIn 
)

Definition at line 37 of file DRKernel.cpp.

◆ ~DRKernel()

virtual muq::SamplingAlgorithms::DRKernel::~DRKernel ( )
virtualdefault

Member Function Documentation

◆ AcceptanceRates()

virtual Eigen::VectorXd muq::SamplingAlgorithms::DRKernel::AcceptanceRates ( ) const
inlinevirtual

For each stage, we define the acceptance rate as the ratio of the number of proposal calls to the number of times the proposal from that stage was accepted. Note that later stages will be called less often than earlier stages.

Returns
An Eigen::VectorXd containing acceptance rates for each stage.

Definition at line 105 of file DRKernel.h.

References numProposalAccepts, and numProposalCalls.

◆ Alpha()

template<typename VecType1 , typename VecType2 >
double muq::SamplingAlgorithms::DRKernel::Alpha ( VecType1 &  likelies,
VecType2 &  proposed_points 
) const
inlineprotected

Definition at line 167 of file DRKernel.h.

References muq::Utilities::GetSlice(), nlohmann::detail::dtoa_impl::k, and QFun().

Referenced by Step().

◆ CreateProposals()

std::vector< std::shared_ptr< MCMCProposal > > DRKernel::CreateProposals ( boost::property_tree::ptree const &  pt,
std::shared_ptr< AbstractSamplingProblem > const &  problem 
)
staticprotected

Extracts information from the property tree and creates MCMC proposals.

Definition at line 228 of file DRKernel.cpp.

References muq::SamplingAlgorithms::MCMCProposal::Construct(), muq::SamplingAlgorithms::TransitionKernel::problem, proposals, and muq::Utilities::StringUtilities::Split().

◆ CreateScales()

std::vector< double > DRKernel::CreateScales ( boost::property_tree::ptree const &  pt)
staticprotected

In some cases, the proposal at each stage is just a scaled version of some base proposal distribution. In these cases, we can store and adapt a a single proposal if we explicitly store the scales. This function reads a property tree and creates a vector of proposal scalings. See the class level documentation for the necessary ptree format.

Definition at line 171 of file DRKernel.cpp.

References muq::Utilities::StringUtilities::Split().

◆ EvaluateProposal()

double DRKernel::EvaluateProposal ( unsigned int  stage,
std::shared_ptr< SamplingState > const &  x,
std::shared_ptr< SamplingState > const &  y 
) const

Evaluates the log density of a stage proposal at point y of the proposal located at point x. This function takes care of all necessary scaling.

Definition at line 81 of file DRKernel.cpp.

References muq::SamplingAlgorithms::TransitionKernel::blockInd, isScaled, proposals, and propScales.

Referenced by QFun().

◆ GetScales()

std::vector<double> muq::SamplingAlgorithms::DRKernel::GetScales ( ) const
inline

Returns a vector with the scaling used for each proposal stage.

Definition at line 123 of file DRKernel.h.

References propScales.

◆ PostStep()

void DRKernel::PostStep ( unsigned int const  t,
std::vector< std::shared_ptr< SamplingState >> const &  state 
)
overridevirtual

Allow the kernel to adapt given a new state.

By default this function does nothing but children can override it to adapt the kernel

Parameters
[in]tThe current step
[in]stateThe current state

Reimplemented from muq::SamplingAlgorithms::TransitionKernel.

Definition at line 63 of file DRKernel.cpp.

References uniqueProps.

◆ PrintStatus()

void DRKernel::PrintStatus ( std::string  prefix) const
overridevirtual

Print the status of this kernel to std::cout.

Parameters
[in]prefixA string that should be appended to the output. Typically used for handling indentation in nested kernels.

Reimplemented from muq::SamplingAlgorithms::TransitionKernel.

Definition at line 210 of file DRKernel.cpp.

References numProposalAccepts, and numProposalCalls.

◆ Proposals()

virtual std::vector<std::shared_ptr<MCMCProposal> > muq::SamplingAlgorithms::DRKernel::Proposals ( )
inlinevirtual

Return a vector of the MCMC proposals used in each stage.

Definition at line 83 of file DRKernel.h.

References proposals.

◆ QFun()

template<typename VecType >
double muq::SamplingAlgorithms::DRKernel::QFun ( VecType const &  proposed_points) const
inlineprotected

Definition at line 203 of file DRKernel.h.

References EvaluateProposal().

Referenced by Alpha().

◆ SampleProposal()

std::shared_ptr< SamplingState > DRKernel::SampleProposal ( unsigned int  stage,
std::shared_ptr< SamplingState > const &  state 
) const

Generates a sample of a stage proposal at the point x. This function handles all necessary scaling.

Definition at line 71 of file DRKernel.cpp.

References muq::SamplingAlgorithms::TransitionKernel::blockInd, isScaled, proposals, and propScales.

Referenced by Step().

◆ SetBlockInd()

void DRKernel::SetBlockInd ( int  newBlockInd)
overridevirtual

◆ Step()

std::vector< std::shared_ptr< SamplingState > > DRKernel::Step ( unsigned int const  t,
std::shared_ptr< SamplingState prevState 
)
overridevirtual

Member Data Documentation

◆ isScaled

bool muq::SamplingAlgorithms::DRKernel::isScaled = false
protected

Definition at line 156 of file DRKernel.h.

Referenced by EvaluateProposal(), and SampleProposal().

◆ numProposalAccepts

Eigen::VectorXi muq::SamplingAlgorithms::DRKernel::numProposalAccepts
protected

Definition at line 162 of file DRKernel.h.

Referenced by AcceptanceRates(), PrintStatus(), and Step().

◆ numProposalCalls

Eigen::VectorXi muq::SamplingAlgorithms::DRKernel::numProposalCalls
protected

Definition at line 159 of file DRKernel.h.

Referenced by AcceptanceRates(), PrintStatus(), and Step().

◆ proposals

std::vector<std::shared_ptr<MCMCProposal> > muq::SamplingAlgorithms::DRKernel::proposals
protected

◆ propScales

std::vector<double> muq::SamplingAlgorithms::DRKernel::propScales
protected

Definition at line 155 of file DRKernel.h.

Referenced by EvaluateProposal(), GetScales(), and SampleProposal().

◆ uniqueProps

std::set<std::shared_ptr<MCMCProposal> > muq::SamplingAlgorithms::DRKernel::uniqueProps
protected

Definition at line 152 of file DRKernel.h.

Referenced by PostStep().


The documentation for this class was generated from the following files: