MetropolisSampler#
- class agabpylib.mcmc.metropolis.MetropolisSampler(lnprob, proposal_rvs)#
Bases:
object
Base class for Metropolis samplers. Can deal with multi-dimensional sampling problems.
Limitations:
Simplistic implementation
Only one chain at a time
No conservation of state
Methods Summary
Get the acceptance fraction for the MCMC chain.
Get the MCMC samples.
run_mcmc
(theta_init, n_iter[, burnin, thin])Run the sampler.
Methods Documentation
- get_acceptance_fraction()#
Get the acceptance fraction for the MCMC chain.
- Parameters:
None –
- Returns:
acceptance_frac – The acceptance fraction.
- Return type:
float
- get_samples()#
Get the MCMC samples.
- Parameters:
None –
- Returns:
samples – The array with MCMC samples (shape (n_samples, n_parameters)).
- Return type:
float array
- run_mcmc(theta_init, n_iter, burnin=0, thin=1)#
Run the sampler.
TODO: Handle the case where the probability densities for both the current and proposed sample are -np.inf.
- Parameters:
theta_init (float, or float array) – Initial values of the samples theta_k.
n_iter (int) – Number of MCMC iterations to perform.
burnin (int) – Number of “burn-in” steps to take.
thin (int) – Only output every thin samples.
- Return type:
Nothing