Generalized Metropolis Algorithm
Module containing Markov Chains Monte Carlo sampler utilizing Metropolis algorithm with arbitrary, symetrical proposal distribution. It should be noted, that the proposal distribution should be symetrical for the sampler to be usable. Otherwise, Metropolis-Hastings algorithm should be used which can be found in metropolis_hastings.py.
- class monte.generalized_metropolis.GeneralizedMetropolis(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, proposal_sampler=None, 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)
proposal_sampler (callable) – Function that returns a random value from a desired proposal distribution given current value of parameter. The only argument should be the sampling distribution location.
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