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
SamplingAlgorithmwhich operates on \(g \subset G\) for some global Markov chain state \(G\),MwgStepreturns a newSamplingAlgorithmthat operates on \(G\), but applies the original sampling algorithm to only \(g\), automatically computing the conditional posterior distribution \(\pi(g | g^c)\).More technically,
MwgSteplifts an instance ofSamplingAlgorithminto the Metropolis-within-Gibbs monad, making it compatible with the structure of the global state, and composable with other instances ofSamplingAlgorithmwhich 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_namesdetermines the structure of the subset of the MCMC chain state forwarded tosampling_algorithm. This means there is an important difference betweensampling_algorithm="foo"andsampling_algorithm=["foo"]. The former will forward theArrayLikestructure representing thefoocoordinate to the underlying kernel, whereas the latter will forward a (named) tuple of length 1 _containing_ theArrayLiketo the underlying kernel.- __init__()#
Methods
__init__()