Stacking Variational Bayesian Monte Carlo (S-VBMC)
Important!
S-VBMC is now part of PyVBMC, and this standalone package is deprecated. From PyVBMC 1.5, use
pyvbmc.SVBMCinstead:pip install --upgrade "pyvbmc[torch]"from pyvbmc import SVBMCThe integrated version is faster and reports a more precise ELBO, with its uncertainty. Its documentation explains how to use it and how to migrate code written for this package, and PyVBMC Example 7 walks through a complete example.
The
svbmcpackage receives no further updates. This repository remains as the code of the S-VBMC paper [1], and the rest of this README describes that original implementation.
Overview
Stacking Variational Bayesian Monte Carlo (S-VBMC)[1] is a fast post-processing step for Variational Bayesian Monte Carlo (VBMC). VBMC is an approximate Bayesian inference technique that produces a variational posterior in the form of a Gaussian mixture (see the relevant papers [2-4] for more details). S-VBMC improves upon this by combining ("stacking") the Gaussian mixture components from several independent VBMC runs into a single, larger mixture, which we call "stacked posterior". It then re-optimizes the weights of this combined mixture to maximize the combined Evidence Lower BOund (ELBO, a lower bound on log model evidence).
A key advantage of S-VBMC is its efficiency: the original model is never re-evaluated, making it an inexpensive way to boost inference performance. Furthermore, no communication is needed among VBMC runs, making it possible to run them in parallel before applying S-VBMC as a post-processing step with negligible computational overhead.
Refer to the S-VBMC paper for further details [1].
When to use S-VBMC
S-VBMC works as a post-processing step for VBMC, so it shares its use cases (described here).
Performing several VBMC inference runs with different initialization points is already recommended for robustness and convergence diagnostics; therefore, S-VBMC naturally fits into VBMC's best practices. Because S-VBMC is inexpensive and effective, we recommend using it whenever you first perform inference with VBMC. It is especially useful when separate VBMC runs yield noticeably different variational posteriors, which might happen when the target distribution has a particularly complex shape (see this notebook for two examples of this).
How to use S-VBMC
1. Installation
Create a new environment in conda and activate it:
conda create -n svbmc-env python=3.11
conda activate svbmc-env
Install svbmc with pip:
pip install svbmc
2. Running S-VBMC
You should have already run VBMC multiple times on the same problem and saved the resulting VariationalPosterior objects as .pkl files. Refer to these notebooks for VBMC usage examples.
First, load these objects into a single list. For example, if you have your files in a folder named vbmc_runs/:
import pickle
import glob
vp_files = glob.glob("vbmc_runs/*.pkl")
vp_list = []
for file in vp_files:
with open(file, "rb") as f:
vp_list.append(pickle.load(f))
Next, initialize the SVBMC object with this list and run the optimization.
from svbmc.svbmc import SVBMC
# Initialize the SVBMC object and optimize the weights
vp_stacked = SVBMC(vp_list=vp_list)
vp_stacked.optimize()
# The SVBMC object now contains the optimized weights and ELBO estimates
print(f"Stacked ELBO: {vp_stacked.elbo['estimated']}")
Note: For compatibility with VBMC, this implementation of S-VBMC stores results in NumPy arrays. However, it uses PyTorch under the hood to run the ELBO optimization.
3. Tutorials
We include two detailed walkthroughs:
- Basic Usage: This notebook shows how to run S-VBMC, with an optional guide on how to run VBMC multiple times.
- Noisy Log-Density Evaluations: This notebook addresses scenarios where the target log-density evaluations are noisy and a discussion of ELBO debiasing.
How to use the final posterior
If you want to compute estimates (or visualize) the final stacked posterior, you can draw samples from it using .sample():
# Draw 10,000 samples from the final, stacked posterior
samples = vp_stacked.sample(n_samples=10000)
You can also extract the ELBO estimates for model comparison (see here; and here if your log-density evaluations are noisy).
For advanced users
Do not "open the box" to get S-VBMC stacked posterior's individual components' means and covariance matrices. This is because each VBMC run may use different internal parameter transformations. Consequently, the component means and covariance matrices from different VBMC posteriors exist in incompatible parameter spaces. Combining them creates a mixture whose individual Gaussian components are not directly meaningful. Always use samples from the final stacked posterior, which are correctly transformed back into the original parameter space. These are available via the .sample() method.
References and citation
- Silvestrin, F., Li, C., & Acerbi, L. (2025). Stacking Variational Bayesian Monte Carlo. In Transactions on Machine Learning Research. (paper on arXiv, TMLR).
- Acerbi, L. (2018). Variational Bayesian Monte Carlo. In Advances in Neural Information Processing Systems 31: 8222-8232. (paper + supplement on arXiv, NeurIPS Proceedings)
- Acerbi, L. (2020). Variational Bayesian Monte Carlo with Noisy Likelihoods. In Advances in Neural Information Processing Systems 33: 8211-8222 (paper + supplement on arXiv, NeurIPS Proceedings).
- Huggins, B., Li, C., Tobaben, M., Aarnos, M., & Acerbi, L. (2023). PyVBMC: Efficient Bayesian inference in Python. Journal of Open Source Software 8(86), 5428, https://doi.org/10.21105/joss.05428.
Please cite all four references if you use S-VBMC in your work.
Additional references
- Acerbi, L. (2019). An Exploration of Acquisition and Mean Functions in Variational Bayesian Monte Carlo. In Proc. Machine Learning Research 96: 1-10. 1st Symposium on Advances in Approximate Bayesian Inference, Montréal, Canada. (paper in PMLR)
BibTeX
@article{
silvestrin2025stacking,
title={Stacking Variational Bayesian Monte Carlo},
author={Francesco Silvestrin and Chengkun LI and Luigi Acerbi},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2025},
url={https://openreview.net/forum?id=M2ilYAJdPe},
note={}
}
@article{acerbi2018variational,
title={{V}ariational {B}ayesian {M}onte {C}arlo},
author={Acerbi, Luigi},
journal={Advances in Neural Information Processing Systems},
volume={31},
pages={8222--8232},
year={2018}
}
@article{acerbi2020variational,
title={{V}ariational {B}ayesian {M}onte {C}arlo with noisy likelihoods},
author={Acerbi, Luigi},
journal={Advances in Neural Information Processing Systems},
volume={33},
pages={8211--8222},
year={2020}
}
@article{huggins2023pyvbmc,
title = {PyVBMC: Efficient Bayesian inference in Python},
author = {Bobby Huggins and Chengkun Li and Marlon Tobaben and Mikko J. Aarnos and Luigi Acerbi},
publisher = {The Open Journal},
journal = {Journal of Open Source Software},
url = {https://doi.org/10.21105/joss.05428},
doi = {10.21105/joss.05428},
year = {2023},
volume = {8},
number = {86},
pages = {5428}
}
@article{acerbi2019exploration,
title={An Exploration of Acquisition and Mean Functions in {V}ariational {B}ayesian {M}onte {C}arlo},
author={Acerbi, Luigi},
journal={PMLR},
volume={96},
pages={1--10},
year={2019}
}
License
S-VBMC is released under the terms of the BSD 3-Clause License.
Acknowledgments
S-VBMC was developed by members of the Machine and Human Intelligence Lab at the University of Helsinki. This work was supported by Research Council of Finland (grants 358980 and 356498).
Metadata
Release files for svbmc 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| svbmc-0.1.2.tar.gz | 31.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| svbmc-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 53.7 kB
Release files / svbmc-0.1.2.tar.gz
| Download URL | svbmc-0.1.2.tar.gz |
|---|---|
| Size | 31.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04b4e9271f6b1f4ff5056c6c1a3894b1c7fe8ef78173f72a63ac31b57c945717
|
|
BLAKE2b-256 checksum How to use checksums |
0757e2dd0e7c95ea1ff4ca5c64bbcde6587cbf6b7ccbe3a458a339576d4000d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / svbmc-0.1.2-py3-none-any.whl
| Download URL | svbmc-0.1.2-py3-none-any.whl |
|---|---|
| Size | 22.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4032d33e3fef2b40e435083a6f4c211ed00f6c49c58f5159e8df40fefaf68b55
|
|
BLAKE2b-256 checksum How to use checksums |
95530fd959e953c98a1f7b7374095d8b10a9ff962359db7f7fe04e6122ba95ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|