LieselMCMC#
- class liesel.goose.LieselMCMC(model, which=None)[source]#
Bases:
objectManages the setup of MCMC specifications for a Liesel model.
- Parameters:
Examples
Liesel Workflow
For this example, we import
tensorflow_probabilityas 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
SamplingResultsobject.More control
For additional control, we initialize an
EngineBuilderand 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.
Collect jitter functions for model variables that define a jitter distribution.
Collect and organize model variables into kernel groups.
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.
Logs a warning if there are any parameters in the model that have no inference specification for MCMC.
Attributes