# 摊销推断

摊销推断是一种机器学习方法：模型只需训练一次即可执行统计推断，从而对新数据的后验估计通过单次前向传播产生，而不必为每个数据集重新运行MCMC或变分推断之类的优化过程。<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup> 在基于模拟的推断（SBI）中，训练好的网络为似然难以处理的模拟器近似后验、似然或似然比，模拟与训练的成本只支付一次，并在其后所有观测中重复使用。<sup>[2](https://doi.org/10.48550/arxiv.2305.17161)</sup> 该术语源于认知科学中的概率推理，塞缪尔·J·格什曼与诺亚·D·古德曼曾描述如何复用过去费力的推断以做出快速决策，如今它指代一类用于[贝叶斯推断](https://www.edgepedia.org/zh/bayesian-inference)的神经方法。<sup>[3](https://gershmanlab.com/pubs/GershmanGoodman14.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 产出什么 | 一个训练好的条件密度估计器，对任何新观测返回后验估计，无需重新训练或进一步模拟<sup>[2](https://doi.org/10.48550/arxiv.2305.17161)</sup> |
| 查询时速度 | NPE后验样本通常通过单次前向传播在毫秒级生成；一次基准MCMC运行生成24,000个样本约需一分钟<sup>[4](https://arxiv.org/html/2508.12939)</sup><sup> • </sup><sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup> |
| 训练损失（NPE） | 在模拟数据对上 \( \mathcal{L}_{\text{NPE}} = -\mathbb{E}_{p(\theta)p(x|\theta)} \log q(\theta|x) \) <sup>[2](https://doi.org/10.48550/arxiv.2305.17161)</sup> |
| 主要变体 | NPE（后验）、NLE（似然，推断时需MCMC）、NRE（基于分类器的似然比）<sup>[4](https://arxiv.org/html/2508.12939)</sup> |
| 模拟成本 | 摊销方法比序贯方法需要更大的模拟预算；在基准任务上Simformer所需模拟次数约为NPE的十分之一<sup>[5](https://export.arxiv.org/pdf/2302.09125v3.pdf)</sup><sup> • </sup><sup>[6](https://proceedings.mlr.press/v235/gloeckler24a.html)</sup> |
| 校准指标 | 期望覆盖率，是条件覆盖率的必要但非充分条件<sup>[7](https://arxiv.org/html/2305.14275v3)</sup> |
| 主要失效模式 | 摊销差距、校准失准、模型设定错误<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup><sup> • </sup><sup>[7](https://arxiv.org/html/2305.14275v3)</sup> |

## 工作原理

该方法在从先验和模拟器抽取的模拟数据对 \( (\theta, x) \) 上训练一个条件密度估计器 \( q_{\phi}(\theta|x) \)。神经SBI最小化负对数似然损失

\[ \mathcal{L}(\phi) = \mathbb{E}_{(\theta, x) \sim p(\theta, x)} \left[ -\log q_{\phi}(\theta|x) \right], \]

从而使网络学会将数据映射到生成这些数据的后验分布。<sup>[4](https://arxiv.org/html/2508.12939)</sup> 由于期望是在 \( p(\theta)p(x|\theta) \) 下取的，因此无需评估似然，只需模拟。训练完成后，对每个新观测的推断直接使用 \( q(\theta|x) \)，将模拟与训练的计算成本摊销到所有观测上。<sup>[2](https://doi.org/10.48550/arxiv.2305.17161)</sup>

三种主要目标在估计对象上有所不同。NPE直接近似后验。NLE训练似然 \( p(x|\theta) \) 的条件生成模型，然后在推断时需要MCMC或变分推断，在200次试验下生成1,000个后验样本通常需要数分钟。NRE通过训练分类器区分联合样本 \( p(x,\theta) \) 与边缘样本 \( p(x)p(\theta) \) 来学习似然比 \( p(x|\theta)/p(x) \)，其计算成本可能低于生成模型。<sup>[4](https://arxiv.org/html/2508.12939)</sup>

查询时的速度优势很大。在一项基准测试中，单次MCMC运行生成24,000个样本（抽稀至1,000个）约需一分钟计算时间，而神经方法每次近似后验推断仅需几十毫秒。<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup>

## 操作流程

实践者定义模拟器和先验，生成模拟数据，训练估计器，在摊销模式与序贯模式之间选择，验证校准，并将网络应用于观测数据。摊销方法返回适用于许多观测的后验而无需重新训练，序贯方法则将推断集中于某一特定观测以提高模拟效率；sbi文档建议当需要对约10个以上观测进行推断时使用摊销方法。<sup>[8](https://sbi.readthedocs.io/en/latest/how_to_guide/06_choosing_inference_method.html)</sup>

校准通过期望覆盖率检查，这是评估摊销推断算法校准最常用的指标；它是条件覆盖率的必要但非充分条件。<sup>[7](https://arxiv.org/html/2305.14275v3)</sup> 一项关于无似然推断算法的元研究强调，缺乏此类校准限制了得出下游科学结论的能力。<sup>[7](https://arxiv.org/html/2305.14275v3)</sup>

## 起源

该术语由塞缪尔·J·格什曼与诺亚·D·古德曼在《概率推理中的摊销推断》一文中提出，该文于2014年发表在eScholarship上，将过去推断的复用置于人类概率推理的框架中。<sup>[3](https://gershmanlab.com/pubs/GershmanGoodman14.pdf)</sup> 神经SBI框架可追溯至帕帕马卡里奥斯与默里（2016），他们提出用贝叶斯神经网络通过[条件密度估计](https://www.edgepedia.org/zh/conditional-density-estimation)学习对精确后验的参数化近似，而非像传统ABC那样返回 \( \epsilon \)-近似的样本；其方法利用初步后验拟合来引导后续模拟，将所需模拟次数减少了几个数量级。<sup>[9](https://doi.org/10.48550/arxiv.1605.06376)</sup> 格林伯格、农嫩马赫与马克（2019）提出了使用归一化流（将简单分布变换为复杂分布的神经网络）的NPE，命名为自动后验变换，这是sbi包中的默认方法。<sup>[10](https://doi.org/10.48550/arxiv.1905.07488)</sup><sup> • </sup><sup>[11](https://sbi.readthedocs.io/en/latest/tutorials/16_implemented_methods.html)</sup> 该领域所依托的早期工作包括近似贝叶斯计算，由博蒙特、张与鲍尔丁于2002年为群体遗传学形式化。<sup>[12](https://doi.org/10.1093/genetics/162.4.2025)</sup>

## 变体

NPE直接以后验为目标，NLE以似然为目标然后需要MCMC或变分推断来抽取后验样本，NRE以基于分类器的似然比为目标，sbi默认使用修改后的损失函数。<sup>[11](https://sbi.readthedocs.io/en/latest/tutorials/16_implemented_methods.html)</sup> 所有SNPE方法在第一轮使用相同的损失函数，因此NPE等价于单轮SNPE。<sup>[11](https://sbi.readthedocs.io/en/latest/tutorials/16_implemented_methods.html)</sup>

[归一化流](https://www.edgepedia.org/zh/normalizing-flow)之外的生成骨干网络如今支撑着该领域。[流匹配](https://www.edgepedia.org/zh/flow-matching)后验估计（FMPE）由达克斯及其同事于2023年报告，通过流匹配目标学习条件向量场，

\[ \mathcal{L}_{\text{FMPE}} = \mathbb{E} \left\| v_{t,x}(\theta_{t}) - u_{t}(\theta_{t}|\theta_{1}) \right\|^{2}, \]

取代NPE的对数似然目标，同时保留 \( q(\theta|x) \) 的精确密度评估，作者指出这对他们的物理学应用至关重要。<sup>[2](https://doi.org/10.48550/arxiv.2305.17161)</sup> 2024年，格勒克勒及其同事引入了Simformer，一种用于摊销贝叶斯推断的扩散变换器方法，在基准任务上优于最先进的摊销方法，能处理函数值参数以及缺失或非结构化数据，并可采样联合参数-数据分布的任意条件分布，包括后验和似然。<sup>[6](https://proceedings.mlr.press/v235/gloeckler24a.html)</sup> 用于NPE的条件扩散模型训练比归一化流更快，推断时间略有增加。<sup>[13](https://raw.githubusercontent.com/mlresearch/v258/main/assets/chen25d/chen25d.pdf)</sup>

两个开源平台主导着实践。基于PyTorch构建的sbi Python包实现了以后验、似然或似然-证据比为估计目标的摊销与序贯方法。<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup> 基于[TensorFlow](https://www.edgepedia.org/zh/tensorflow)构建并支持GPU和TPU加速的BayesFlow支持摊销贝叶斯工作流，并包含模型设定错误检测，以在模拟不能完美代表现实时帮助保持后验的忠实性。<sup>[14](https://doi.org/10.21105/joss.05702)</sup> swyft包实现了用于物理科学的截断边缘神经比率估计。<sup>[15](https://doi.org/10.21105/joss.04205)</sup>

## 应用

已发表的应用涵盖神经科学（离子通道电导、可塑性、全脑动力学）、认知科学（知觉决策）、生物学、社会科学，以及包括引力波、宇宙学和系外行星在内的物理学。<sup>[4](https://arxiv.org/html/2508.12939)</sup> 仅BayesFlow就已被应用于流行病学、认知建模、计算精神病学、神经科学、粒子物理学、计量经济学、地震成像、航空航天和风力涡轮机设计。<sup>[14](https://doi.org/10.21105/joss.05702)</sup> Simformer在生态学、流行病学和神经科学的模拟器上进行了展示。<sup>[6](https://proceedings.mlr.press/v235/gloeckler24a.html)</sup>

## 局限与替代方案

摊销差距是指使训练好的估计器相对于KL最优贝叶斯估计器次优的额外偏差或方差。<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup> 在一项基准测试中，所有神经方法总体上略逊于MCMC，原因在于摊销差距、使用了不够灵活的后验近似，或两者兼有。<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup> 变分自编码器中的相关工作形式化定义了用摊销分布评估的ELBO与最优逐数据集变分分布之间的差距。<sup>[16](https://ar5iv.labs.arxiv.org/html/1801.03558)</sup>

校准失准是一种有记录的失效模式：摊销变分近似尽管经过大量补救工作，仍无法达到期望覆盖率。<sup>[7](https://arxiv.org/html/2305.14275v3)</sup> 模型设定错误——即模拟不能代表现实——威胁后验的有效性，BayesFlow内置了检测方法。<sup>[14](https://doi.org/10.21105/joss.05702)</sup> 模拟成本方面则相反：摊销推断比序贯推断需要大得多的模拟预算，以补偿其更大的预测任务。<sup>[5](https://export.arxiv.org/pdf/2302.09125v3.pdf)</sup> 架构改进降低了这一成本：在基准任务和观测上平均而言，Simformer所需模拟次数约为NPE的十分之一。<sup>[6](https://proceedings.mlr.press/v235/gloeckler24a.html)</sup> 序贯（多轮）方法以摊销换取模拟效率，但所得后验仅对特定观测 \( x_o \) 准确，而非对任意 \( x \)。<sup>[8](https://sbi.readthedocs.io/en/latest/how_to_guide/06_choosing_inference_method.html)</sup> 与MCMC相比，摊销方法在每个数据集上快几个数量级，但在基准测试中略欠准确；与传统ABC相比，它们避免了 \( \epsilon \)-近似并返回密度而非样本。<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)</sup><sup> • </sup><sup>[9](https://doi.org/10.48550/arxiv.1605.06376)</sup>

## References

1. [Neural Methods for Amortized Inference](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-112723-034123)
2. [Dax, Maximilian and colleagues (2023). Flow Matching for Scalable Simulation-Based Inference. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2305.17161)
3. [Amortized Inference in Probabilistic Reasoning (Gershman & Goodman, 2014)](https://gershmanlab.com/pubs/GershmanGoodman14.pdf)
4. [Simulation-Based Inference: A Practical Guide](https://arxiv.org/html/2508.12939)
5. [JANA (arXiv 2302.09125v3)](https://export.arxiv.org/pdf/2302.09125v3.pdf)
6. [All-in-one simulation-based inference (Simformer)](https://proceedings.mlr.press/v235/gloeckler24a.html)
7. [Variational Inference with Coverage Guarantees in Simulation-Based Inference](https://arxiv.org/html/2305.14275v3)
8. [Choosing an inference method, sbi documentation](https://sbi.readthedocs.io/en/latest/how_to_guide/06_choosing_inference_method.html)
9. [Papamakarios, George, Murray, Iain (2016). Fast $ε$-free Inference of Simulation Models with Bayesian Conditional Density Estimation. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1605.06376)
10. [Greenberg, David S., Nonnenmacher, Marcel, Macke, Jakob H. (2019). Automatic Posterior Transformation for Likelihood-Free Inference. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1905.07488)
11. [Implemented methods, sbi documentation](https://sbi.readthedocs.io/en/latest/tutorials/16_implemented_methods.html)
12. [Mark A Beaumont, Wenyang Zhang, David J Balding (2002). Approximate Bayesian Computation in Population Genetics. Genetics.](https://doi.org/10.1093/genetics/162.4.2025)
13. [Conditional diffusions for amortized neural posterior estimation](https://raw.githubusercontent.com/mlresearch/v258/main/assets/chen25d/chen25d.pdf)
14. [Stefan T. Radev and colleagues (2023). BayesFlow: Amortized Bayesian Workflows With Neural Networks. The Journal of Open Source Software.](https://doi.org/10.21105/joss.05702)
15. [Benjamin Kurt Miller and colleagues (2022). swyft: Truncated Marginal Neural Ratio Estimation in Python. The Journal of Open Source Software.](https://doi.org/10.21105/joss.04205)
16. [Inference Suboptimality in Variational Autoencoders](https://ar5iv.labs.arxiv.org/html/1801.03558)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/amortized-inference

English original: https://www.edgepedia.org/amortized-inference
