Exact Inference — Variable Elimination
Answering posterior queries in a Bayesian network exactly with inference by enumeration and normalisation, then variable elimination with factors, pointwise products and summing out, the effect of elimination order on factor size, pruning irrelevant variables, and the complexity of exact inference (linear on polytrees, NP-hard in general).
The inference task
Given a Bayesian network, a query variable , evidence and the remaining hidden variables , compute the posterior
where is the normalisation constant . In practice we compute the unnormalised values for each value of and rescale them to sum to 1 — we never need separately.
Inference by enumeration
Write the joint as the product of CPT entries and sum over the hidden variables. For the alarm network:
Moving factors outside the sums where possible helps, but the depth-first evaluation still recomputes the same sub-products: is evaluated for every value of . Time is for Boolean variables (space is linear).
Variable elimination
Variable elimination (VE) evaluates the same expression right to left, storing intermediate results as factors — tables indexed by their variables.
- Create a factor for each CPT, with evidence variables fixed to their observed values (they are no longer variables of the factor).
- For each hidden variable in some order:
- take all factors that mention and form their pointwise product;
- sum out from the product, giving a new factor over the remaining variables;
- put the new factor back in the pool.
- Multiply the remaining factors (all over the query variable) and normalise.
Factor operations
Pointwise product: with . The variables are the union, so the size is exponential in the number of variables.
Summing out: — adds the entries that agree on .
Elimination order
Correctness does not depend on the order, but the cost does: it is dominated by the largest factor created. Eliminating a variable connected to others creates a factor over variables ( entries). Finding the best order is NP-hard; greedy heuristics eliminate the variable that creates the smallest factor (min-degree / min-fill).
Irrelevant variables
Every variable that is not an ancestor of a query or evidence variable is irrelevant and can be removed before inference — summing out a leaf gives . For in the alarm network, drops out.
Complexity
| Network | Exact inference cost |
|---|---|
| Polytree (singly connected: at most one undirected path between any two nodes) | linear in the total size of the CPTs |
| Multiply connected | exponential in the worst case; NP-hard in general (#P-hard) |
Hardness follows because a Bayesian network can encode 3-SAT: a query is positive iff the formula is satisfiable. For large or densely connected networks we therefore turn to approximate inference by sampling. Clustering (join-tree) algorithms generalise VE to answer all single-variable posteriors at once.
Quick revision
Practice questions
GATE-style questions: 4 one-mark and 6 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
Chain network with Boolean variables: ; , ; , .
is ______ (round to two decimals).
Chain network with Boolean variables: ; , ; , .
is ______ (round to three decimals).
Chain network with Boolean variables: ; , ; , .
The posterior is ______ (round to two decimals).
In variable elimination, "summing out" a variable from a set of factors means
The pointwise product of a factor and a factor , where all variables are Boolean, is a factor with how many entries? ______
In the alarm network (, , ), the query is . Which variables can be pruned (are irrelevant) before running variable elimination?
One or more options are correct.
Which statement about the complexity of exact inference in Bayesian networks is correct?
Variable is connected (in the factor graph) to 6 other Boolean variables, and every factor mentioning is multiplied together when is eliminated. The factor produced after summing out has how many entries? ______
Compared with inference by enumeration, variable elimination is faster mainly because it
In the alarm network with , , , , , , , , , : given that both John and Mary call, is ______ (round to two decimals).