Bayesian posterior sampling via SGD

One of those times when the easy thing can also be the smart thing

Randomly exploring the posterior space.

Combining Markov Chain Monte Carlo and Stochastic Gradient Descent for Bayesian inference, especially by using SGD to do some cheap version of MCMC posterior sampling. Overviews in Ma, Chen, and Fox (2015) and Mandt, Hoffman, and Blei (2017). A lot of probabilistic neural nets are built on this idea.

A related idea is estimating gradients of parameters by Monte Carlo; there is nothing necessarily Bayesian about that per se; in that case we are doing a noisy estimate of a deterministic quantity. In this setting we are interested in the noise itself.

I have a vague memory that this argument is leveraged in Neal (1996)? Should check. For sure the version in Mandt, Hoffman, and Blei (2017) is a highly developed and modern take. Basically, they analyse the distribution near convergence as an autoregressive process:

Stochastic Gradient Descent with a constant learning rate (constant SGD) simulates a Markov chain with a stationary distribution. With this perspective, we derive several new results.

  1. We show that constant SGD can be used as an approximate Bayesian posterior inference algorithm. Specifically, we show how to adjust the tuning parameters of constant SGD to best match the stationary distribution to a posterior, minimizing the Kullback-Leibler divergence between these two distributions.
  2. We demonstrate that constant SGD gives rise to a new variational EM algorithm that optimizes hyperparameters in complex probabilistic models.
  3. We also propose SGD with momentum for sampling and show how to adjust the damping coefficient accordingly.
  4. We analyze MCMC algorithms. For Langevin Dynamics and Stochastic Gradient Fisher Scoring, we quantify the approximation errors due to finite learning rates. Finally,
  5. we use the stochastic process perspective to give a short proof of why Polyak averaging is optimal. Based on this idea, we propose a scalable approximate MCMC algorithm, the Averaged Stochastic Gradient Sampler.

The article is rather beautiful. Importantly they leverage the assumption that we are sampling from approximately (log-)quadratic posterior modes, which means that we should be suspicious of the method when

  1. The posterior is not quadratic, i.e. the distribution is not well approximated by a Gaussian at the mode, and
  2. The same for the tails. If there are low-probability but high importance posterior configurations such that they are not Gaussian in the tails, we should be skeptical that they will be sampled well; I have an intuition that this is a more stringent requirement, but TBH I am not sure of the exact relationship of these two conditions.

The models leverage gradient flow, which is a continuous limit of stochastic gradient descent.

Stochastic Weight Averaging

A popular recent development is the Stochastic Weight Averaging family of methods (Izmailov et al. 2018, 2020; Maddox et al. 2019; Wilson and Izmailov 2020). See Andrew G Wilson’s web page for a brief description of the sub methods, since he seems to have been involved in all of them.

Stochastic Gradient Langevin MCMC

β€œa Markov Chain reminiscent of noisy gradient descent” (Welling and Teh 2011) extending vanilla Langevin dynamics.

SG Hamiltonian Monte Carlo

SG thermostats

  1. Some kind of variance control using auxiliary variables?

SG Fisher scoring

Ahn, Korattikara, and Welling (2012)



Ahn, Sungjin, Anoop Korattikara, and Max Welling. 2012. β€œBayesian Posterior Sampling via Stochastic Gradient Fisher Scoring.” In Proceedings of the 29th International Coference on International Conference on Machine Learning, 1771–78. ICML’12. Madison, WI, USA: Omnipress.
Alexos, Antonios, Alex J. Boyd, and Stephan Mandt. 2022. β€œStructured Stochastic Gradient MCMC.” In Proceedings of the 39th International Conference on Machine Learning, 414–34. PMLR.
Brosse, Nicolas, Γ‰ric Moulines, and Alain Durmus. 2018. β€œThe Promises and Pitfalls of Stochastic Gradient Langevin Dynamics.” In Proceedings of the 32nd International Conference on Neural Information Processing Systems, 8278–88. NIPS’18. Red Hook, NY, USA: Curran Associates Inc.
Chandramoorthy, Nisha, Andreas Loukas, Khashayar Gatmiry, and Stefanie Jegelka. 2022. β€œOn the Generalization of Learning Algorithms That Do Not Converge.” arXiv.
Chaudhari, Pratik, and Stefano Soatto. 2018. β€œStochastic Gradient Descent Performs Variational Inference, Converges to Limit Cycles for Deep Networks.” In 2018 Information Theory and Applications Workshop (ITA), 1–10.
Chen, Tianqi, Emily Fox, and Carlos Guestrin. 2014. β€œStochastic Gradient Hamiltonian Monte Carlo.” In Proceedings of the 31st International Conference on Machine Learning, 1683–91. Beijing, China: PMLR.
Chen, Zaiwei, Shancong Mou, and Siva Theja Maguluri. 2021. β€œStationary Behavior of Constant Stepsize SGD Type Algorithms: An Asymptotic Characterization.” arXiv.
Choi, Hyunsun, Eric Jang, and Alexander A. Alemi. 2019. β€œWAIC, but Why? Generative Ensembles for Robust Anomaly Detection.” arXiv.
Dieuleveut, Aymeric, Alain Durmus, and Francis Bach. 2018. β€œBridging the Gap Between Constant Step Size Stochastic Gradient Descent and Markov Chains.” arXiv.
Ding, Nan, Youhan Fang, Ryan Babbush, Changyou Chen, Robert D. Skeel, and Hartmut Neven. 2014. β€œBayesian Sampling Using Stochastic Gradient Thermostats.” In Proceedings of the 27th International Conference on Neural Information Processing Systems - Volume 2, 3203–11. NIPS’14. Cambridge, MA, USA: MIT Press.
Durmus, Alain, and Eric Moulines. 2016. β€œHigh-Dimensional Bayesian Inference via the Unadjusted Langevin Algorithm.” arXiv:1605.01559 [Math, Stat], May.
Dutordoir, Vincent, James Hensman, Mark van der Wilk, Carl Henrik Ek, Zoubin Ghahramani, and Nicolas Durrande. 2021. β€œDeep Neural Networks as Point Estimates for Deep Gaussian Processes.” arXiv:2105.04504 [Cs, Stat], May.
Ge, Rong, Holden Lee, and Andrej Risteski. 2020. β€œSimulated Tempering Langevin Monte Carlo II: An Improved Proof Using Soft Markov Chain Decomposition.” arXiv:1812.00793 [Cs, Math, Stat], September.
Girolami, Mark, and Ben Calderhead. 2011. β€œRiemann Manifold Langevin and Hamiltonian Monte Carlo Methods.” Journal of the Royal Statistical Society: Series B (Statistical Methodology) 73 (2): 123–214.
Grenander, Ulf, and Michael I. Miller. 1994. β€œRepresentations of Knowledge in Complex Systems.” Journal of the Royal Statistical Society: Series B (Methodological) 56 (4): 549–81.
Hodgkinson, Liam, Robert Salomone, and Fred Roosta. 2019. β€œImplicit Langevin Algorithms for Sampling From Log-Concave Densities.” arXiv:1903.12322 [Cs, Stat], March.
Izmailov, Pavel, Wesley J. Maddox, Polina Kirichenko, Timur Garipov, Dmitry Vetrov, and Andrew Gordon Wilson. 2020. β€œSubspace Inference for Bayesian Deep Learning.” In Proceedings of The 35th Uncertainty in Artificial Intelligence Conference, 1169–79. PMLR.
Izmailov, Pavel, Dmitrii Podoprikhin, Timur Garipov, Dmitry Vetrov, and Andrew Gordon Wilson. 2018. β€œAveraging Weights Leads to Wider Optima and Better Generalization,” March.
Le, Samuel L. Smith and Quoc V. 2018. β€œA Bayesian Perspective on Generalization and Stochastic Gradient Descent.” In.
Ma, Yi-An, Tianqi Chen, and Emily B. Fox. 2015. β€œA Complete Recipe for Stochastic Gradient MCMC.” In Proceedings of the 28th International Conference on Neural Information Processing Systems - Volume 2, 2917–25. NIPS’15. Cambridge, MA, USA: MIT Press.
Maclaurin, Dougal, David Duvenaud, and Ryan P. Adams. 2015. β€œEarly Stopping as Nonparametric Variational Inference.” In Proceedings of the 19th International Conference on Artificial Intelligence and Statistics, 1070–77. arXiv.
Maddox, Wesley, Timur Garipov, Pavel Izmailov, Dmitry Vetrov, and Andrew Gordon Wilson. 2019. β€œA Simple Baseline for Bayesian Uncertainty in Deep Learning,” February.
Mandt, Stephan, Matthew D. Hoffman, and David M. Blei. 2017. β€œStochastic Gradient Descent as Approximate Bayesian Inference.” JMLR, April.
Neal, Radford M. 1996. β€œBayesian Learning for Neural Networks.” Secaucus, NJ, USA: Springer-Verlag New York, Inc.
Norton, Richard A., and Colin Fox. 2016. β€œTuning of MCMC with Langevin, Hamiltonian, and Other Stochastic Autoregressive Proposals.” arXiv:1610.00781 [Math, Stat], October.
Osawa, Kazuki, Siddharth Swaroop, Mohammad Emtiyaz E Khan, Anirudh Jain, Runa Eschenhagen, Richard E Turner, and Rio Yokota. 2019. β€œPractical Deep Learning with Bayesian Principles.” In Advances in Neural Information Processing Systems. Vol. 32. Red Hook, NY, USA: Curran Associates, Inc.
Parisi, G. 1981. β€œCorrelation Functions and Computer Simulations.” Nuclear Physics B 180 (3): 378–84.
RΓ‘sonyi, MiklΓ³s, and Kinga Tikosi. 2022. β€œOn the Stability of the Stochastic Gradient Langevin Algorithm with Dependent Data Stream.” Statistics & Probability Letters 182 (March): 109321.
Shang, Xiaocheng, Zhanxing Zhu, Benedict Leimkuhler, and Amos J Storkey. 2015. β€œCovariance-Controlled Adaptive Langevin Thermostat for Large-Scale Bayesian Sampling.” In Advances in Neural Information Processing Systems. Vol. 28. NIPS’15. Curran Associates, Inc.
Smith, Samuel L., Benoit Dherin, David Barrett, and Soham De. 2020. β€œOn the Origin of Implicit Regularization in Stochastic Gradient Descent.” In.
Welling, Max, and Yee Whye Teh. 2011. β€œBayesian Learning via Stochastic Gradient Langevin Dynamics.” In Proceedings of the 28th International Conference on International Conference on Machine Learning, 681–88. ICML’11. Madison, WI, USA: Omnipress.
Wenzel, Florian, Kevin Roth, Bastiaan Veeling, Jakub Swiatkowski, Linh Tran, Stephan Mandt, Jasper Snoek, Tim Salimans, Rodolphe Jenatton, and Sebastian Nowozin. 2020. β€œHow Good Is the Bayes Posterior in Deep Neural Networks Really?” In Proceedings of the 37th International Conference on Machine Learning, 10248–59. PMLR.
Wilson, Andrew Gordon, and Pavel Izmailov. 2020. β€œBayesian Deep Learning and a Probabilistic Perspective of Generalization,” February.
Xifara, T., C. Sherlock, S. Livingstone, S. Byrne, and M. Girolami. 2014. β€œLangevin Diffusions and the Metropolis-Adjusted Langevin Algorithm.” Statistics & Probability Letters 91 (Supplement C): 14–19.

No comments yet. Why not leave one?

GitHub-flavored Markdown & a sane subset of HTML is supported.