A Bayesian network represents a joint probability distribution with a directed acyclic graph.
In the classic burglary network, burglary (B) and earthquake (E) can trigger an alarm (A), and
John (J) and Mary (M) may call after hearing it. The graph and its conditional probability
tables let you ask questions such as P(B | J): the probability of a burglary given that John called.
What the arrows encode
An arrow points from a parent variable to a child whose probability table is conditioned on
that parent. Here, the alarm table depends on burglary and earthquake, while each call table
depends on the alarm. An arrow may be given a causal interpretation when the model and data
justify it, but the mathematical role of the graph is to encode factorization and conditional
independence.
The safe rule is the local Markov property: given its parents, a node is conditionally
independent of its non-descendants. A missing arrow by itself does not prove that two arbitrary
variables are independent; the conclusion depends on the full graph and on which variables are observed.
The explaining-away effect
Select John and Mary both call. The two calls make an alarm more plausible,
which raises the posterior probability of burglary. Then add evidence that an earthquake
occurred. The burglary probability falls because the earthquake already provides an explanation
for the alarm and the calls.
Burglary and earthquake are independent before evidence in this network. After observing their
common effect, they become dependent: evidence for one cause can reduce belief in the other.
This collider pattern is called explaining away.
Exact inference and Gibbs sampling
Exact inference sums or eliminates the possible values of unobserved variables to normalize the
posterior. Enumeration is easy in this five-variable network, but its worst-case work grows
exponentially with the number and structure of variables. More efficient exact methods, such as
variable elimination or junction-tree algorithms, exploit the graph structure but can still be expensive.
Gibbs sampling approximates the posterior by repeatedly resampling one unobserved variable from
its conditional distribution given the current values of the others. More samples usually reduce
visible sampling noise, although successive samples are correlated and convergence depends on the
model. A finite sample is an estimate, not an exact answer.
What this model leaves out
Larger Bayesian networks may learn their probability tables or even parts of their structure from
data. Practical inference can use variable elimination, belief propagation, Monte Carlo methods,
or variational approximations. This applet isolates the central idea: a graph specifies how a joint
distribution factors, and evidence changes beliefs throughout that structure.
For teachers
Curriculum: Directed graphical models, conditional probability tables,
conditional independence, explaining away, and exact versus sampling-based inference.
Pre-exploration prompts:
- Does an arrow always establish causation, or can it represent a probabilistic dependency?
- If an alarm sounds, which possible causes become more likely?
- Could learning one cause make another cause less likely?
Post-exploration prompts:
- Observe John calling, then observe both calls. Why does the second call add evidence?
- Add earthquake evidence. Which posterior changes most, and why?
- Run Gibbs sampling several times at 1,000 samples, then at 50,000. Separate sampling variation from a change in the underlying model.
- Raise the burglary prior in the table. Which conclusions change because the prior changed rather than because the evidence changed?
Misconceptions to test: every arrow is causal; no edge always means
independence; sampling is exact inference performed more slowly.
贝叶斯网络用有向无环图表示联合概率分布。在经典的入室盗窃网络中,入室盗窃 B 和地震 E 都可能触发警报 A,John J 和 Mary M 听到警报后可能打电话。图结构与条件概率表可以回答 P(B | J) 之类的问题,也就是在 John 打来电话的条件下发生入室盗窃的概率。
箭头编码了什么
箭头从父变量指向子变量,子变量的概率表以父变量为条件。在本网络中,警报表取决于入室盗窃和地震,而两人的来电表都取决于警报。当模型假设与数据支持时,箭头可以被赋予因果解释;从数学上看,图的作用是编码概率分解和条件独立关系。
更准确的规则是局部马尔可夫性质:给定一个节点的父节点后,该节点与其非后代条件独立。仅仅缺少一条箭头,并不能证明任意两个变量独立;结论取决于完整图结构以及哪些变量已被观测。
解释消除效应
选择 John 和 Mary 都来电。两次来电使警报发生的可能性更高,因此入室盗窃的后验概率上升。随后再加入发生地震的证据。入室盗窃的概率会下降,因为地震已经为警报和来电提供了一个解释。
在这个网络中,入室盗窃和地震在没有证据时相互独立。观测到它们的共同结果后,两者会变得相关:支持一个原因的证据可能降低对另一个原因的信念。这种碰撞节点结构产生的现象称为解释消除。
精确推理与 Gibbs 采样
精确推理通过对未观测变量的可能取值进行求和或消元,计算并归一化后验概率。在这个五变量网络中,枚举很容易;在一般情况下,计算量会随变量数量和图结构呈指数增长。变量消元或连接树等更高效的精确方法会利用图结构,但仍可能十分昂贵。
Gibbs 采样通过反复更新一个未观测变量来近似后验分布,每次都依据其他变量当前取值下的条件分布重新采样。更多样本通常会减少可见的采样波动,不过相邻样本彼此相关,而且收敛情况取决于模型。有限样本给出的是估计值,不是精确答案。
这个模型省略了什么
更大的贝叶斯网络可能从数据中学习概率表,甚至学习部分图结构。实际推理会使用变量消元、信念传播、蒙特卡洛方法或变分近似。本工具集中呈现核心思想:图规定联合分布如何分解,而证据会沿着这一结构改变各变量的信念。
教师指导
课程目标:有向图模型、条件概率表、条件独立、解释消除,以及精确推理与采样推理的区别。
探索前问题:
- 箭头是否总能证明因果关系,还是也可以表示概率依赖?
- 警报响起时,哪些可能原因会变得更可信?
- 得知一个原因后,另一个原因是否可能变得不那么可信?
探索后问题:
- 先观测 John 来电,再观测两人都来电。第二次来电为什么增加了证据?
- 加入地震证据。哪个后验概率变化最大,为什么?
- 用 1,000 个样本多次运行 Gibbs 采样,再改为 50,000 个样本。区分采样波动与模型本身发生变化。
- 提高表中的入室盗窃先验概率。哪些结论因为先验改变而变化,而不是因为证据改变?
需要检验的误解:每条箭头都表示因果;没有边就总是独立;采样只是速度较慢的精确推理。