function ELIMINATION-ASK(X, e, bn) returns a distribution over X
inputs: X, the query variable
e, observed values for variables E
bn, a Bayesian network specifying joint distribution P(X1, …, Xn)
factors ← []
for each var in ORDER(bn.VARS) do
factors ← [MAKE-FACTOR(var, e) | factors]
if var is a hidden variable then factors ← SUM-OUT(var, factors)
return NORMALIZE(POINTWISE-PRODUCT(factors))
Figure ?? The variable elimination algorithm for inference in Bayesian networks.