# 贝叶斯神经网络

贝叶斯神经网络（BNN）是用[贝叶斯推断](https://www.edgepedia.org/zh/bayesian-inference)训练的神经网络，它在网络的权重上放置概率分布，而不是拟合单个点值，因此每个预测都带有量化的不确定性。贝叶斯学习的结果是模型参数上的概率分布，表达了对不同参数值可能性的信念，其起点是为这些参数定义一个先验分布。<sup>[1](https://www.cs.columbia.edu/~blei/seminar/2020-representation/readings/Neal1996.pdf)</sup> 由于权重是分布，网络的输出是预测分布而非某个标签或数值，据报告，BNN 比经典神经网络具有更好的校准性，能区分不同类型的不确定性，并在小数据集上具有数据效率。<sup>[2](https://export.arxiv.org/pdf/2007.06823)</sup>

| 关键事实 | 详情 |
|---|---|
| 学到的是什么 | 权重上的后验分布 \( p(\theta \mid D) \)，而非点估计<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> |
| 核心障碍 | 边际似然 \( p(D) = \int p(\theta)\,p(D \mid \theta)\,d\theta \) 在深层网络中通常难以计算<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> |
| 预测 | 贝叶斯模型平均 \( p(y \mid x, D) = \int p(y \mid x, w)\,p(w \mid D)\,dw \)，通过对网络实现进行蒙特卡洛采样来近似<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup><sup> • </sup><sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> |
| 不确定性类型 | 认知不确定性（可通过更多数据减少，由后验承载）与偶然不确定性（数据噪声，由似然承载）<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> |
| 主要推断方法族 | 变分推断、MCMC（尤其是哈密顿蒙特卡洛）、基于 dropout 的近似，以及拉普拉斯近似<sup>[5](https://wjmaddox.github.io/assets/BNN_tutorial_CILVR.pdf)</sup> |
| 规模问题 | 数百万到数十亿权重上的后验，且似然为多峰，使经典 Metropolis-Hastings 和 Gibbs 采样失效<sup>[6](https://arxiv.org/pdf/2502.18300v4.pdf)</sup> |
| 实际成本 | 拉普拉斯近似网络不增加训练成本，只需与几个训练轮次相当的事后开销<sup>[7](https://arxiv.org/html/2402.00809)</sup> |

## 工作原理

给定数据集 \( D \)，BNN 指定权重上的先验 \( p(\theta) \) 和似然 \( p(D \mid \theta) \)，目标是后验 \( p(\theta \mid D) = p(\theta)\,p(D \mid \theta)/p(D) \)。<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> 分母即边际似然，需要对所有可能的权重设置积分，对深层网络难以计算，因此后验必须近似。<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup> 对新输入的预测通过贝叶斯模型平均 \( p(y \mid x, D) = \int p(y \mid x, w)\,p(w \mid D)\,dw \) 进行，该式对神经网络同样没有闭式解。<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup> 实践中，这个积分通过从近似后验中抽取 \( N_s \) 个权重样本、并将每个样本作为普通网络运行来估计；它们输出的离散程度构成预测分布。<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup>

预测不确定性分解为两部分：各个预测分布的期望熵是偶然不确定性（数据固有的噪声），预测与权重之间的互信息 \( I[y^*;\theta \mid x^*, D] \) 是认知不确定性，后者随着数据增多而收缩。<sup>[6](https://arxiv.org/pdf/2502.18300v4.pdf)</sup> 忽略后验不确定性会导致过度自信的预测。<sup>[5](https://wjmaddox.github.io/assets/BNN_tutorial_CILVR.pdf)</sup>

## 具体实现

主流的实用方法是变分推断：通过最小化与真实后验的 Kullback-Leibler 散度来拟合一个可处理的分布族 \( q_\phi(\theta) \)，等价于最大化证据下界 \( L_{\mathrm{ELBO}}(\phi) := \log p(D) - \mathrm{KL}[q_\phi(\theta) \,\|\, p(\theta \mid D)] \)，该式可拆分为期望对数似然项和朝向先验的 KL 正则项。<sup>[6](https://arxiv.org/pdf/2502.18300v4.pdf)</sup><sup> • </sup><sup>[8](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/thesis.pdf)</sup> 由于重参数化技巧，梯度可以穿过采样过程：权重样本 \( \theta \sim q_\phi(\theta) \) 被改写为辅助噪声 \( \varepsilon \) 的可微变换 \( T_\phi(\varepsilon) \)，因此 ELBO 可以用普通反向传播优化。<sup>[6](https://arxiv.org/pdf/2502.18300v4.pdf)</sup> 平均场高斯——即每个权重得到一个独立高斯后验——是最流行的变分选择之一。<sup>[6](https://arxiv.org/pdf/2502.18300v4.pdf)</sup>

另一大类是随机梯度 MCMC。由于非线性激活破坏了先验与后验的共轭性，精确后验采样需要 MCMC；[哈密顿蒙特卡洛](https://www.edgepedia.org/zh/hamiltonian-monte-carlo)用一个动量向量扩展状态，并使用基于梯度的提议，产生的样本相关性更低，收敛速度比随机游走 Metropolis-Hastings 更快。<sup>[9](https://ar5iv.labs.arxiv.org/html/2304.02595)</sup> 全批量 HMC 被认为是 BNN 训练的黄金标准，但代价高昂。<sup>[10](https://www.osti.gov/servlets/purl/2001808)</sup><sup> • </sup><sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup> 拉普拉斯近似是一种事后替代方案：它在已训练网络的众数附近拟合一个高斯，保持已训练网络的预测不变，并可扩展到大型模型，其中海森矩阵常用 KFAC 近似以保证可处理性。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2024/file/19774ce2d4b0d17a3a8aea26ad99fe8a-Paper-Conference.pdf)</sup><sup> • </sup><sup>[7](https://arxiv.org/html/2402.00809)</sup>

## 起源

1991年，Wray Buntine 与 Andreas S. Weigend 在《Complex Systems》上发表了《Bayesian Back-Propagation》，提出了用于前馈网络反向传播训练中统计成分的近似贝叶斯方法，涵盖非线性回归和 one-of-C 分类。<sup>[12](https://content.wolfram.com/sites/13/2018/02/05-6-4.pdf)</sup> [David J. C. MacKay](https://www.edgepedia.org/zh/david-j-c-mackay) 1992年发表在《Neural Computation》上的论文《Bayesian Interpolation》和《A Practical Bayesian Framework for Backpropagation Networks》建立了一个定量框架，其中贝叶斯“证据”通过惩罚过度复杂的模型自动体现[奥卡姆剃刀](https://www.edgepedia.org/zh/occams-razor)原则，并支持架构比较、剪枝以及参数和输出上的误差棒。<sup>[13](https://doi.org/10.1162/neco.1992.4.3.415)</sup><sup> • </sup><sup>[14](https://doi.org/10.1162/neco.1992.4.3.448)</sup> 专著《Bayesian Learning for Neural Networks》使用哈密顿蒙特卡洛对 BNN 后验进行采样，此后 HMC 一直被视为 BNN 训练的黄金标准。<sup>[1](https://www.cs.columbia.edu/~blei/seminar/2020-representation/readings/Neal1996.pdf)</sup><sup> • </sup><sup>[10](https://www.osti.gov/servlets/purl/2001808)</sup> 将变分技术用于 BNN，以及现代深度学习的复兴，则伴随 Bayes by Backprop（2015）和基于 dropout 的贝叶斯近似（2015-2016）而来。<sup>[8](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/thesis.pdf)</sup>

## 变体

**Bayes by Backprop** 是一种与反向传播兼容的算法，通过最小化变分自由能（边际似然的下界期望）来学习权重上的概率分布。<sup>[15](https://proceedings.mlr.press/v37/blundell15.html)</sup> 它是随机变分推断结合重参数化技巧的实用实现，因此反向传播对变分参数照常工作。<sup>[2](https://export.arxiv.org/pdf/2007.06823)</sup>

**MC Dropout** 来自 Gal 与 Ghahramani 2015年的论文《Dropout as a Bayesian Approximation》，该文证明，在每层之前使用 dropout 的任意深度网络在数学上等价于一个概率深度高斯过程的近似；它速度快，可应用于已经用 dropout 训练过的模型而无需重新训练，不过有证据表明它不能完全捕捉预测不确定性。<sup>[16](https://doi.org/10.48550/arxiv.1506.02142)</sup><sup> • </sup><sup>[2](https://export.arxiv.org/pdf/2007.06823)</sup><sup> • </sup><sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup>

**深度集成**来自 Lakshminarayanan、Pritzel 与 Blundell（2016），从不同的随机初始化训练多个网络并平均其预测分布；它们与自助法的区别仅在于不做重采样。<sup>[17](https://doi.org/10.48550/arxiv.1612.01474)</sup><sup> • </sup><sup>[10](https://www.osti.gov/servlets/purl/2001808)</sup> **SWAG** 从 SGD 迭代的轨迹构建高斯近似后验，从该轨迹而非单点的海森矩阵估计曲率。<sup>[7](https://arxiv.org/html/2402.00809)</sup> Wilson 与 Izmailov（2020）的 MultiSWAG 是相关变体。<sup>[18](https://doi.org/10.48550/arxiv.2002.08791)</sup> 在随机梯度 MCMC 方面，SGLD（Welling 与 Teh，2012）向 SGD 注入朗之万噪声，SGHMC（Chen、Fox 与 Guestrin，2014）加入哈密顿表述。<sup>[19](https://link.springer.com/chapter/10.1007/978-3-030-42553-1_3)</sup><sup> • </sup><sup>[20](https://doi.org/10.48550/arxiv.1402.4102)</sup> VOGN（Khan 及其同事，2018）通过在 Adam 内部进行权重扰动实现可扩展的变分推断。<sup>[21](https://doi.org/10.48550/arxiv.1806.04854)</sup>

## 应用

与高保真 HMC 后验的比较为各变体的表现提供了最清晰的定量图景。在 CIFAR-10 上，[深度集成](https://www.edgepedia.org/zh/deep-ensembles)在总变差距离上比 SGLD 或 SGHMC 更好地近似 HMC 预测分布，且比标准变分推断更接近 HMC。<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup> 在 CIFAR-10-C 分布偏移下，深度集成和 SGLD 始终比基于 HMC 的 BNN 更稳健，在高损坏强度下，甚至单个 SGD 模型也胜过 HMC 集成。<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup> 在 WILDS 基准上，对单峰近似进行集成能将 CNN 的泛化和校准大幅提升，即使所有成员都从同一个预训练检查点出发；然而在微调大型变换器时，集成没有带来收益，最后一层 Bayes by Backprop 在准确率上大幅胜出，SWAG 取得最佳校准。<sup>[22](https://proceedings.neurips.cc/paper_files/paper/2023/file/5d97b7e62022c859347397f6c1e8d0f9-Paper-Conference.pdf)</sup> 在模拟分类实验中，用 MCMC 拟合的 BNN 显著优于用变分推断拟合的 BNN，用自助法训练的网络以与深度集成相同的计算开销紧随其后，位列第二。<sup>[10](https://www.osti.gov/servlets/purl/2001808)</sup> 据报告，这些技术的应用涵盖工业用途、医疗应用、金融、欺诈检测、工程和遗传学。<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup>

## 局限与替代方案

**冷后验之争。** Wenzel 及其同事（2020）通过细致的 MCMC 采样报告称，贝叶斯后验预测产生的预测系统性地差于包括 SGD 点估计在内的更简单方法，并且将后验取 \( 1/T \) 次幂、得到温度 \( T < 1 \) 的“冷后验”后，性能改善，这会过度计算证据并偏离贝叶斯范式。<sup>[23](https://ar5iv.labs.arxiv.org/html/2002.02405)</sup> Izmailov 及其同事（2021）得出相反结论：用全批量 HMC 采样的 BNN 在温度 \( T = 1 \) 时表现强劲，不需要调温，冷后验效应在很大程度上是数据增强的伪影。<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup>

**廉价近似的病态行为。** 对于单隐层 ReLU BNN，平均场高斯变分推断和 MC dropout 可证明无法在分离良好的低不确定性区域之间实质性地提高不确定性；精确推断没有这种病态行为，因此它来自近似而非模型。<sup>[24](https://dl.acm.org/doi/10.5555/3495724.3497057)</sup> 更广泛地说，拉普拉斯和变分等局部近似只能捕捉多峰后验的单个众数，且其后验依赖于网络的参数化方式。<sup>[7](https://arxiv.org/html/2402.00809)</sup> 随机梯度 MCMC 方法从根本上是有偏的，因为它们省略了 Metropolis-Hastings 校正，数据子采样噪声会扰动平稳分布。<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup> 深度集成也有自身的告诫：对于后果重大、数据稀少的问题，其不确定性不会在远离训练数据处发散。<sup>[10](https://www.osti.gov/servlets/purl/2001808)</sup> 此外，将贝叶斯理论转化为实用实现的技术难度也限制了其采用。<sup>[3](https://link.springer.com/article/10.1007/s10462-023-10443-1)</sup>

**先验。** 权重上的高方差高斯先验能带来强劲性能，权重空间先验的细节不如架构所隐含的函数空间先验重要。<sup>[4](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)</sup> 然而标准的 \( \mathcal{N}(0, I) \) 先验对 ResNet-20 是一个糟糕的选择，因为从它抽取的典型函数对所有输入都以高概率集中在同样的少数几个类别上。<sup>[23](https://ar5iv.labs.arxiv.org/html/2002.02405)</sup> 2023年以来的工作将先验移入函数空间：FSP-Laplace（Cinquin、Pförtner、Fortuin、Hennig 与 Bamler，2024）为拉普拉斯近似在函数空间中放置可解释的[高斯过程](https://www.edgepedia.org/zh/gaussian-process)先验，解决了各向同性高斯权重空间先验随深度增长而出现的病态问题。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2024/file/19774ce2d4b0d17a3a8aea26ad99fe8a-Paper-Conference.pdf)</sup> 对于大语言模型，贝叶斯方法正与低秩适配（LoRA）以及在参数空间子空间中运行的 SG-MCMC 相结合。<sup>[7](https://arxiv.org/html/2402.00809)</sup>

## References

1. [Bayesian Learning for Neural Networks (Neal, 1996)](https://www.cs.columbia.edu/~blei/seminar/2020-representation/readings/Neal1996.pdf)
2. [Hands-on Bayesian Neural Networks – A Tutorial (Jospin et al.)](https://export.arxiv.org/pdf/2007.06823)
3. [Bayesian learning for neural networks: an algorithmic survey (Artificial Intelligence Review, Springer)](https://link.springer.com/article/10.1007/s10462-023-10443-1)
4. [What Are Bayesian Neural Network Posteriors Really Like? (ICML 2021, PMLR v139)](https://proceedings.mlr.press/v139/izmailov21a/izmailov21a.pdf)
5. [Bayesian Neural Networks: A Tutorial (Maddox, NYU CILVR)](https://wjmaddox.github.io/assets/BNN_tutorial_CILVR.pdf)
6. [Bayesian Computation in Deep Learning (survey chapter, arXiv 2025)](https://arxiv.org/pdf/2502.18300v4.pdf)
7. [Position: Bayesian Deep Learning is Needed in the Age of Large-Scale AI (arXiv, 2024)](https://arxiv.org/html/2402.00809)
8. [Uncertainty in Deep Learning (Yarin Gal, PhD thesis)](https://www.cs.ox.ac.uk/people/yarin.gal/website/thesis/thesis.pdf)
9. [Bayesian neural networks via MCMC: a Python-based tutorial (arXiv:2304.02595)](https://ar5iv.labs.arxiv.org/html/2304.02595)
10. [Evaluating the quality of uncertainty quantification enabled deep learning models (OSTI technical report)](https://www.osti.gov/servlets/purl/2001808)
11. [FSP-LAPLACE: Function-Space Priors for the Laplace Approximation in Bayesian Deep Learning (NeurIPS 2024)](https://proceedings.neurips.cc/paper_files/paper/2024/file/19774ce2d4b0d17a3a8aea26ad99fe8a-Paper-Conference.pdf)
12. [Bayesian Back-Propagation (Buntine, Complex Systems reprint)](https://content.wolfram.com/sites/13/2018/02/05-6-4.pdf)
13. [David J. C. MacKay (1992). Bayesian Interpolation. Neural Computation.](https://doi.org/10.1162/neco.1992.4.3.415)
14. [David J. C. MacKay (1992). A Practical Bayesian Framework for Backpropagation Networks. Neural Computation.](https://doi.org/10.1162/neco.1992.4.3.448)
15. [Weight Uncertainty in Neural Network (Blundell et al., ICML 2015, PMLR)](https://proceedings.mlr.press/v37/blundell15.html)
16. [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)
17. [Lakshminarayanan, Balaji, Pritzel, Alexander, Blundell, Charles (2016). Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1612.01474)
18. [Wilson, Andrew Gordon, Izmailov, Pavel (2020). Bayesian Deep Learning and a Probabilistic Perspective of Generalization. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2002.08791)
19. [Bayesian Neural Networks: An Introduction and Survey (Springer chapter)](https://link.springer.com/chapter/10.1007/978-3-030-42553-1_3)
20. [Chen, Tianqi, Fox, Emily B., Guestrin, Carlos (2014). Stochastic Gradient Hamiltonian Monte Carlo. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1402.4102)
21. [Khan, Mohammad Emtiyaz and colleagues (2018). Fast and Scalable Bayesian Deep Learning by Weight-Perturbation in Adam. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1806.04854)
22. [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)
23. [How Good is the Bayes Posterior in Deep Neural Networks Really? (Wenzel et al., ICML 2020)](https://ar5iv.labs.arxiv.org/html/2002.02405)
24. [On the expressiveness of approximate inference in Bayesian neural networks (Foong et al., NeurIPS 2019)](https://dl.acm.org/doi/10.5555/3495724.3497057)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 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-neural-network

English original: https://www.edgepedia.org/bayesian-neural-network
