# 贝叶斯深度学习

贝叶斯深度学习（BDL）将深度神经网络与[贝叶斯概率](https://www.edgepedia.org/zh/bayesian-probability)论相结合，使模型输出的是预测的概率分布而非单一的点估计，从而量化模型应当具有的不确定性程度。标准的确定性网络对每一个输入都给出一个自信的数值，包括那些它从未有效见过的输入；BDL则以概率分布取代固定权重，并将其传播为预测分布，在一个统一的概率框架中整合了深度学习与[贝叶斯推断](https://www.edgepedia.org/zh/bayesian-inference)。<sup>[1](https://arxiv.org/pdf/1604.01662)</sup>

| 关键事实 | 详情 |
|---|---|
| 不确定的是什么 | 网络权重服从后验分布 \( p(\theta \mid D) \)；预测变为在该后验上平均的预测分布。<sup>[2](https://proceedings.mlr.press/v37/blundell15)</sup> |
| 核心算法 | 通过反向传播学习权重分布的Bayes by Backprop，最小化变分自由能。<sup>[2](https://proceedings.mlr.press/v37/blundell15)</sup> |
| 最廉价的方法 | MC Dropout与拉普拉斯近似相对于标准训练几乎不增加训练时间成本（相对于MAP的倍数为1.0），SWAG的成本为MAP的1.0至1.5倍。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup> |
| 最昂贵的方法 | 随机梯度变分推断（如Bayes by Backprop）的训练时间约为MAP的5.0至5.7倍；SVGD约为8.0至10.0倍。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup> |
| 不确定性类型 | 偶然不确定性是观测中固有的噪声；认知不确定性是模型不确定性，在数据充足时可以消除。<sup>[4](https://proceedings.neurips.cc/paper_files/paper/2017/file/2650d6089a6d640c5e85b2b88265dc2b-Paper.pdf)</sup> |
| 主要失效模式 | 标准的基于KL的变分推断因寻模行为而倾向于低估后验不确定性。<sup>[5](https://arxiv.org/pdf/2502.18300v4.pdf)</sup> |
| 实际应用领域 | 医疗健康、药物发现、气候科学、机器人学、自动驾驶、金融与欺诈检测。<sup>[6](https://arxiv.org/html/2402.00809)</sup><sup> • </sup><sup>[7](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> |

## 工作原理

[贝叶斯神经网络](https://www.edgepedia.org/zh/bayesian-neural-network)在其权重 \( \theta \) 上放置一个先验分布，并在观测到数据 \( D \) 后寻求后验 \( p(\theta \mid D) \)。预测通过预测分布 \( P(\hat{y} \mid \hat{x}) = E_{P(w \mid D)}[P(\hat{y} \mid \hat{x}, w)] \) 做出，这是对权重后验的期望，其行为类似于由不可数无穷多个网络组成的集成，而通常只使参数数量翻倍。<sup>[2](https://proceedings.mlr.press/v37/blundell15)</sup> 在实践中，该期望通过从后验中采样 \( N_s \) 组权重、运行 \( N_s \) 个网络实现、并由其输出构造置信区间来近似。<sup>[7](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup>

对权重的[精确推断](https://www.edgepedia.org/zh/exact-inference)难以处理，因此变分推断用一个可处理的分布 \( q(\theta) \) 近似后验，方法是极小化 \( q(\theta) \) 到 \( p(\theta \mid D) \) 的KL散度。<sup>[7](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> 由于真实后验未知，目标函数为证据下界（ELBO）。对于变分族 \( q_\phi \)，恒等式

\[ \int q_{\phi}(H_0) \log \frac{P(H_0, D)}{q_{\phi}(H_0)}\, dH_0 = \log P(D) - D_{\mathrm{KL}}(q_{\phi} \,\|\, P) \]

表明极小化KL散度等价于极大化ELBO，后者通常通过随机梯度变分推断来优化。<sup>[8](https://faculty.utrgv.edu/dongchul.kim/6379/t9.pdf)</sup> 梯度之所以能穿过采样，归功于重参数化技巧：将采样的权重写成确定性变换 \( \theta = T_{\phi}(\varepsilon) \)，其中 \( \varepsilon \sim p_{\mathrm{base}}(\varepsilon) \)，从而对 \( \phi \) 可微。<sup>[5](https://arxiv.org/pdf/2502.18300v4.pdf)</sup>

BDL还将两类不确定性区分开来。认知不确定性由权重后验 \( p(\theta \mid D) \) 刻画，随数据增多而收缩；偶然不确定性是数据中的内在噪声，由似然 \( p(y \mid \theta) \) 刻画。<sup>[7](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> 总的预测不确定性分解为

\[ H[p(y^* \mid x^*, D)] = E_{p(\theta \mid D)}\big[H[p(y^* \mid x^*, \theta)]\big] + I[y^*; \theta \mid x^*, D], \]

第一项为偶然不确定性，互信息项为认知不确定性。<sup>[5](https://arxiv.org/pdf/2502.18300v4.pdf)</sup>

## 实施方法

实践者首先选择一种近似方法。2023年一项大规模基准测试所收录的主要方法族包括：Bayes by Backprop（用SGD拟合对角高斯后验）、Rank-1变分推断、iVON、SVGD、最后一层拉普拉斯近似、MC Dropout，以及从存储的SGD迭代点构造低秩高斯后验的SWAG。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup>

Bayes by Backprop是一种与反向传播兼容的算法，用于学习网络权重上的概率分布，通过最小化变分自由能（对数边际似然的证据下界的负值）来正则化权重。<sup>[2](https://proceedings.mlr.press/v37/blundell15)</sup> MC Dropout无需改变架构：对于伯努利dropout变分分布 \( q(\omega) \)，变分优化与dropout训练完全相同，因此用dropout训练的网络本身就是一个贝叶斯神经网络，不确定性来自测试时对 \( T \) 次随机前向传播取平均。<sup>[9](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/3_bayesian_deep_learning.pdf)</sup> 拉普拉斯近似网络不增加训练时间成本，只需少数几个轮次的事后开销即可产生不确定性估计。<sup>[6](https://arxiv.org/html/2402.00809)</sup> 训练之后，模型不仅在准确率上评估，还在校准性上评估，例如用[期望校准误差](https://www.edgepedia.org/zh/expected-calibration-error)；在一项PyTorch库研究中，将测试时后验样本从0增加到5同时降低了ECE和MCE，改善了校准性。<sup>[10](https://ar5iv.labs.arxiv.org/html/2309.12928)</sup> 软件反映了这些权衡：BayesDLL库为PyTorch（包括视觉Transformer）实现了变分推断、MC dropout、随机梯度MCMC和拉普拉斯近似，其中SGLD和拉普拉斯近似带来的开销至多为基础模型复杂度的两倍。<sup>[10](https://ar5iv.labs.arxiv.org/html/2309.12928)</sup>

## 起源

大卫·J. C. 麦凯（David J. C. MacKay）在《前馈网络学习的实用贝叶斯框架》（“A Practical Bayesian Framework for Backpropagation Networks”，Neural Computation，1992）中引入了用于前馈网络学习映射的定量且实用的贝叶斯框架，给出了剪枝或增长网络的客观停止规则，并量化了参数与输出的误差棒；其贝叶斯“证据”通过惩罚过度灵活的模型体现了[奥卡姆剃刀](https://www.edgepedia.org/zh/occams-razor)。<sup>[11](https://www.cs.columbia.edu/~blei/seminar/2020-representation/readings/MacKay1992a.pdf)</sup><sup> • </sup><sup>[12](https://doi.org/10.1162/neco.1992.4.3.448)</sup> 现代变分方法的复兴始于查尔斯·布伦德尔（Charles Blundell）及其同事在《神经网络中的权重不确定性》（“Weight Uncertainty in Neural Networks”，arXiv，2015）中报告Bayes by Backprop，<sup>[13](https://doi.org/10.48550/arxiv.1505.05424)</sup> 以及亚林·加尔（Yarin Gal）与佐宾·加赫拉马尼（Zoubin Ghahramani）在《Dropout作为贝叶斯近似》（“Dropout as a Bayesian Approximation”，arXiv，2015）中报告dropout与贝叶斯近似的等价性。<sup>[14](https://doi.org/10.48550/arxiv.1506.02142)</sup> 这一术语本身由王浩（Hao Wang）与杨迪然（Dit-Yan Yeung）的《走向贝叶斯深度学习：一个框架及若干现有方法》（“Towards Bayesian Deep Learning: A Framework and Some Existing Methods”，IEEE Transactions on Knowledge and Data Engineering，2016）确立，该文提出了一个统一框架，其中深度学习的感知提升高层贝叶斯推断，而推断反馈增强感知。<sup>[15](https://doi.org/10.1109/tkde.2016.2606428)</sup><sup> • </sup><sup>[16](https://dl.acm.org/doi/10.1109/tkde.2016.2606428)</sup> 可扩展变分dropout所依赖的局部重参数化技巧由迪德里克·P. 金马（Diederik P. Kingma）、蒂姆·萨利曼斯（Tim Salimans）与马克斯·韦林（Max Welling）在《变分Dropout与局部重参数化技巧》（“Variational Dropout and the Local Reparameterization Trick”，arXiv，2015）中报告。<sup>[17](https://doi.org/10.48550/arxiv.1506.02557)</sup>

## 变体

**Bayes by Backprop** 通过SGD为每个权重拟合高斯变分后验；它在MNIST分类上与dropout相当，在非线性回归中改善泛化，其权重不确定性可驱动[强化学习中的探索](https://www.edgepedia.org/zh/exploration-in-reinforcement-learning)。<sup>[2](https://proceedings.mlr.press/v37/blundell15)</sup> **MC Dropout** 是获得有根据的不确定性最廉价的途径，只需在推断时进行多次随机前向传播。<sup>[9](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/3_bayesian_deep_learning.pdf)</sup> **拉普拉斯近似**与**SWAG**是事后或近事后方法：拉普拉斯近似不增加训练时间成本，而SWAG从SGD迭代点构造高斯近似后验。<sup>[6](https://arxiv.org/html/2402.00809)</sup> **深度集成**用通常五到十个独立训练的MAP模型近似后验；SNGP将最后一层替换为[高斯过程](https://www.edgepedia.org/zh/gaussian-process)，不能直接与权重空间的贝叶斯算法相比较。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup> 集成并不自动是贝叶斯的：一个RBF网络的例子表明，其输出方差在远离训练数据处可以为零，而那恰恰是最需要不确定性的地方。<sup>[18](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/2_language_of_uncertainty.pdf)</sup> **函数空间BDL**是较新的方向：吴梦静（Mengjing Wu）、宣俊宇（Junyu Xuan）与陆杰（Jie Lu）的贝叶斯神经网络函数空间随机梯度MCMC（arXiv，2024）在函数空间中进行采样。<sup>[19](https://doi.org/10.48550/arxiv.2409.16632)</sup>

## 应用

贝叶斯神经网络在医疗应用、金融、欺诈检测、工程与遗传学等高风险领域广受接纳。<sup>[7](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> 2024年的一篇立场论文将医疗健康、药物发现、气候科学、机器人学、自动驾驶与天体物理学列为BDL的应用领域，并主张不确定性量化可以缓解大语言模型中的幻觉与过度自信预测，同时指出针对大语言模型的BDL方法仍相对未被探索。<sup>[6](https://arxiv.org/html/2402.00809)</sup> 在[计算](https://www.edgepedia.org/zh/computation)机视觉中，一个基于DenseNet的异方差模型处理一幅640×480图像耗时150毫秒，其认知不确定性在远离训练集的测试点上增大，而偶然不确定性保持相对恒定。<sup>[4](https://proceedings.neurips.cc/paper_files/paper/2017/file/2650d6089a6d640c5e85b2b88265dc2b-Paper.pdf)</sup> 采用落后于理论：截至2020年初，工业实践中尚无公开报道的贝叶斯神经网络部署。<sup>[20](https://proceedings.mlr.press/v119/wenzel20a.html)</sup>

## 局限与替代方案

**近似推断低估不确定性。** 标准的基于KL的变分推断是寻模的，倾向于低估后验不确定性。<sup>[5](https://arxiv.org/pdf/2502.18300v4.pdf)</sup> 拉普拉斯等局部近似与变分方法只捕捉多峰BNN后验的单一模态，且依赖参数化，线性化可以缓解这一问题。<sup>[6](https://arxiv.org/html/2402.00809)</sup>

**精确后验未必更好。** 文策尔（Wenzel）及其同事表明，在流行深度神经网络中对真实贝叶斯后验进行仔细的MCMC采样，并不能改善准确率或校准性，这使人们对深度网络中贝叶斯后验的标准理解产生怀疑。<sup>[20](https://proceedings.mlr.press/v119/wenzel20a.html)</sup>

**分布外行为薄弱。** 在一个二维例子中，BNN与MC Dropout都可能对分布外数据估计出低不确定性，而高斯过程能检测出OOD样本；高斯过程具有距离感知能力，但随数据维度增长扩展性不佳。<sup>[21](https://ar5iv.labs.arxiv.org/html/2107.12248)</sup> 经验上，与不维护认知不确定性的模型相比，BNN在OOD检测上往往仅略微优越，这表明存在不能仅由近似推断解释的根本局限。<sup>[21](https://ar5iv.labs.arxiv.org/html/2107.12248)</sup> [深度集成](https://www.edgepedia.org/zh/deep-ensembles)作为最接近的实用替代方案，以数倍于单个模型训练的成本换取简单性，但在远离数据处可能坍缩为零方差。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup><sup> • </sup><sup>[18](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/2_language_of_uncertainty.pdf)</sup>

**贝叶斯计算的扩展。** 三个障碍占主导：超高维权重向量（数百万到数十亿）、高度非线性的多峰似然，以及使传统MCMC失效的海量数据；随机梯度MCMC使得在ResNet等大规模BNN中采样成为可能。<sup>[5](https://arxiv.org/pdf/2502.18300v4.pdf)</sup> 近期工作从先验与推断空间两方面入手：文森特·福图因（Vincent Fortuin）及其同事通过最小化Wasserstein距离调整BNN权重先验，使其诱导的函数先验匹配高斯过程先验，在包括CNN在内的回归与分类任务上带来系统性改善，<sup>[22](https://jmlr.org/papers/volume23/20-1340/20-1340.pdf)</sup> 而2023年的基准测试首次对BDL用于微调大型预训练模型进行了系统评估，因为从头训练代价高昂。<sup>[3](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup>

## References

1. [A Survey on Bayesian Deep Learning (Wang & Yeung, arXiv 2016)](https://arxiv.org/pdf/1604.01662)
2. [Weight Uncertainty in Neural Networks (Blundell, Cornebise, Kavukcuoglu, Wierstra, ICML 2015, PMLR v37, pp. 1613–1622)](https://proceedings.mlr.press/v37/blundell15)
3. [Beyond Deep Ensembles: A Large-Scale Evaluation of Bayesian Deep Learning under Distribution Shift (NeurIPS 2023)](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)
4. [What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision? (Kendall & Gal, NeurIPS 2017)](https://proceedings.neurips.cc/paper_files/paper/2017/file/2650d6089a6d640c5e85b2b88265dc2b-Paper.pdf)
5. [Bayesian Computation in Deep Learning (2025 survey)](https://arxiv.org/pdf/2502.18300v4.pdf)
6. [Position: Bayesian Deep Learning is Needed in the Age of Large-Scale AI (2024)](https://arxiv.org/html/2402.00809)
7. [Bayesian learning for neural networks: an algorithmic survey (Artificial Intelligence Review, 2023)](https://link.springer.com/article/10.1007/s10462-023-10443-1)
8. [Hands-on Bayesian Neural Networks – A Tutorial (IEEE tutorial)](https://faculty.utrgv.edu/dongchul.kim/6379/t9.pdf)
9. [Bayesian Deep Learning (chapter of Yarin Gal's PhD thesis, Uncertainty in Deep Learning)](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/3_bayesian_deep_learning.pdf)
10. [BayesDLL: Bayesian Deep Learning Library](https://ar5iv.labs.arxiv.org/html/2309.12928)
11. [A Practical Bayesian Framework for Backpropagation Networks (MacKay, 1992)](https://www.cs.columbia.edu/~blei/seminar/2020-representation/readings/MacKay1992a.pdf)
12. [David J. C. MacKay (1992). A Practical Bayesian Framework for Backpropagation Networks. Neural Computation.](https://doi.org/10.1162/neco.1992.4.3.448)
13. [Blundell, Charles and colleagues (2015). Weight Uncertainty in Neural Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1505.05424)
14. [Gal, Yarin, Ghahramani, Zoubin (2015). Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1506.02142)
15. [Hao Wang, Dit-Yan Yeung (2016). Towards Bayesian Deep Learning: A Framework and Some Existing Methods. IEEE Transactions on Knowledge and Data Engineering.](https://doi.org/10.1109/tkde.2016.2606428)
16. [Towards Bayesian Deep Learning: A Framework and Some Existing Methods (Wang & Yeung, IEEE TKDE Vol 28 No 12, 2016)](https://dl.acm.org/doi/10.1109/tkde.2016.2606428)
17. [Kingma, Diederik P., Salimans, Tim, Welling, Max (2015). Variational Dropout and the Local Reparameterization Trick. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1506.02557)
18. [The Language of Uncertainty (chapter of Yarin Gal's PhD thesis)](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/2_language_of_uncertainty.pdf)
19. [Wu, Mengjing, Xuan, Junyu, Lu, Jie (2024). Functional Stochastic Gradient MCMC for Bayesian Neural Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2409.16632)
20. [How Good is the Bayes Posterior in Deep Neural Networks Really? (Wenzel et al., ICML 2020)](https://proceedings.mlr.press/v119/wenzel20a.html)
21. [Are Bayesian neural networks intrinsically good at out-of-distribution detection?](https://ar5iv.labs.arxiv.org/html/2107.12248)
22. [All You Need is a Good Functional Prior for Bayesian Deep Learning (JMLR)](https://jmlr.org/papers/volume23/20-1340/20-1340.pdf)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Titles A to H

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/bayesian-deep-learning

English original: https://www.edgepedia.org/bayesian-deep-learning
