Gibbs Sampler
Module containing Markov Chains Monte Carlo sampler utilizing a special case of single-component Metropolis-Hastings algorithm called Gibbs sampler. Since Gibbs sampler utilizes full conditional posterior distribution as proposal density, all proposals are accepted.
- class monte.gibbs_sampler.GibbsSampler(sampling_distributions)[source]
Bases:
BaseSampler- __init__(sampling_distributions) None[source]
Initializes the problem sampler object.
- Parameters:
sampling_distributions (ndarray) –
Array of full conditional posterior distributions
\[f(\theta_j|\theta_{\backslash j, y}).\]The order of the distributions should match the order of parameters in parameter vector passed to sample() method. Each respective distribution should take all other parameters as arguments and return the sample of the particular parameter conditional on those arguments.
- sample(iter, warmup, theta, lag=1, **kwargs)[source]
Samples from the posterior distribution
- Parameters:
iter (int) – Number of iterations of the algorithm
warmup (int) – Number of warmup steps of the algorithm. These are discarded so that the only samples recorded are the ones obtained after the Markov chain has reached the stationary distribution
theta (ndarray) – Vector of initial values of parameters
lag (int, optional) – Sampler lag. Parameter specifying every how many iterations will the sample be recorded. Used to limit autocorrelation of the samples. If lag=1, every sample is recorded, if lag=3 each third sample is recorded, etc. , defaults to 1
- Raises:
ValueError – Returns error if number of parameters doesn’t match the number of sampling distributions
- Returns:
Numpy arrays of samples and acceptance information for every algorithm iteration.
- Return type:
ndarray, ndarray