liveBook · Manning

Variable elimination

As explained in Causal AI

Variable elimination computes a target distribution by summing out selected variables from factors represented by a graphical model.

When a graphical model must answer a conditional question such as whether education differs between car drivers and train riders, variable elimination sums out irrelevant variables until the remaining factor represents the requested distribution. It uses graph structure to perform this reduction efficiently for tabular probabilistic models. section 3.1.11 section 2.2.5

A practical workflow is:

  • Represent the model as a graphical model with probability tables or factors. section 2.2.5
  • Specify the target variables and observed evidence, such as E given T = train. section 3.1.11
  • Sum over variables that are not needed, using the graph to determine an effective elimination order. section 2.2.5
  • Read the resulting factor as the target probability table; software such as pgmpy performs the algorithm. section 3.1.11 section 2.2.5
Listing 3.7 Inference on the trained causal graphical model
from pgmpy.inference import VariableElimination    #1
inference = VariableElimination(model)     
query1 = inference.query(['E'], evidence={"T": "train"})
query2 = inference.query(['E'], evidence={"T": "car"})
print("train")
print(query1)
print("car")
print(query2)

A pgmpy query constructs VariableElimination on a trained model, conditions on transportation, and prints separate education distributions for train and car. section 3.1.11

From conditional queries to counterfactuals

In the Monty Hall model, applying the do operation to set the hypothetical strategy to switching and then querying with VariableElimination combines abduction and prediction. Given a player who stayed and lost, the inferred probability of winning under switching is 1.0; conditioning only on losing produces probability 0.6667. section 9.2.4

How Causal AI covers it

How deep it goes
Explains factor summation, graph-guided elimination, and library use, but defers detailed algorithmic derivation and continuous-model generalization.
Examples
Uses education and transportation tables, Pyro inference, and Monty Hall counterfactual distributions.
What it assumes
Assumes graphical-model and probability-table basics while treating inference as software-supported model querying.
What you can do after
Apply it via pgmpy to compute conditional distributions and discrete counterfactual queries from graphical models.
How it connects
Connects graphical models with belief propagation, importance sampling, causal inference, and counterfactual inference.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.