Answering probability queries in a Bayesian network exactly: inference by enumeration, factors and their operations, the variable elimination algorithm, irrelevant variables and how the elimination order sets the cost. GATE asks posteriors in small networks and factor sizes.
A query asks for the posterior of a query variable given evidence . The remaining variables are hidden. By definition of conditional probability and marginalisation,
where is a normalising constant. In practice we compute the unnormalised value for each value of and divide by their sum; is never needed separately.
Inference by enumeration writes the joint as the product of CPT entries and sums it over all hidden values. With binary variables this touches up to terms, each a product of numbers: time , but only linear space if done depth-first.
Enumeration repeats work. In
we can pull outside the sum because it does not depend on . Moving factors outside sums and caching partial sums is exactly what variable elimination does, systematically.
A useful check: posteriors over the values of must add to 1, and evidence that is very likely under one value of should raise that value's posterior.
2. Factors and their operations
A factor is a table that gives a non-negative number for each combination of values of its variables. Each CPT is a factor: is a factor . Evidence turns a CPT into a smaller factor: fixing in gives a factor over only.
Three operations are needed.
Restriction: set evidence variables to their observed values and drop them from the factor.
Pointwise product: with . The result is over the union of the variables.
Summing out: gives a factor over ; add the entries that agree on and .
Size. A factor over variables each with values has entries. The product of and over ternary variables has entries. The cost of variable elimination is driven by the largest factor it builds, so watch the union of variables at each step.
Factors need not sum to 1. Only the last step, normalising the final factor over the query, turns numbers into a probability distribution.
3. The variable elimination algorithm
Variable elimination (VE) computes as follows.
Make one factor per CPT and restrict all of them by the evidence.
Choose an order for the hidden variables.
For each hidden variable in turn: multiply all factors that mention , sum out , and put the new factor back.
Multiply the remaining factors (all over only) and normalise.
On the chain , the query becomes
P(C)=b∑P(C∣b)f1(b)a∑P(a)P(b∣a).
Each sum involves only two variables, so the cost is linear in the length of the chain, while enumeration would be exponential.
Irrelevant (barren) variables. A variable that is neither a query nor evidence nor an ancestor of one can be removed before starting: its CPT sums to 1. For in , the node W contributes , so it can be dropped. Repeat the pruning, since removing a leaf may make its parent a barren leaf too.
VE gives the same answer in every order. Only the work changes.
Variable elimination on the chain A → B → C: multiply the factors that mention A, sum A out, then repeat for B
4. Cost and the elimination order
Eliminating a variable creates a factor over all its current neighbours in the factor graph. Time and space are exponential in the size of the largest factor created, so the order matters.
Example: a naive Bayes network with class and children , query .
Order
Largest factor
first, then
factor over (each )
first
factor over , size
Useful facts:
For a polytree (no undirected cycles), a good order makes VE linear in the total CPT size.
For general networks, exact inference is NP-hard, and finding the best order is itself NP-hard. Greedy heuristics pick next the variable that creates the smallest factor (min-degree) or adds the fewest new edges (min-fill).
Under the best order, the number of variables in the largest product formed (the eliminated variable plus its neighbours), minus one, is the treewidth of the moralised graph.
When exact inference is too costly, approximate methods (sampling) are used, covered in the next topic.
GATE questions here usually give a small network and ask for a posterior, or ask for the variables or entries of the factor created at some step. Write the factor's variable set before computing numbers.
Formulas to remember
Posterior by marginalisation, found by normalising
Pointwise product
Summing out
Factor size variables with values each
Chain marginal
Enumeration cost binary variables
Common mistakes
Forgetting to normalise the final factor; unnormalised values are , not .
Summing out a variable from only one of the factors that mention it; multiply all of them first.
Writing the product of and as a factor over only; a product is over the union of variables.
Restricting by evidence after summing; set evidence values first, or you sum over values that did not happen.
Thinking a bad elimination order gives a wrong answer; it gives the right answer, slowly.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Variable elimination on a chain
numerical
Chain , all binary. ; , ; , . Find .
Step 1: Eliminate A first: which factors mention A?
Try it on paper first.
Example 2: Posterior with a common effect
numerical
Rain R and sprinkler S both cause wet grass W. , , for . Find .
Step 1: Restrict by the evidence and set up the sum.
Try it on paper first.
Example 3: Dropping barren variables
conceptual
In the network , , , , which variables can be removed before computing ?
Step 1: Find the nodes that are not query, evidence or their ancestors.
Try it on paper first.
Example 4: Choosing an elimination order
conceptual
A network has with children (all binary). For the query , compare eliminating first with eliminating and first.
Step 1: Eliminate Y first.
Try it on paper first.
Previous year questions
1 official GATE DA question on this topic, newest first.
9 questions: up to 1 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.