Gaussian Metropolis Algorithm

Module containing Markov Chains Monte Carlo sampler utilizing Metropolis algorithm with Gaussian proposal distribution.

class monte.gaussian_metropolis.GaussianMetropolis(log_posterior)[source]

Bases: BaseSampler

__init__(log_posterior) None[source]

Initializes the problem sampler object.

Parameters:

log_posterior (callable) – Log-probability of the target distribution to be sampled from. This should either be posterior distribution of the model or a product of prior distribution and likelihood.

sample(iter, warmup, theta, step_size, lag=1, **kwargs)[source]

Samples from the log_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 parameter(s)

  • step_size (float) – Proposal step size equal to the standard deviation of the proposal distribution

  • 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

Returns:

Numpy arrays of samples and acceptance information for every algorithm iteration.

Return type:

ndarray, ndarray