gemlib.mcmc.MwgStep

Contents

gemlib.mcmc.MwgStep#

class gemlib.mcmc.MwgStep(sampling_algorithm, target_names, kernel_kwargs_fn=<function MwgStep.<lambda>>)#

A Metropolis-within-Gibbs step.

Given an instance of SamplingAlgorithm which operates on \(g \subset G\) for some global Markov chain state \(G\), MwgStep returns a new SamplingAlgorithm that operates on \(G\), but applies the original sampling algorithm to only \(g\), automatically computing the conditional posterior distribution \(\pi(g | g^c)\).

More technically, MwgStep lifts an instance of SamplingAlgorithm into the Metropolis-within-Gibbs monad, making it compatible with the structure of the global state, and composable with other instances of SamplingAlgorithm which also operate on the global state.

Parameters:
  • sampling_algorithm (SamplingAlgorithm) – an instance of a sampling algorithms

  • target_names (str | list[str]) – coordinate name(s) within a global chain position on which the Metropolis-within-Gibbs step is to operate

  • kernel_kwargs_fn (Callable[[Position], dict]) – a callable taking the chain position as an argument, and returning a dictionary of extra kwargs to SamplingAlgorithm.step().

Returns:

An instance of SamplingAlgorithm.

Note

The structure of the argument supplied to target_names determines the structure of the subset of the MCMC chain state forwarded to sampling_algorithm. This means there is an important difference between sampling_algorithm="foo" and sampling_algorithm=["foo"]. The former will forward the ArrayLike structure representing the foo coordinate to the underlying kernel, whereas the latter will forward a (named) tuple of length 1 _containing_ the ArrayLike to the underlying kernel.

__init__()#

Methods