∑GATE DA Atlas

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).

Section 710 practice questions

The inference task

Given a Bayesian network, a query variable XX, evidence E=e\mathbf E = \mathbf e and the remaining hidden variables Y\mathbf Y, compute the posterior

P(X∣e)=α P(X,e)=α∑yP(X,e,y),P(X\mid\mathbf e) = \alpha\,P(X, \mathbf e) = \alpha\sum_{\mathbf y}P(X, \mathbf e, \mathbf y),

where α\alpha is the normalisation constant 1/P(e)1/P(\mathbf e). In practice we compute the unnormalised values for each value of XX and rescale them to sum to 1 — we never need P(e)P(\mathbf e) separately.

Inference by enumeration

Write the joint as the product of CPT entries and sum over the hidden variables. For the alarm network:

P(B∣j,m)=α P(B)∑eP(e)∑aP(a∣B,e) P(j∣a) P(m∣a).P(B\mid j, m) = \alpha\,P(B)\sum_e P(e)\sum_a P(a\mid B, e)\,P(j\mid a)\,P(m\mid a).

Moving factors outside the sums where possible helps, but the depth-first evaluation still recomputes the same sub-products: P(j∣a)P(m∣a)P(j\mid a)P(m\mid a) is evaluated for every value of ee. Time is O(n 2n)O(n\,2^n) for nn 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.

  1. Create a factor for each CPT, with evidence variables fixed to their observed values (they are no longer variables of the factor).
  2. For each hidden variable HH in some order:
    • take all factors that mention HH and form their pointwise product;
    • sum out HH from the product, giving a new factor over the remaining variables;
    • put the new factor back in the pool.
  3. Multiply the remaining factors (all over the query variable) and normalise.

Factor operations

Pointwise product: f1(A,B)×f2(B,C)=f(A,B,C)f_1(A, B) \times f_2(B, C) = f(A, B, C) with f(a,b,c)=f1(a,b) f2(b,c)f(a, b, c) = f_1(a, b)\,f_2(b, c). The variables are the union, so the size is exponential in the number of variables.

Summing out: f′(B,C)=∑af(a,B,C)f'(B, C) = \sum_a f(a, B, C) — adds the entries that agree on B,CB, C.

P(A) · P(B|A)factors over A, B f₁(B) = Σₐ …B: .31 / ¬B: .69 f₂(C) = Σ_b f₁ P(C|b)C: .324 / ¬C: .676 eliminate A, then B: every factor stays over ≤ 2 variables enumeration would instead sum 4 full products for each value of C
Variable elimination on the chain A → B → C (numbers from the practice questions).

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 kk others creates a factor over kk variables (2k2^k 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 ∑xP(x∣parents)=1\sum_x P(x\mid\text{parents}) = 1. For P(J∣b)P(J\mid b) in the alarm network, MM drops out.

Complexity

NetworkExact inference cost
Polytree (singly connected: at most one undirected path between any two nodes)linear in the total size of the CPTs
Multiply connectedexponential 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.

Q1NAT1 mark

Chain network A→B→CA \to B \to C with Boolean variables: P(A)=0.3P(A) = 0.3; P(B∣A)=0.8P(B\mid A) = 0.8, P(B∣¬A)=0.1P(B\mid\neg A) = 0.1; P(C∣B)=0.6P(C\mid B) = 0.6, P(C∣¬B)=0.2P(C\mid\neg B) = 0.2.

P(B)P(B) is ______ (round to two decimals).

Q2NAT2 marks

Chain network A→B→CA \to B \to C with Boolean variables: P(A)=0.3P(A) = 0.3; P(B∣A)=0.8P(B\mid A) = 0.8, P(B∣¬A)=0.1P(B\mid\neg A) = 0.1; P(C∣B)=0.6P(C\mid B) = 0.6, P(C∣¬B)=0.2P(C\mid\neg B) = 0.2.

P(C)P(C) is ______ (round to three decimals).

Q3NAT2 marks

Chain network A→B→CA \to B \to C with Boolean variables: P(A)=0.3P(A) = 0.3; P(B∣A)=0.8P(B\mid A) = 0.8, P(B∣¬A)=0.1P(B\mid\neg A) = 0.1; P(C∣B)=0.6P(C\mid B) = 0.6, P(C∣¬B)=0.2P(C\mid\neg B) = 0.2.

The posterior P(A∣C)P(A\mid C) is ______ (round to two decimals).

Q4MCQ1 mark

In variable elimination, "summing out" a variable XX from a set of factors means

Q5NAT1 mark

The pointwise product of a factor f1(A,B)f_1(A, B) and a factor f2(B,C)f_2(B, C), where all variables are Boolean, is a factor with how many entries? ______

Q6MSQ2 marks

In the alarm network (B→A←EB \to A \leftarrow E, A→JA \to J, A→MA \to M), the query is P(J∣B=true)P(J\mid B = \text{true}). Which variables can be pruned (are irrelevant) before running variable elimination?

One or more options are correct.

Q7MCQ2 marks

Which statement about the complexity of exact inference in Bayesian networks is correct?

Q8NAT2 marks

Variable XX is connected (in the factor graph) to 6 other Boolean variables, and every factor mentioning XX is multiplied together when XX is eliminated. The factor produced after summing out XX has how many entries? ______

Q9MCQ1 mark

Compared with inference by enumeration, variable elimination is faster mainly because it

Q10NAT2 marks

In the alarm network with P(B)=0.001P(B) = 0.001, P(E)=0.002P(E) = 0.002, P(A∣B,E)=0.95P(A\mid B,E) = 0.95, P(A∣B,¬E)=0.94P(A\mid B,\neg E) = 0.94, P(A∣¬B,E)=0.29P(A\mid\neg B,E) = 0.29, P(A∣¬B,¬E)=0.001P(A\mid\neg B,\neg E) = 0.001, P(J∣A)=0.9P(J\mid A) = 0.9, P(J∣¬A)=0.05P(J\mid\neg A) = 0.05, P(M∣A)=0.7P(M\mid A) = 0.7, P(M∣¬A)=0.01P(M\mid\neg A) = 0.01: given that both John and Mary call, P(B∣J,M)P(B\mid J, M) is ______ (round to two decimals).