LieselMCMC.run_for_epochs()

LieselMCMC.run_for_epochs()#

LieselMCMC.run_for_epochs(*, seed, num_chains, adaptation, posterior, burnin=0, adaptation_thinning=1, burnin_thinning=1, posterior_thinning=1, apply_jitter=True, store_kernel_states=False, show_progress=True, positions_included=None, positions_excluded=None, save_path=None)[source]#

Shorthand method for quickly running MCMC for a set number of epochs.

Parameters:
  • seed (int) – Random seed for reproducibility.

  • num_chains (int) – Number of MCMC chains.

  • adaptation (int) – Number of samples to be drawn in the respective epoch.

  • burnin (int, default: 0) – Number of samples to be drawn in the respective epoch.

  • posterior (int) – Number of samples to be drawn in the respective epoch.

  • adaptation_thinning (int, default: 1) – Thinning to be applied in the respective epoch.

  • burnin_thinning (int, default: 1) – Thinning to be applied in the respective epoch.

  • posterior_thinning (int, default: 1) – Thinning to be applied in the respective epoch.

  • apply_jitter (bool, default: True) – Whether to apply jitter to the initial states, by default True. Note that initial values for a variable will only jittered if the MCMCSpec for this variable was supplied with a jitter_dist. Think of this argument rather as an off-switch of existing jittering.

  • store_kernel_states (bool, default: False) – Whether to store kernel states in sampling results, which may be useful for debugging.

  • show_progress (bool, default: True) – Whether to show progress bars during sampling.

  • positions_included (list[str] | None, default: None) – List of additional position keys that should be tracked, see EngineBuilder.positions_included.

  • positions_excluded (list[str] | None, default: None) – List of position keys that should not be tracked. Excluded keys override additional keys see EngineBuilder.positions_excluded.

  • save_path (str | Path | None, default: None) – Filepath to a pickle file in which results should be saved. If the file exists, results are loaded from this file and no sampling occurs.

Return type:

SamplingResults

Warning

This method is only appropriate, if your MCMC algorithm is fully specified via MCMCSpec objects in the Var.inference attributes of the variables in your model.

See also

get_engine_builder

Method to obtain an EngineBuilder from the LieselMCMC object. The EngineBuilder allows for more detailed custom configuration; for example you can add additional MCMC kernels via EngineBuilder.add_kernel().

Notes

The method is equivalent to the following code:

eb = LieselMCMC(model).get_engine_builder(
    seed=seed, num_chains=num_chains, apply_jitter=apply_jitter
)

eb.store_kernel_states = store_kernel_states
eb.positions_included = positions_included or []
eb.positions_excluded = positions_excluded or []
eb.show_progress = show_progress

if adaptation > 0:
    eb.add_adaptation(adaptation, adaptation_thinning)
if burnin > 0:
    eb.add_burnin(burnin, burnin_thinning)
eb.add_posterior(posterior, posterior_thinning)
engine = eb.build()
engine.sample_all_epochs()
engine.get_results()