Samplers#
There are currently three different samplers that are directly integrated within fiesta’s API.
Of course, the fiesta priors and likelihood functions could also be used with different samplers, but direct use through the Fiesta sampling class is only possible with either flowmc, blackjax-smc, or numpyro-svi.
To decide which sampler to use, use the sampler argument when initializing the Fiesta class. By default, this will be flowmc.
You can also pass additional sampling kwargs to the Fiesta class, if you do not wanna use their standard settings.
We briefly present the different samplers and their optional arguments here.
flowmc (default)#
flowMC is an MCMC sampler that combines local Metropolis-adjusted Langevin algorithm (MALA) steps with a normalizing flow that is trained on the fly for efficient global proposals. This significantly improves sampling efficiency for complicated posterior distributions while still sampling the true posterior distribution. Details can be found in the flowMC paper and the documentation.
The following keyword arguments can be passed to Fiesta(..., sampler="flowmc", **sampling_kwargs):
Argument |
Description |
Default |
|---|---|---|
|
Number of parallel MCMC chains. |
|
|
Number of local MALA steps per sampling loop. |
|
|
Number of global normalizing-flow proposals per sampling loop. |
|
|
Number of training sampling loops. |
|
|
Number of production sampling loops after training. |
|
|
Number of epochs used to train the normalizing flow during each training loop. |
|
|
Number of rational quadratic spline coupling layers. |
|
|
Hidden layer sizes of the neural networks used in the normalizing flow. |
|
|
Number of bins in each rational quadratic spline transform. |
|
|
Step size used by the local MALA sampler. |
|
|
Learning rate for normalizing flow training. |
|
|
Maximum number of training samples stored for training the flow. |
|
|
Batch size for generating normalizing-flow proposals. |
|
|
Number of chains processed simultaneously. |
|
|
Mini-batch size used during normalizing flow optimization. |
|
|
Print progress information during sampling. |
|
For most applications, the default settings provide good performance.
The parameters that are most commonly adjusted are n_chains, n_training_loops, n_production_loops, and mala_step_size.
sampler = Fiesta(
...,
sampler="flowmc",
n_chains=200,
n_training_loops=30,
n_production_loops=20,
mala_step_size=1e-3,
)
After sampling, fiesta returns the production samples as the posterior samples.
If sampler_extra_output=True is passed to the Fiesta.save_results() method, additional diagnostic information from both the training and production phases (chains, log probabilities, acceptance rates, and training losses) are saved in two separate files results_training.npz and results_production.npz in the output directory.
blackjax-smc#
blackjax-smc implements an adaptive Sequential Monte Carlo (SMC) sampler.
Instead of directly sampling the posterior, the algorithm starts by drawing particles from the prior distribution and gradually transforms them into posterior samples through a sequence of intermediate distributions by increasing the inverse temperature on the likelihood function.
At each tempering stage, particles are rejuvenated using an MCMC kernel and resampled when necessary.
An advantage of SMC methods is that they naturally provide an estimate of the Bayesian evidence.
The implementation in fiesta is based on the adaptive_tempered_smc algorithm from blackjax with automatic tuning of the tempering schedule.
More details can be found in the blackjax documentation.
The following keyword arguments can be passed to Fiesta(..., sampler="blackjax-smc", **sampling_kwargs):
Argument |
Description |
Default |
|---|---|---|
|
Number of particles used by the SMC sampler. |
|
|
Target relative effective sample size (ESS) used to adapt the tempering schedule. Larger values result in more tempering stages. |
|
|
Number of MCMC rejuvenation steps performed after each tempering stage. |
|
|
MCMC kernel used to rejuvenate particles. Currently only “random_walk” is implemented. |
|
|
Proposal scale of the random-walk kernel. Ignored for other kernels. |
|
For most applications, the default settings work well. The parameters that are most commonly adjusted are n_particles, target_ess, num_mcmc_steps, and random_walk_sigma.
sampler = Fiesta(
...,
sampler="blackjax-smc",
n_particles=10000,
target_ess=0.95,
num_mcmc_steps=20,
random_walk_sigma=0.03,
)
After sampling, fiesta returns the posterior samples.
In addition, the estimated log-evidence is printed to the console.
If sampler_extra_output=True is passed to the Fiesta.save_results() method, fiesta also saves a smc_metadata.json file containing diagnostic information.
numpyro-svi#
numpyro-svi performs Stochastic Variational Inference (SVI) using numpyro.
Instead of drawing exact samples from the posterior, SVI optimizes the parameters of a variational distribution to approximate the posterior by maximizing the Evidence Lower Bound (ELBO).
Once optimization has converged, samples are drawn from the optimized variational distribution.
Here, we use a diagonal truncated normal distribution as variational distribution, meaning this method cannot represent correlations between different parameters.
Summarized: This SVI method just serves as a cheap approximation method and should not be used to obtain accurate posterior samples.
The following keyword arguments can be passed to Fiesta(..., sampler="numpyro-svi", **sampling_kwargs):
Argument |
Description |
Default |
|---|---|---|
|
Number of optimization iterations used to fit the variational posterior. |
|
|
Learning rate of the Adam optimizer. |
|
|
Number of posterior samples drawn from the optimized variational distribution. |
|
For most applications, the default settings provide a good starting point.
If the optimization has not converged, increasing num_iter is usually the first parameter to adjust.
The step_size may also need tuning if the ELBO is unstable or converges slowly.
sampler = Fiesta(
...,
sampler="numpyro-svi",
num_iter=20000,
step_size=5e-4,
num_samples=5000,
)
After optimization, fiesta draws num_samples samples from the learned variational distribution and returns them as posterior samples.
The final ELBO is printed to the console.
If sampler_extra_output=True is passed to the Fiesta.save_results() method, fiesta also saves a svi_metadata.json file containing diagnostic information.