LieselMCMC

Contents

LieselMCMC#

class liesel.goose.LieselMCMC(model, which=None)[source]#

Bases: object

Manages the setup of MCMC specifications for a Liesel model.

Parameters:
  • model (Model) – The Liesel model object containing the variables and their inference specifications.

  • which (str | None, default: None) – A named inference configuration to use. If None, the default inference attached to each variable is used.

Examples

Liesel Workflow

For this example, we import tensorflow_probability as follows:

>>> import tensorflow_probability.substrates.jax.distributions as tfd

First, we set up a minimal model:

>>> mu = lsl.Var.new_param(0.0, name="mu", inference=gs.MCMCSpec(gs.NUTSKernel))
>>> dist = lsl.Dist(tfd.Normal, loc=mu, scale=1.0)
>>> y = lsl.Var.new_obs(jnp.array([1.0, 2.0, 3.0]), dist, name="y")
>>> model = lsl.Model([y])

Now we run MCMC:

>>> results = gs.LieselMCMC(model).run_mcmc(
...     seed=1, num_chains=4, adaptation=250, posterior=100
... )

The function returns a SamplingResults object.

More control

For additional control, we initialize an EngineBuilder and continue from there.

>>> builder = gs.LieselMCMC(model).get_engine_builder(seed=1, num_chains=4)
>>> builder.add_adaptation(1000)
>>> builder.add_posterior(1000)

Methods

get_engine_builder(seed, num_chains[, ...])

Create and configure an EngineBuilder for MCMC sampling.

get_jitter_functions()

Collect jitter functions for model variables that define a jitter distribution.

get_kernel_groups()

Collect and organize model variables into kernel groups.

get_kernel_list()

Construct the list of MCMC kernels from kernel groups.

get_spec(var)

Retrieve the MCMC specification for a given variable.

run_for_epochs(*, seed, num_chains, ...[, ...])

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

validate_inference_specs()

Logs a warning if there are any parameters in the model that have no inference specification for MCMC.

Attributes