# 联结树算法

联结树算法是一种用于概率图模型的精确推断方法，它将网络的变量重新组织为一棵由团（cluster）构成的树，然后通过团之间的消息传递来计算边缘分布。它是贝叶斯网络及相关模型中精确推断的标准引擎，也是 Hugin、BayesiaLab 和 pgmpy 等软件默认推断机制的基础。<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup><sup> • </sup><sup>[2](https://www.bayesia.com/bayesialab/user-guide/main-menu/inference/exact-inference)</sup><sup> • </sup><sup>[3](https://pgmpy.org/api/generated/inference/pgmpy.inference.BeliefPropagation.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 计算内容 | 因子化概率分布中所有变量的精确边缘分布（通过变体也可计算最大后验赋值）<sup>[4](https://arxiv.org/abs/1308.0187)</sup> |
| 核心结构 | 一棵树，其顶点为变量集合（团），满足运行交性质<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup> |
| 构建方法 | 道德化、三角化，然后在团图上构造最大权重生成树<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup><sup> • </sup><sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup> |
| 代价驱动因素 | 树宽，即最大团的规模；运行时间随其指数增长<sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup> |
| 排序问题 | 选择最优三角化排序是 NP 难的，尽管存在良好的启发式方法<sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup> |
| 起源 | Lauritzen 与 Spiegelhalter，*Journal of the Royal Statistical Society, Series B*，50(2):157–224，1988 年<sup>[7](https://researchprofiles.ku.dk/en/publications/local-computations-with-probabilities-on-graphical-structures-and/)</sup> |

## 联结树结构

联结树是一棵树（连通且无环的图），其顶点是模型变量的子集。每个顶点携带一个非负势函数 \( \psi_C(x_C) \)，即定义在该集合中变量上的函数。其定义性要求是运行交性质：只要两个团 \( C_i \) 和 \( C_j \) 共享一个变量，它们之间唯一路径上的每个团也必须包含它们的交集 \( C_i \cap C_j \)。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup> 正是这一性质使得局部消息传递能够产生全局正确的结果：相邻团之间的局部一致性蕴含整棵树上的全局一致性，因为任何出现在两个团中的变量都会出现在连接它们的路径上的每个团中。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup>

不满足该性质的、由团构成的树有时被称为团树而非联结树。例如，团 \(\{1,2\}\) 和 \(\{1,3\}\) 通过中间团 \(\{2,3\}\) 相连，就违反了该性质，因为共享变量 1 并未出现在中间顶点上。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup>

联结树的边携带分离集，即相邻团的交集。联结树表示保证联合分布可分解为团边缘分布的乘积除以分离集边缘分布的乘积，<sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup> 这一形式使得所有边缘分布的局部计算成为可能。

## 构建树

对于贝叶斯网络这样的有向模型，构建过程分三步进行。<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup>

1. **道德化。** 在每对共享子节点但彼此不相连的父节点之间添加无向边，然后去掉所有有向边。结果是道德图，一个嵌入原始分布的无向模型。<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup>
2. **三角化。** 添加填充边使图成为弦图，即每个长度大于 3 的环都有一条弦——连接环中非相邻节点的边。这产生一个可分解图，其团可以排列成联结树。<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup><sup> • </sup><sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup>
3. **成树。** 三角化图的团成为团图的节点，边以团之间交集的大小为权重，该团图的最大权重生成树即为联结树。<sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup>

每个团持有一个定义在其变量状态空间笛卡尔积上的表格，因此表格大小随团的大小指数增长。对于 \( n \) 个节点，可能的三角化数量可高达 \( n! \)，而由此产生的联结树的复杂度差异极大，这使得寻找最优三角化十分困难；实际系统使用贪心单步前瞻启发式方法，某些情况下也有近似最优方法可用。<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup> 三角化排序的选择等价于变量消元排序的选择，而寻找最优排序是 NP 难的。<sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup>

## 消息传递

一旦树构建完成且势函数初始化完毕（对于有向模型，每个变量的条件概率被分配到包含该变量及其父节点的团中），推断便通过两个阶段的消息传递进行。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup><sup> • </sup><sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup>

- **收集（向内）阶段。** 消息从叶节点向选定的根节点传递，更新顺序确保一个团只有在收到其自身子树的消息后才发送消息。
- **分发（向外）阶段。** 消息从根节点向叶节点回传，排序约束相反。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup><sup> • </sup><sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup>

每条消息通过对团的势函数在不在分离集中的变量上求和，并将结果沿边传递，使分离集与相邻团保持一致。两个阶段结束后，每对相邻势函数在其共享变量上达成一致，而根据运行交性质，这种局部一致性扩展到整棵树。校准后的团势函数恰好就是这些团上的边缘分布。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup> 实践中消息传递常以并行方式执行；如果所有势函数同时更新，它们至多在 \( d \) 步内收敛到一致解，其中 \( d \) 是树中最长路径的长度。<sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup>

该算法等价于在树上安排的变量消元，正如普通树上的信念传播等价于变量消元一样。<sup>[8](https://jmaasch.github.io/pgm/pdfs/pgm_ch_4_exact_inference.pdf)</sup>

## 计算代价

图的树宽，即其联结树中最大团的规模，决定了计算代价：树算法的运行时间随最大团的规模指数增长，因此该方法仅对有界树宽的图实用。<sup>[6](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)</sup> 在三角化被迫产生非常大团的图上，该过程需要指数时间，这就是为什么大量研究工作投入到近似推断算法中，例如循环信念传播——它在有环图上运行消息传递，但收敛性无法保证。<sup>[9](https://homepages.inf.ed.ac.uk/csutton/publications/sutton-thesis.pdf)</sup><sup> • </sup><sup>[5](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)</sup>

由于构建代价至关重要，研究工作致力于寻找更好的树。一种算法能找到接近最优的联结树，最坏情况复杂度为 \( O(c^{k} n^{a}) \)，其中 \( n \) 是顶点数，\( k \) 是最小化的最大团规模，并保证最重团状态空间的对数在最优值的常数因子范围内；当 \( k = O(\log n) \) 时，这为贝叶斯网络提供了多项式时间的推断算法。<sup>[10](https://arxiv.org/abs/1302.3558)</sup> 另外，McAuley 和 Caetano 证明，当团势函数在子团上因子化时（这在真实应用中很常见），联结树算法用于最大后验推断的期望复杂度会改善，相比经典算法有显著加速。<sup>[11](https://proceedings.mlr.press/v9/mcauley10a.html)</sup>

## 传播架构

两种经典方案组织消息传递，在时间与空间之间权衡。<sup>[4](https://arxiv.org/abs/1308.0187)</sup>

- **Shafer-Shenoy 传播**，源自哲学家与决策理论家 Glenn Shafer 和堪萨斯大学管理科学教授 Prakash P. Shenoy 于 1990 年提出的概率传播框架，从因子化势函数计算消息而不存储团势函数，空间需求仅限于因子和消息所需的空间。<sup>[12](https://www.researchwithrutgers.org/en/publications/probability-propagation/)</sup><sup> • </sup><sup>[4](https://arxiv.org/abs/1308.0187)</sup>
- **Hugin 传播**为每个团存储完整的势函数，因此其空间随联结树的宽度指数增长，但速度至少与 Shafer-Shenoy 传播相当，且当树具有大尺寸高度数顶点时显著更快。<sup>[4](https://arxiv.org/abs/1308.0187)</sup>

后来的架构将两者结合：ARCH-1 以 Shafer-Shenoy 的低空间需求达到 Hugin 的速度（至多差一个常数因子），ARCH-2 在大型高度数顶点上更快，在这些情况下带来多项式级的时间节省。<sup>[4](https://arxiv.org/abs/1308.0187)</sup>

## 历史与软件

现代表述可追溯到当时从事图模型研究的统计学家 Steffen L. Lauritzen 和当时在如今的剑桥大学任职的统计学家 David J. Spiegelhalter，他们 1988 年的论文引入了图结构上的局部计算用于专家系统，动机来自肌电图中的应用。<sup>[7](https://researchprofiles.ku.dk/en/publications/local-computations-with-probabilities-on-graphical-structures-and/)</sup> 1990 年的 Shafer-Shenoy 概率传播论文给出了一种局部计算的表述，避免了条件概率所需的除法，并推广到 Dempster-Shafer 信念函数等替代测度。<sup>[12](https://www.researchwithrutgers.org/en/publications/probability-propagation/)</sup>

该算法现已嵌入主流工具。Hugin 决策引擎在网络从编辑模式切换到运行模式时生成联结树，并通过其上的向内和向外传播进行推断。<sup>[1](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)</sup> BayesiaLab 默认构建联结树用于精确推断，在用户首次从建模模式切换到验证模式时构建；对于大型网络，构建可能耗时且占用内存，但一旦树存在，推断就很快，而对网络的任何修改都会强制重建树。<sup>[2](https://www.bayesia.com/bayesialab/user-guide/main-menu/inference/exact-inference)</sup> 在 pgmpy——一个用于概率与因果推理的 Python 库——中，`BeliefPropagation` 类为输入模型创建 `JunctionTree` 并通过信念传播进行校准，联结树是该库与变量消元并列的核心推断数据结构之一。<sup>[3](https://pgmpy.org/api/generated/inference/pgmpy.inference.BeliefPropagation.html)</sup><sup> • </sup><sup>[13](https://github.com/pgmpy/pgmpy/blob/dev/AGENTS.md)</sup> Kevin Murphy 的 Bayes Net Toolbox 是一个早期 MATLAB 库，它将联结树引擎描述为“所有精确推断算法之母”。<sup>[14](https://www.cs.ubc.ca/~murphyk/Software/BNT/usage.html)</sup>

## References

1. [Junction Tree, Hugin Development Environment manual](https://data.biotracer.hugin.com/htmlhelp/descr_jt_pane.html)
2. [Exact Inference, BayesiaLab user guide](https://www.bayesia.com/bayesialab/user-guide/main-menu/inference/exact-inference)
3. [pgmpy.inference.BeliefPropagation API documentation](https://pgmpy.org/api/generated/inference/pgmpy.inference.BeliefPropagation.html)
4. [A Time and Space Efficient Junction Tree Architecture, arXiv:1308.0187](https://arxiv.org/abs/1308.0187)
5. [Chapter 7: Junction Trees and Message Passing, Graphical Models (Evans, University of Oxford)](https://www.stats.ox.ac.uk/~evans/gms/_book/jt.html)
6. [Overview of Probabilistic Graphical Models, Cornell CS6780 lecture notes](https://www.cs.cornell.edu/courses/cs6780/2010fa/materials/OverviewPGM.pdf)
7. [Lauritzen, S. L. & Spiegelhalter, D. J. (1988). Local Computations with Probabilities on Graphical Structures and Their Application to Expert Systems. JRSS B, 50(2), 157–224](https://researchprofiles.ku.dk/en/publications/local-computations-with-probabilities-on-graphical-structures-and/)
8. [Probabilistic Graphical Models: A Concise Tutorial, Chapter 4: Exact Inference](https://jmaasch.github.io/pgm/pdfs/pgm_ch_4_exact_inference.pdf)
9. [Sutton, R. S. PhD thesis (1984), University of Massachusetts](https://homepages.inf.ed.ac.uk/csutton/publications/sutton-thesis.pdf)
10. [A Sufficiently Fast Algorithm for Finding Close to Optimal Junction Trees, arXiv:1302.3558](https://arxiv.org/abs/1302.3558)
11. [McAuley, J. & Caetano, T. (2010). Exploiting Within-Clique Factorizations in Junction-Tree Algorithms. AISTATS, PMLR 9:525–532](https://proceedings.mlr.press/v9/mcauley10a.html)
12. [Shafer, G. R. & Shenoy, P. P. (1990). Probability propagation. Annals of Mathematics and Artificial Intelligence, 2(1–4), 327–351](https://www.researchwithrutgers.org/en/publications/probability-propagation/)
13. [pgmpy AGENTS.md, repository development guide](https://github.com/pgmpy/pgmpy/blob/dev/AGENTS.md)
14. [How to use the Bayes Net Toolbox, Kevin Murphy](https://www.cs.ubc.ca/~murphyk/Software/BNT/usage.html)

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

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › Formal logic and foundations › Inference › Inference in computing and AI › Approximate and probabilistic inference in machine learning

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/junction-tree-algorithm

English original: https://www.edgepedia.org/junction-tree-algorithm
