# 变分贝叶斯推断

变分贝叶斯推断（Variational Bayesian inference，VI）通过将推断转化为优化来近似难以处理的后验概率分布：它先设定一个密度函数族，再从中找出与目标最接近的成员，接近程度用KL散度（Kullback–Leibler divergence）衡量。<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> 输出的是一个密度函数，而不是样本。VI往往比马尔可夫链蒙特卡洛（MCMC）采样更快，但与MCMC不同，它不保证从目标密度中渐近精确地采样。<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> 在许多应用中，观察到在相同近似精度下，VI的运行速度比MCMC快几个数量级。<sup>[2](https://ar5iv.labs.arxiv.org/html/1710.03266)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 所选族中的一个密度 \( q \)，在KL散度意义下最接近后验<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> |
| 目标函数 | 证据下界（ELBO），\( \mathcal{L} = \log p(x) - D_{KL}(q \| p) \)；最大化它等价于最小化KL散度<sup>[3](https://www.deeplearningbook.org/contents/inference.html)</sup> |
| 经典函数族 | 平均场分解 \( q(\theta) = \prod_{i} q_{i}(\theta_{i}) \)<sup>[4](https://robots.ox.ac.uk/~sjrob/Pubs/vbTutorialFinal.pdf)</sup> |
| 经典算法 | 坐标上升（CAVI），收敛到对初始化敏感的局部最优<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> |
| 已展示的规模 | 用随机变分推断处理了30万篇《自然》、180万篇《纽约时报》和380万篇维基百科文章<sup>[5](https://www.cs.columbia.edu/~blei/papers/HoffmanBleiWangPaisley2013.pdf)</sup> |
| 已知偏差 | 通常低估后验方差，这是其目标函数的后果<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> |

## 工作原理

证据下界（ELBO）定义为 \( \mathcal{L}(v, \theta, q) = \log p(v; \theta) - D_{KL}(q(h \mid v) \| p(h \mid v; \theta)) \)，其中 \( q \) 是潜变量 \( h \) 上的任意分布。它至多等于数据的对数概率，仅当 \( q \) 为真实后验时取等号，因此最大化ELBO会驱使 \( q \) 趋向于后验。<sup>[3](https://www.deeplearningbook.org/contents/inference.html)</sup> 该界也可以利用Jensen不等式从 \( \log p(x) \) 推导出来。<sup>[6](https://arxiv.org/pdf/1711.05597v3.pdf)</sup>

反向KL是实际选择：VI最小化的是 \( D_{KL}(q \| p) \) 而非 \( D_{KL}(p \| q) \)，因为ELBO中的期望是在 \( q_{\phi} \) 下取的，而 \( q_{\phi} \) 可以被采样；正向KL则需要在难以处理的后验下取期望。<sup>[7](https://drawinginferences.com/chapters/vi.html)</sup> 算法分为平均场变分贝叶斯（对 \( q \) 做分解）和固定形式变分贝叶斯（\( q \) 是由变分参数 \( \lambda \) 索引的参数族）。<sup>[8](https://ar5iv.labs.arxiv.org/html/2103.01327)</sup>

## 实现方法

在平均场变分贝叶斯中，分解 \( q(\theta) = q_{1}(\theta_{1}) q_{2}(\theta_{2}) \) 给出坐标上升更新 \( q_{1}(\theta_{1}) \propto \exp(\mathbb{E}_{q_{2}}[\log p(y, \theta)]) \) 和 \( q_{2}(\theta_{2}) \propto \exp(\mathbb{E}_{q_{1}}[\log p(y, \theta)]) \)，每个因子都需要在其他所有因子上取期望；下界在每次迭代中递增。<sup>[8](https://ar5iv.labs.arxiv.org/html/2103.01327)</sup> 在条件共轭模型中，这些更新类似于EM算法：“E步”计算局部潜变量的近似条件分布，“M步”计算全局潜变量的条件分布。<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> 对于全局参数 \( \lambda \) 和局部参数 \( \phi_{i} \)，ELBO的自然梯度为 \( \hat{\nabla}_{\lambda} \mathcal{L} = \mathbb{E}_{\phi}[\eta(Z, x)] - \lambda \)，用它更新可以改善优化，但在适当的正则性和步长假设下，它可能只收敛到驻点，一般而言并不保证局部最优。<sup>[5](https://www.cs.columbia.edu/~blei/papers/HoffmanBleiWangPaisley2013.pdf)</sup>

**随机变分推断（SVI）** 反复对数据做子采样以形成带噪的自然梯度估计，并以递减的步长沿其更新，\( \lambda^{(t)} = \lambda^{(t-1)} + \rho_{t} G_{t}^{-1} b_{t}(\lambda^{(t-1)}) \)，使用Fisher度量；学习率必须满足Robbins–Monro条件 \( \sum_{t} \rho_{t} = \infty \)，\( \sum_{t} \rho_{t}^{2} < \infty \)。<sup>[5](https://www.cs.columbia.edu/~blei/papers/HoffmanBleiWangPaisley2013.pdf)</sup><sup>[6](https://arxiv.org/pdf/1711.05597v3.pdf)</sup> 重参数化技巧将 \( z = g_{\phi}(\epsilon) \) 写出，其中 \( \epsilon \sim p(\epsilon) \) 与 \( \phi \) 独立，例如对高斯分布有 \( g_{\phi}(\epsilon) = \mu + \sigma \cdot \epsilon \)，从而让梯度穿过期望；将估计量代入任意随机优化器（Adam、SGD）即可在Pyro等系统中实现SVI。<sup>[7](https://drawinginferences.com/chapters/vi.html)</sup> 自动微分变分推断（ADVI）对此做了推广：它将受约束的潜变量变换到实坐标空间，通过蒙特卡洛积分估计ELBO，并用随机梯度上升优化，无需共轭假设。<sup>[9](https://papers.nips.cc/paper_files/paper/2015/file/352fe25daf686bdb4edca223c921acea-Paper.pdf)</sup><sup>[10](https://doi.org/10.48550/arxiv.1603.00788)</sup> ADVI每次迭代的复杂度为 \( O(2N \cdot M \cdot K) \)，其中 \( M \) 为蒙特卡洛样本数（通常为1到10），小批量大小为 \( B \) 时为 \( O(2B \cdot M \cdot K) \)；其梯度估计量的方差低于黑箱VI，因此单样本往往就足够。<sup>[9](https://papers.nips.cc/paper_files/paper/2015/file/352fe25daf686bdb4edca223c921acea-Paper.pdf)</sup>

## 起源

MCMC和变分方法的根源都在统计物理中。<sup>[11](https://www.cs.princeton.edu/courses/archive/fall11/cos597C/reading/WainwrightJordan2008.pdf)</sup> Neal和Hinton在1998年对EM算法的处理，在变分界与EM之间建立了重要联系。<sup>[12](https://doi.org/10.1007/978-94-011-5014-9_12)</sup> 迈克尔·乔丹及其同事1999年发表在《机器学习》上的教程，为贝叶斯网络和马尔可夫随机场中的推断与学习建立了变分方法。<sup>[13](https://doi.org/10.1023/a:1007665907178)</sup> 哈盖·阿蒂亚斯在NIPS 1999（论文集于2000年出版）上提出了变分贝叶斯，作为图模型的实用框架，其算法推广了EM并具有收敛保证。<sup>[14](https://proceedings.neurips.cc/paper/1999/file/74563ba21a90da13dacf2a73e3ddefa7-Paper.pdf)</sup> Wainwright和乔丹2008年发表在《机器学习基础与趋势》上的专著，通过指数族表示和共轭对偶统一了该领域。<sup>[15](https://doi.org/10.1561/2200000001)</sup> 马特·霍夫曼及其同事于2012年提出了随机变分推断。<sup>[16](https://doi.org/10.48550/arxiv.1206.7051)</sup>

## 变体

**坍缩VI** 通过积分消去变量来加速推断，如潜空间变分贝叶斯<sup>[17](https://doi.org/10.1109/tpami.2008.157)</sup>和共轭指数族中的快速VI。<sup>[18](https://doi.org/10.48550/arxiv.1206.5162)</sup> **黑箱VI** 在导数不可用时通过采样估计ELBO梯度，<sup>[19](https://doi.org/10.48550/arxiv.1401.0118)</sup> Wingate和Weber 2013年的自动VI将随机梯度VI引入概率编程。<sup>[20](https://doi.org/10.48550/arxiv.1301.1299)</sup> **归一化流** 通过可逆变换丰富简单的 \( q \)，最初作为对角高斯的事后增强<sup>[21](https://doi.org/10.48550/arxiv.1505.05770)</sup>，后来发展为可随潜变量维度扩展的架构，最著名的是逆自回归流。<sup>[22](https://proceedings.neurips.cc/paper_files/paper/2025/file/7ed14a8ca0da9df00d8d0e15617d8e2a-Paper-Conference.pdf)</sup> 退火流输运蒙特卡洛将流与退火结合用于采样。<sup>[23](https://doi.org/10.48550/arxiv.2102.07501)</sup> 扩散隐式变分推断将扩散模型与隐式VI结合。<sup>[24](https://www.aimsciences.org/article/doi/10.3934/mfc.2026024)</sup> Ξ-VI通过用多边际Sinkhorn算法求解的熵正则化来扩展平均场VI，并证明了后验一致性和Bernstein–von Mises定理。<sup>[25](http://jmlr.org/papers/volume27/24-1057/24-1057.pdf)</sup> 2024年的一项大规模评估将基于流的VI、随机归一化流、退火流输运和CRAFT与基于扩散的采样器进行了基准比较。<sup>[26](https://arxiv.org/abs/2406.07423)</sup> 2025年的一项结果表明，每个满秩变分隐式后验变换都可以精确表示为利用模型的先验函数添加了平移项的前向自回归流。<sup>[22](https://proceedings.neurips.cc/paper_files/paper/2025/file/7ed14a8ca0da9df00d8d0e15617d8e2a-Paper-Conference.pdf)</sup>

## 应用

**主题模型** 是SVI的一个应用，它分析了30万篇《自然》、180万篇《纽约时报》和380万篇维基百科文章，这些规模是批量变分推断无法处理的。<sup>[5](https://www.cs.columbia.edu/~blei/papers/HoffmanBleiWangPaisley2013.pdf)</sup> 用于LDA的随机坍缩变分推断在《纽约时报》和维基百科数据集上收敛到比SVI更好的留出似然。<sup>[27](https://jfoulds.informationsystems.umbc.edu/Foulds_SCVB0.pdf)</sup> 对于LDA，一次VB坐标更新的代价为 \( O(m \cdot k) \)，而精确坍缩VB为 \( O(m^{2} \cdot k) \)，界紧性差距以 \( O(k^{-1}) + p \log m / m \) 递减。<sup>[28](https://papers.nips.cc/paper_files/paper/2008/file/a49e9411d64ff53eccfdd09ad10a15b3-Paper.pdf)</sup> 在**生成建模**中，将神经网络识别模型（概率编码器）拟合到难以处理的后验，就得到变分自编码器。<sup>[29](https://papers.baulab.info/papers/Kingma-2013.pdf)</sup> ADVI部署在Stan概率编程系统中，并被应用于具有数百万观测的数据集。<sup>[9](https://papers.nips.cc/paper_files/paper/2015/file/352fe25daf686bdb4edca223c921acea-Paper.pdf)</sup><sup>[10](https://doi.org/10.48550/arxiv.1603.00788)</sup>

## 局限与替代方案

VI通常低估后验方差，这是其目标函数的后果，其相对于MCMC的准确度仍然未知。<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup> 机制在于反向KL：最小化 \( D_{KL}(q \| p) \) 得到的分布会避开 \( p \) 较小的区域，因此对于多峰后验，\( q \) 倾向于找到单一众数，而覆盖概率质量的 \( D_{KL}(p \| q) \) 会在各众数间平均；对相关高斯的因子化近似则过于紧凑。<sup>[30](https://www.cs.cmu.edu/~rsalakhu/10707/Lectures/Lecture_Variational_Inference_2019.pdf)</sup> 因此平均场高斯引导给出过度自信的可信区间，即一个轴对齐的椭球，中心正确但系统性地过窄。<sup>[7](https://drawinginferences.com/chapters/vi.html)</sup> VB近似的是联合分布，因此各个 \( q_{i}(x_{i}) \) 分量可能很差，甚至与真实边缘分布相差甚远，这使得它比具有局部可解释节点状态的算法更难调试。<sup>[4](https://robots.ox.ac.uk/~sjrob/Pubs/vbTutorialFinal.pdf)</sup> ELBO是非凸的，CAVI只保证对初始化敏感的局部最优。<sup>[1](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)</sup>

与**拉普拉斯近似**相比——后者纯属局部、限于高斯族、不适用于离散变量，且在高维中需要昂贵的Hessian求逆——KL最小化通常能更准确地近似后验协方差。<sup>[6](https://arxiv.org/pdf/1711.05597v3.pdf)</sup> 理论上，高斯VI的均值误差按 \( (d/(\beta n))^{3} \) 缩放，而拉普拉斯为 \( d/(\beta n) \)，小两个数量级。<sup>[31](https://par.nsf.gov/servlets/purl/10633863)</sup> 期望传播达到与高斯VI相同的均值和协方差精度。<sup>[31](https://par.nsf.gov/servlets/purl/10633863)</sup> 由于反向KL是寻模的，ELBO对模式坍缩不敏感；与正向KL相关的证据上界（EUBO）则非常适合量化它。<sup>[26](https://arxiv.org/abs/2406.07423)</sup>

## References

1. [Variational Inference: A Review for Statisticians (Blei, Kucukelbir, McAuliffe), JASA Vol 112, No 518](https://www.tandfonline.com/doi/abs/10.1080/01621459.2017.1285773)
2. [α-Variational Inference with Statistical Guarantees (Wang & Blei)](https://ar5iv.labs.arxiv.org/html/1710.03266)
3. [Deep Learning, Chapter 19: Inference as Optimization (Goodfellow, Bengio, Courville)](https://www.deeplearningbook.org/contents/inference.html)
4. [A tutorial on variational Bayesian inference (Fox & Roberts, Artificial Intelligence Review, 2011)](https://robots.ox.ac.uk/~sjrob/Pubs/vbTutorialFinal.pdf)
5. [Stochastic Variational Inference (Hoffman, Blei, Wang, Paisley, 2013, JMLR)](https://www.cs.columbia.edu/~blei/papers/HoffmanBleiWangPaisley2013.pdf)
6. [Advances in Variational Inference (Zhang, Bütepage, Kjellström, Mandt), IEEE TPAMI](https://arxiv.org/pdf/1711.05597v3.pdf)
7. [Variational inference – Drawing Inferences (Pyro/SVI chapter)](https://drawinginferences.com/chapters/vi.html)
8. [A practical tutorial on Variational Bayes (Tran et al.)](https://ar5iv.labs.arxiv.org/html/2103.01327)
9. [Automatic Variational Inference in Stan (Kucukelbir, Tran, Ranganath, Gelman, Blei, NIPS 2015)](https://papers.nips.cc/paper_files/paper/2015/file/352fe25daf686bdb4edca223c921acea-Paper.pdf)
10. [Kucukelbir, Alp and colleagues (2016). Automatic Differentiation Variational Inference. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1603.00788)
11. [Graphical models, exponential families, and variational inference (Wainwright & Jordan, Foundations and Trends in ML, 2008)](https://www.cs.princeton.edu/courses/archive/fall11/cos597C/reading/WainwrightJordan2008.pdf)
12. [Radford M. Neal, Geoffrey E. Hinton (1998). A View of the Em Algorithm that Justifies Incremental, Sparse, and other Variants. .](https://doi.org/10.1007/978-94-011-5014-9_12)
13. [Michael I. Jordan and colleagues (1999). An Introduction to Variational Methods for Graphical Models. Machine Learning.](https://doi.org/10.1023/a:1007665907178)
14. [A Variational Bayesian Framework for Graphical Models (H. Attias, NIPS 1999)](https://proceedings.neurips.cc/paper/1999/file/74563ba21a90da13dacf2a73e3ddefa7-Paper.pdf)
15. [Martin J. Wainwright, Michael I. Jordan (2008). Graphical Models, Exponential Families, and Variational Inference. Foundations and Trends® in Machine Learning.](https://doi.org/10.1561/2200000001)
16. [Hoffman, Matt and colleagues (2012). Stochastic Variational Inference. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1206.7051)
17. [Jaemo Sung, Z. Ghahramani, Sung-Yang Bang (2008). Latent-Space Variational Bayes. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/tpami.2008.157)
18. [Hensman, James, Rattray, Magnus, Lawrence, Neil D. (2012). Fast Variational Inference in the Conjugate Exponential Family. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1206.5162)
19. [Ranganath, Rajesh, Gerrish, Sean, Blei, David M. (2013). Black Box Variational Inference. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1401.0118)
20. [Wingate, David, Weber, Theophane (2013). Automated Variational Inference in Probabilistic Programming. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1301.1299)
21. [Rezende, Danilo Jimenez, Mohamed, Shakir (2015). Variational Inference with Normalizing Flows. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1505.05770)
22. [Model-Informed Flows for Bayesian Inference (NeurIPS 2025)](https://proceedings.neurips.cc/paper_files/paper/2025/file/7ed14a8ca0da9df00d8d0e15617d8e2a-Paper-Conference.pdf)
23. [Arbel, Michael, Matthews, Alexander G. D. G., Doucet, Arnaud (2021). Annealed Flow Transport Monte Carlo. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2102.07501)
24. [Diffusion implicit variational inference for complex posterior modeling (DIVI)](https://www.aimsciences.org/article/doi/10.3934/mfc.2026024)
25. [Extending Mean-Field Variational Inference via Entropic Regularization: Theory and Computation (Ξ-VI), JMLR](http://jmlr.org/papers/volume27/24-1057/24-1057.pdf)
26. [Beyond ELBOs: A Large-Scale Evaluation of Variational Methods for Sampling (2024)](https://arxiv.org/abs/2406.07423)
27. [Stochastic Collapsed Variational Bayesian Inference for LDA (SCVB0)](https://jfoulds.informationsystems.umbc.edu/Foulds_SCVB0.pdf)
28. [Relative Performance Guarantees for Approximate Inference in Latent Dirichlet Allocation (Teh, Kurihara, Welling, NeurIPS 2008)](https://papers.nips.cc/paper_files/paper/2008/file/a49e9411d64ff53eccfdd09ad10a15b3-Paper.pdf)
29. [Auto-Encoding Variational Bayes (Kingma, Welling, 2013, ICLR 2014)](https://papers.baulab.info/papers/Kingma-2013.pdf)
30. [CMU 10-707 lecture notes on Variational Inference](https://www.cs.cmu.edu/~rsalakhu/10707/Lectures/Lecture_Variational_Inference_2019.pdf)
31. [Approximation accuracy of Gaussian variational inference (error bounds vs Laplace)](https://par.nsf.gov/servlets/purl/10633863)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Oct 15, 2026 · Last review: Sep 30, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Bayesian statistics › Bayesian computation and software › Variational and approximate Bayesian methods

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/variational-bayesian-inference

English original: https://www.edgepedia.org/variational-bayesian-inference
