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
