Skip to main content

Sampling with gradient-based Markov Chain Monte Carlo approaches

Project description

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 LangevinDynamics class that given negative-log of unnormalized density function and starting guess, runs Langevin dynamics to sample from the given density.

  • Implements MetropolisAdjustedLangevin class 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langevin_sampling-1.4.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langevin_sampling-1.4-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file langevin_sampling-1.4.tar.gz.

File metadata

  • Download URL: langevin_sampling-1.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for langevin_sampling-1.4.tar.gz
Algorithm Hash digest
SHA256 09f2dd8ae2b954aa4499f9771b66ee08e780e576d8f0d0042293627f62f02510
MD5 b5383f0913e5331bbee4ab7c1f974e55
BLAKE2b-256 2dbd0f3e71374f34412e6c357a12f95232171bb47228a26d2fdd2eac410f5663

See more details on using hashes here.

File details

Details for the file langevin_sampling-1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for langevin_sampling-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e9832dfeffd1a4f0a4e433b4e827dab491033c2efbc604ff74d14951898be370
MD5 a6e1e63bf7bc898c2d63ac78dd236950
BLAKE2b-256 9dac5e156ec578cc9064644a426a3951f2515220020efc3755089c49c8596792

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page