Inference in Bayesian Networks
Prerequisites
🎯 Learning Objectives
- Perform inference by enumeration in a Bayesian network
- Understand and apply variable elimination
- Compute posterior probabilities step by step
- Appreciate the computational complexity of exact inference
1. Types of Inference
- Posterior probability: P(Query | Evidence) — the most common task
- Most probable explanation (MPE): argmaxx P(X = x | e)
- Maximum a posteriori (MAP): Most probable assignment to a subset of variables
2. Inference by Enumeration
Algorithm: Enumeration
- Express the query P(Q | e) = α · P(Q, e) where α is the normalizing constant
- Expand P(Q, e) using the BN factorization
- Sum out all hidden variables (variables that are neither query nor evidence)
- Normalize to obtain proper probabilities
Example — Alarm Network GATE Style
Given: B → A, E → A, A → J, A → M. Compute P(B | j, m).
Step 1: P(B | j, m) = α P(B, j, m) = α ∑e∑a P(B)P(e)P(a|B,e)P(j|a)P(m|a)
Step 2: Factor and push sums inward:
= α P(B) ∑e P(e) ∑a P(a|B,e) P(j|a) P(m|a)
Step 3: Compute the innermost sum for each combination of B, e values. Then sum over e. Finally normalize over B.
With specific CPT values: P(B=T | j, m) ≈ 0.284
Exponential Complexity
Naive enumeration is O(n · 2n) for n binary variables. This is impractical for large networks.
3. Variable Elimination
Key Idea
Variable elimination avoids redundant computation by eliminating (summing out) variables one at a time, storing intermediate results as factors.
Variable Elimination Algorithm
- Represent each CPT as a factor (a table over its variables)
- Set evidence variables to their observed values
- Choose an elimination ordering for hidden variables
- For each hidden variable Z in order:
- Collect all factors that mention Z
- Multiply them into a single factor
- Sum out Z to produce a new factor
- Multiply remaining factors and normalize
Step-by-Step Variable Elimination
Computing P(B | j, m) in the alarm network:
Initial factors: f1(B), f2(E), f3(A,B,E), f4(J=t,A), f5(M=t,A)
Eliminate E: Collect f2(E) and f3(A,B,E). Product: f6(A,B,E). Sum out E: f7(A,B) = ∑E f6.
Eliminate A: Collect f7(A,B), f4(A), f5(A). Product: f8(A,B). Sum out A: f9(B) = ∑A f8.
Final: Multiply f1(B) × f9(B), normalize. Done!
Elimination Ordering Matters
The order in which hidden variables are eliminated affects the size of intermediate factors and hence the complexity. Finding the optimal ordering is itself NP-hard, but good heuristics (min-fill, min-degree) exist.
4. Complexity of Exact Inference
Complexity Result
Exact inference in Bayesian networks is #P-hard in general. For networks with bounded treewidth w, variable elimination runs in O(n · dw+1) where d is the domain size.
- Polytrees (singly connected BNs): Exact inference is linear-time
- Multiply connected BNs: Exact inference is #P-hard — motivates approximate methods
Summary
- Enumeration: sum out all hidden variables using the BN factorization
- Variable elimination: eliminate one variable at a time with intermediate factors
- VE avoids redundant computation; ordering affects efficiency
- Exact inference is #P-hard in general but tractable for polytrees