autoemcee module

Calculates the Bayesian evidence and posterior samples of arbitrary monomodal models.

class autoemcee.ReactiveAffineInvariantSampler(param_names, loglike, transform=None, num_test_samples=2, vectorized=False, sampler='goodman-weare')[source]

Bases: object

Emcee sampler with reactive exploration strategy.

Initialise sampler.

Parameters
  • param_names (list of str, names of the parameters.) – Length gives dimensionality of the sampling problem.

  • loglike (function) – log-likelihood function. Receives multiple parameter vectors, returns vector of likelihood.

  • transform (function) – parameter transform from unit cube to physical parameters. Receives multiple cube vectors, returns multiple parameter vectors.

  • sampler (str) – if ‘goodman-weare’: use Goodman & Weare’s affine invariant MCMC ensemble sampler if ‘slice’: use Karamanis & Beutler (2020)’s ensemble slice sampler

  • vectorized (bool) – if true, likelihood and transform receive arrays of points, and return arrays

  • num_test_samples (int) – test transform and likelihood with this number of random points for errors first. Useful to catch bugs.

find_starting_walkers(num_global_samples, num_walkers)[source]
run(num_global_samples=10000, num_chains=4, num_walkers=None, max_ncalls=1000000, max_improvement_loops=4, num_initial_steps=100, min_autocorr_times=0, rhat_max=1.01, geweke_max=2.0, progress=True)[source]

Sample until MCMC chains have converged.

The steps are:

  1. Draw num_global_samples from prior. The highest num_walkers points are selected.

  2. Set num_steps to num_initial_steps

  3. Run num_chains MCMC ensembles for num_steps steps

  4. For each walker chain, compute auto-correlation length (Convergence requires num_steps/autocorrelation length > min_autocorr_times)

  5. For each parameter, compute geweke convergence diagnostic (Convergence requires |z| < geweke_max)

  6. For each ensemble, compute gelman-rubin rank convergence diagnostic (Convergence requires rhat<rhat_max)

  7. If converged, stop and return results.

  8. Increase num_steps by 10, and repeat from (3) up to max_improvement_loops times.

Parameters
  • num_global_samples (int) – Number of samples to draw from the prior to

  • num_chains (int) – Number of independent ensembles to run. If running with MPI, this is set to the number of MPI processes.

  • num_walkers (int) – Ensemble size. If None, max(100, 4 * dim) is used

  • max_ncalls (int) – Maximum number of likelihood function evaluations

  • num_initial_steps (int) – Number of sampler steps to take in first iteration

  • max_improvement_loops (int) – Number of times MCMC should be re-attempted (see above)

  • min_autocorr_times (float) – if positive, additionally require for convergence that the number of samples is larger than the min_autocorr_times times the autocorrelation length.

  • geweke_max (float) – Maximum absolute z-score of the geweke test allowed for convergence.

  • rhat_max (float) – Maximum r-hat allowed for convergence.

  • progress (bool) – if True, show progress bars

print_results()[source]

Give summary of marginal likelihood and parameters.

plot(**kwargs)[source]