Sampling with gradient-based Markov Chain Monte Carlo approaches
PyTorch implementation of stochastic gradient Langevin dynamics (SGLD) and preconditioned SGLD (pSGLD), involving simple examples of using unadjusted Langevin dynamics and Metropolis-adjusted Langevin algorithm (MALA) to sample from a 2D Gaussian distribution and "banana" distribution.
Prerequisites
Follow the steps below to install the necessary libraries:
pip install langevin-sampling
Script descriptions
langevin_sampling/SGLD.py: SGLD sampler.
langevin_sampling/precondSGLD.py: pSGLD sampler.
langevin_sampling/samplers.py:
-
Implements
LangevinDynamicsclass that given negative-log of unnormalized density function and starting guess, runs Langevin dynamics to sample from the given density. -
Implements
MetropolisAdjustedLangevinclass that given negative-log of unnormalized density function and starting guess, runs MALA to sample from the given density.
examples/gaussian_LD.py: Sampling from a toy 2D Gaussian distribution with unadjusted Langevin dynamics.
examples/gaussian_MALA.py: Sampling from a toy 2D Gaussian distribution with MALA.
examples/banana_LD.py: Sampling from a toy "banana" distribution with unadjusted Langevin dynamics.
examples/banana_MALA.py: Sampling from a toy "banana" distribution with MALA.
Running the code
To sample a toy 2D Gaussian distribution with unadjusted Langevin dynamics, run:
python examples/gaussian_LD.py
To sample a toy 2D Gaussian distribution with MALA, run:
python examples/gaussian_MALA.py
To sample a toy "banana" distribution with unadjusted Langevin dynamics, run:
python examples/banana_LD.py
To sample a toy "banana" distribution with MALA, run:
python examples/banana_MALA.py
References
-
Max Welling and Yee Whye Teh. Bayesian Learning via Stochastic Gradient Langevin Dynamics. In Proceedings of the 28th International Conference on Machine Learning, ICML’11, pages 681–688, Madison, WI, USA, 2011. Omnipress. ISBN 9781450306195. doi: 10.5555/3104482.3104568. URL https://dl.acm.org/doi/abs/10.5555/3104482.3104568.
-
Chunyuan Li, Changyou Chen, David Carlson, and Lawrence Carin. Preconditioned Stochastic Gradient Langevin Dynamics for Deep Neural Networks. In Proceedings of the Thirtieth AAAI Conference on Artificial Intelligence, AAAI’16, pages 1788–1794. AAAI Press, 2016. doi: 10.5555/3016100.3016149. URL https://dl.acm.org/doi/abs/10.5555/3016100.3016149.
-
Roberts, G.O., Stramer, O. Langevin Diffusions and Metropolis-Hastings Algorithms. Methodology and Computing in Applied Probability 4, pages 337–357, 2002. doi: 10.1023/A:1023562417138. URL https://link.springer.com/article/10.1023/A:1023562417138.
-
Pagani F, Wiegand M, Nadarajah S. An n-dimensional Rosenbrock distribution for MCMC testing. arXiv preprint arXiv:1903.09556. 2019 Mar 22. URL https://arxiv.org/abs/1903.09556.
Questions
Please contact alisk@rice.edu for further questions.
Author
Ali Siahkoohi
Metadata
Release files for langevin-sampling 1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langevin_sampling-1.4.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langevin_sampling-1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.5 kB
Release files / langevin_sampling-1.4.tar.gz
| Download URL | langevin_sampling-1.4.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09f2dd8ae2b954aa4499f9771b66ee08e780e576d8f0d0042293627f62f02510
|
|
BLAKE2b-256 checksum How to use checksums |
2dbd0f3e71374f34412e6c357a12f95232171bb47228a26d2fdd2eac410f5663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.13
|
Release files / langevin_sampling-1.4-py3-none-any.whl
| Download URL | langevin_sampling-1.4-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9832dfeffd1a4f0a4e433b4e827dab491033c2efbc604ff74d14951898be370
|
|
BLAKE2b-256 checksum How to use checksums |
9dac5e156ec578cc9064644a426a3951f2515220020efc3755089c49c8596792
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.13
|