An implementation of the delayed rejection kernel. More...
#include <DRKernel.h>
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< SamplingState > | SampleProposal (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, TransitionKernelConstructor > | TransitionKernelMap |
Static Public Member Functions inherited from muq::SamplingAlgorithms::TransitionKernel | |
static std::shared_ptr< TransitionKernel > | Construct (boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem) |
Static constructor for the transition kernel. More... | |
static std::shared_ptr< TransitionKernelMap > | GetTransitionKernelMap () |
muq::SamplingAlgorithms::DRKernel::DRKernel | ( | boost::property_tree::ptree const & | pt, |
std::shared_ptr< AbstractSamplingProblem > | problem | ||
) |
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::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.
|
virtualdefault |
|
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.
Definition at line 105 of file DRKernel.h.
References numProposalAccepts, and numProposalCalls.
|
inlineprotected |
Definition at line 167 of file DRKernel.h.
References muq::Utilities::GetSlice(), nlohmann::detail::dtoa_impl::k, and QFun().
Referenced by Step().
|
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().
|
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().
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().
|
inline |
Returns a vector with the scaling used for each proposal stage.
Definition at line 123 of file DRKernel.h.
References propScales.
|
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
[in] | t | The current step |
[in] | state | The current state |
Reimplemented from muq::SamplingAlgorithms::TransitionKernel.
Definition at line 63 of file DRKernel.cpp.
References uniqueProps.
|
overridevirtual |
Print the status of this kernel to std::cout.
[in] | prefix | A 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.
|
inlinevirtual |
Return a vector of the MCMC proposals used in each stage.
Definition at line 83 of file DRKernel.h.
References proposals.
|
inlineprotected |
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().
|
overridevirtual |
Reimplemented from muq::SamplingAlgorithms::TransitionKernel.
Definition at line 30 of file DRKernel.cpp.
References muq::SamplingAlgorithms::TransitionKernel::blockInd, and proposals.
|
overridevirtual |
[in] | t | The current step |
[in] | state | The current state |
Implements muq::SamplingAlgorithms::TransitionKernel.
Definition at line 99 of file DRKernel.cpp.
References Alpha(), numProposalAccepts, numProposalCalls, muq::SamplingAlgorithms::TransitionKernel::problem, proposals, muq::SamplingAlgorithms::TransitionKernel::reeval, and SampleProposal().
|
protected |
Definition at line 156 of file DRKernel.h.
Referenced by EvaluateProposal(), and SampleProposal().
|
protected |
Definition at line 162 of file DRKernel.h.
Referenced by AcceptanceRates(), PrintStatus(), and Step().
|
protected |
Definition at line 159 of file DRKernel.h.
Referenced by AcceptanceRates(), PrintStatus(), and Step().
|
protected |
Definition at line 145 of file DRKernel.h.
Referenced by CreateProposals(), EvaluateProposal(), Proposals(), SampleProposal(), SetBlockInd(), and Step().
|
protected |
Definition at line 155 of file DRKernel.h.
Referenced by EvaluateProposal(), GetScales(), and SampleProposal().
|
protected |
Definition at line 152 of file DRKernel.h.
Referenced by PostStep().