# 鲍姆-韦尔奇算法

**鲍姆-韦尔奇算法**（Baum–Welch algorithm）是一种期望最大化（EM）算法，用于从无标注的观测序列中估计隐马尔可夫模型（HMM）的参数，特别是转移概率和发射概率。它也被称为前向-后向算法，是HMM训练的标准算法。<sup>[1](https://web.stanford.edu/~jurafsky/slp3/A.pdf)</sup> 伦纳德·E·鲍姆（Leonard E. Baum）和泰德·皮特里（Ted Petrie）在1966年发表于《数理统计年鉴》（*The Annals of Mathematical Statistics*）的论文中为该方法奠定了统计学基础，而与鲍姆之名相关的重估程序则在此后直至1972年的工作中得到描述。<sup>[2](https://cir.nii.ac.jp/crid/1363951794262055808)</sup><sup> • </sup><sup>[1](https://web.stanford.edu/~jurafsky/slp3/A.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 估计对象 | 从无标注观测序列中估计HMM的转移概率A和发射概率B（以及初始状态分布）。<sup>[1](https://web.stanford.edu/~jurafsky/slp3/A.pdf)</sup> |
| 算法类别 | 期望最大化（EM）算法的一个特例（登普斯特等，1977）。<sup>[1](https://web.stanford.edu/~jurafsky/slp3/A.pdf)</sup> |
| 核心计算 | 前向算法和后向算法计算后验状态概率；由这些后验概率得到的期望转移计数和期望发射计数被用于重新估计参数。<sup>[3](https://www.stat.cmu.edu/~cshalizi/dst/18/lectures/24/lecture-24.html)</sup><sup> • </sup><sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup> |
| 收敛保证 | 对数似然在迭代之间不下降；它可能保持不变，因此算法收敛到似然的一个驻点，而不一定是局部最大值或全局最大值。<sup>[3](https://www.stat.cmu.edu/~cshalizi/dst/18/lectures/24/lecture-24.html)</sup><sup> • </sup><sup>[16](https://ocw.mit.edu/courses/6-438-algorithms-for-inference-fall-2014/7b1e302a77ea08f830f9adb9920ade43_MIT6_438F14_Lec22.pdf)</sup> |
| 主要缺点 | 容易陷入局部最优；与拟牛顿直接最大化相比，收敛速度通常较慢。<sup>[5](https://jmlr.csail.mit.edu/beta/papers/v18/16-093.html)</sup><sup> • </sup><sup>[6](https://arxiv.org/abs/2409.02477)</sup> |
| 主要应用 | 语音识别、计算生物学、计算机视觉和计量经济学。<sup>[5](https://jmlr.csail.mit.edu/beta/papers/v18/16-093.html)</sup> |

## 所解决的问题

隐马尔可夫模型假设观测序列由一个不可观测的马尔可夫过程生成：隐藏状态按照转移概率演化，每个状态按照发射分布产生观测。如果状态序列已知，参数可以通过简单计数来估计，正如在全可见马尔可夫模型中那样。由于状态是隐藏的，目前没有已知的方法可以通过解析求解来找到使观测序列概率最大化的模型。<sup>[1](https://web.stanford.edu/~jurafsky/slp3/A.pdf)</sup><sup> • </sup><sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup>

鲍姆-韦尔奇算法通过迭代重估来解决这一问题。从参数的初始猜测出发，它计算一个更好的估计，然后重复，迭代地改进其所学到的概率。<sup>[1](https://web.stanford.edu/~jurafsky/slp3/A.pdf)</sup> 在EM框架下，观测数据是序列，隐藏数据是生成这些序列的状态路径，参数是发射概率和转移概率。<sup>[7](https://pages.cs.wisc.edu/~matthewb/pages/notes/pdf/hmms/BaumWelch.pdf)</sup>

## 算法的工作原理

**E步。** 对于每个训练序列，算法运行前向递归和后向递归。前向变量 \( \alpha_i(t) \) 是截至时间t的观测前缀与时间t处于状态 \( S_i \) 的联合概率；后向变量 \( \beta_i(t) \) 是在时间t处于状态 \( S_i \) 的条件下，时间t之后的部分观测序列的概率。<sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup> 由这两个量，算法计算每个时刻占据每个状态的后验概率 \( \gamma_i(t) = \alpha_i(t)\beta_i(t)/P(O\mid\lambda) \)，以及采取每条转移的后验概率 \( \xi_{ij}(t) = \alpha_i(t)\,a_{ij}\,b_j(O_{t+1})\,\beta_j(t+1)/P(O\mid\lambda) \)。<sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup><sup> • </sup><sup>[7](https://pages.cs.wisc.edu/~matthewb/pages/notes/pdf/hmms/BaumWelch.pdf)</sup> 对时间求和，\( \gamma_i(t) \) 给出访问状态 \( S_i \) 的期望次数，\( \xi_{ij}(t) \) 给出从 \( S_i \) 转移到 \( S_j \) 的期望次数。<sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup>

**M步。** 期望计数成为参数的加权最大似然重估值：每条转移概率被重估为该转移的期望使用次数除以其源状态的期望离开次数，每个发射概率被重估为该符号从某状态发射的期望次数除以访问该状态的期望次数。<sup>[3](https://www.stat.cmu.edu/~cshalizi/dst/18/lectures/24/lecture-24.html)</sup><sup> • </sup><sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup> 对于连续观测模型，同一框架重估状态均值和协方差；例如，对角协方差高斯HMM由其初始状态概率 \( \pi_i \)、转移概率 \( a_{ij} \)、各状态均值 \( \mu_{di} \) 和各状态协方差矩阵 \( \Sigma_i \) 定义。<sup>[8](https://courses.grainger.illinois.edu/ece417/fa2018/ece417fa2018lecture13.html)</sup>

两步交替进行直至收敛。E步使用当前参数计算后验边缘分布，M步更新参数，并且由于鲍姆-韦尔奇算法的似然在迭代之间不下降，模型序列沿着似然曲面攀升。<sup>[3](https://www.stat.cmu.edu/~cshalizi/dst/18/lectures/24/lecture-24.html)</sup><sup> • </sup><sup>[16](https://ocw.mit.edu/courses/6-438-algorithms-for-inference-fall-2014/7b1e302a77ea08f830f9adb9920ade43_MIT6_438F14_Lec22.pdf)</sup>

## 收敛性质

鲍姆及其同事证明了一个构成整个程序基础的重估性质：如果当前模型为 \( \lambda = (A, B, \pi) \)，重估公式产生 \( \bar{\lambda} \)，那么要么 \( \bar{\lambda} = \lambda \)，意味着当前模型是似然的一个临界点，要么 \( P(O\mid\bar{\lambda}) > P(O\mid\lambda) \)，意味着新模型更有可能。因此迭代产生一个最大似然估计，但只是局部的，而且似然曲面可能非常复杂。<sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup>

这种局部最优行为是众所周知的，并促使了随机重启等实际对策：由于EM训练只是局部最优的，从不同的随机初始化重启可以用来避免糟糕的局部解。<sup>[5](https://jmlr.csail.mit.edu/beta/papers/v18/16-093.html)</sup><sup> • </sup><sup>[9](https://github.com/google-research/opengrm/blob/main/opengrm/baumwelch/README.md)</sup> 2017年发表于《机器学习研究杂志》（*Journal of Machine Learning Research*）的一项分析刻画了总体似然任意全局最优周围的吸引域，并提供了其作者所描述的、在似然非凸的情形下鲍姆-韦尔奇算法收敛到全局最优的首个严格局部收敛保证。<sup>[5](https://jmlr.csail.mit.edu/beta/papers/v18/16-093.html)</sup>

收敛速度与收敛保证是两回事。鲍姆-韦尔奇算法的收敛速度通常较慢，而使用L-BFGS-B等拟牛顿方法对似然进行直接最大化可以收敛得更快，不过由于参数边界的缘故，这类方法实现起来更为复杂。QNEM等混合方案根据似然的凸性在鲍姆-韦尔奇更新和拟牛顿更新之间切换。<sup>[6](https://arxiv.org/abs/2409.02477)</sup>

## 变体与替代方案

**维特比训练。** 维特比训练（也称分段k均值）不在E步中对所有状态序列求和，而只使用单一最可能的状态序列。在实践中，鲍姆-韦尔奇训练比维特比训练稍慢，但更为精确。<sup>[9](https://github.com/google-research/opengrm/blob/main/opengrm/baumwelch/README.md)</sup> 维特比训练已与鲍姆-韦尔奇算法一起用于基于HMM的基因查找器，如GeneMarkS和EasyGene。<sup>[10](https://pmc.ncbi.nlm.nih.gov/articles/PMC1298918/)</sup>

**内存高效训练。** 经典实现为每个时间步存储前向值和后向值，这对长序列来说代价高昂。一种线性内存的鲍姆-韦尔奇训练算法对于具有M个状态、T个自由转移参数和E个自由发射参数、输入序列长度为L的模型，每次迭代需要 \( O(M) \) 内存和 \( O(L\,M\,T_{\max}(T+E)) \) 时间，其中 \( T_{\max} \) 是任何状态连接到的最大状态数；此前内存效率最高的检查点方法需要 \( O(\log(L)\,M) \) 内存。<sup>[11](https://arxiv.org/abs/cs/0505028)</sup>

**推广。** 鲍姆-韦尔奇框架已被扩展，例如扩展为通过多序列比对纳入序列间相似性信息的广义算法，以及配合轮廓HMM用于转座子识别的条件变体。<sup>[12](https://pmc.ncbi.nlm.nih.gov/articles/PMC3869655/)</sup><sup> • </sup><sup>[13](https://pmc.ncbi.nlm.nih.gov/articles/PMC2822524/)</sup>

## 应用

HMM在统计学文献中被描述为离散时间序列建模的主要支柱之一，应用包括语音识别、计算生物学、计算机视觉和计量经济学，而鲍姆-韦尔奇算法是从观测中估计此类模型的标准途径。<sup>[5](https://jmlr.csail.mit.edu/beta/papers/v18/16-093.html)</sup> 在语音识别中，劳伦斯·拉比纳（Lawrence Rabiner）1989年广为使用的教程为该领域确立了HMM参数的鲍姆-韦尔奇重估方法，该教程将前向-后向程序、维特比算法和重估公式一并呈现。<sup>[4](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)</sup> 在基因组学中，通过鲍姆-韦尔奇或维特比训练进行的HMM参数估计是基因查找系统的基础，而用于序列家族搜索和比对的轮廓HMM则依赖于该算法在计算上可行的最大似然训练。<sup>[10](https://pmc.ncbi.nlm.nih.gov/articles/PMC1298918/)</sup><sup> • </sup><sup>[13](https://pmc.ncbi.nlm.nih.gov/articles/PMC2822524/)</sup>

## 软件

开源实现直接暴露了该算法。Python包hmmlearn运行鲍姆-韦尔奇EM来估计转移概率、发射概率和起始概率，迭代次数由 `n_iter` 参数限制，当对数似然的增益低于阈值 `tol` 时宣布收敛；`monitor_` 属性记录收敛历史。<sup>[14](https://hmmlearn.readthedocs.io/en/stable/api.html)</sup><sup> • </sup><sup>[15](https://hmmlearn.readthedocs.io/en/latest/tutorial.html)</sup> 谷歌研究院的opengrm库在有限状态转换器上实现鲍姆-韦尔奇训练，其中半环的选择决定了E步是对所有状态序列求和（真正的鲍姆-韦尔奇）还是仅取最可能的一个（维特比训练）。<sup>[9](https://github.com/google-research/opengrm/blob/main/opengrm/baumwelch/README.md)</sup>

## References

1. [Dan Jurafsky and James H. Martin. Speech and Language Processing, Appendix A: HMM training, the forward-backward algorithm.](https://web.stanford.edu/~jurafsky/slp3/A.pdf)
2. [Baum, L. E., and Petrie, T. (1966). Statistical Inference for Probabilistic Functions of Finite State Markov Chains. The Annals of Mathematical Statistics 37(6):1554–1563.](https://cir.nii.ac.jp/crid/1363951794262055808)
3. [Cosma Shalizi. Hidden Markov Models and State Estimation, lecture notes, Carnegie Mellon University.](https://www.stat.cmu.edu/~cshalizi/dst/18/lectures/24/lecture-24.html)
4. [Lawrence R. Rabiner (1989). A Tutorial on Hidden Markov Models and Selected Applications in Speech Recognition (lecture slides transcription).](https://www2.cs.uh.edu/~rmverma/NLP/hmm.pdf)
5. [Statistical and Computational Guarantees for the Baum-Welch Algorithm. Journal of Machine Learning Research 18 (2017).](https://jmlr.csail.mit.edu/beta/papers/v18/16-093.html)
6. [Parameter estimation of hidden Markov models: comparison of EM and quasi-Newton methods with a new hybrid algorithm. arXiv:2409.02477.](https://arxiv.org/abs/2409.02477)
7. [Matthew B. (2014). The Baum-Welch Algorithm, University of Wisconsin lecture notes.](https://pages.cs.wisc.edu/~matthewb/pages/notes/pdf/hmms/BaumWelch.pdf)
8. [Mark Hasegawa-Johnson (2018). ECE 417 Lecture 13: Baum-Welch/Expectation-Maximization for Training HMMs, University of Illinois.](https://courses.grainger.illinois.edu/ece417/fa2018/ece417fa2018lecture13.html)
9. [opengrm baumwelch README, Google Research.](https://github.com/google-research/opengrm/blob/main/opengrm/baumwelch/README.md)
10. [Gene identification in novel eukaryotic genomes by self-training algorithm. PMC.](https://pmc.ncbi.nlm.nih.gov/articles/PMC1298918/)
11. [A linear memory algorithm for Baum-Welch training. arXiv:cs/0505028.](https://arxiv.org/abs/cs/0505028)
12. [Generalized Baum-Welch Algorithm Based on the Similarity between Sequences. PMC.](https://pmc.ncbi.nlm.nih.gov/articles/PMC3869655/)
13. [Transposon identification using profile HMMs. PMC.](https://pmc.ncbi.nlm.nih.gov/articles/PMC2822524/)
14. [hmmlearn 0.3.3 API Reference.](https://hmmlearn.readthedocs.io/en/stable/api.html)
15. [hmmlearn Tutorial.](https://hmmlearn.readthedocs.io/en/latest/tutorial.html)
16. [ocw.mit.edu](https://ocw.mit.edu/courses/6-438-algorithms-for-inference-fall-2014/7b1e302a77ea08f830f9adb9920ade43_MIT6_438F14_Lec22.pdf)

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

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Stochastic processes › Markov chains and processes › Discrete-time Markov chains › Discrete-time Markov chains: fundamentals and examples

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/baum-welch-algorithm

English original: https://www.edgepedia.org/baum-welch-algorithm
