liveBook · Manning

Counterfactual inference algorithm

As explained in Causal AI

A counterfactual inference algorithm is a computational procedure for determining the outcome that would have occurred under an alternative condition using a causal model.

A counterfactual inference algorithm computes what would have happened under an alternative condition using a structural causal model (SCM). Unlike prediction, it preserves the observed case while changing a specified condition through an ideal intervention. section 9.5

Run the algorithm in three stages:

  • Abduction: infer the exogenous variables that plausibly generated the observed endogenous variables. section 9.5
  • Action: apply the hypothetical condition as an ideal intervention in the model. section 9.5
  • Prediction: generate the hypothetical outcome using the intervened model and the exogenous-variable distribution inferred during abduction. section 9.5

Abduction may be exact when every endogenous variable is observed and the SCM assignment functions are invertible. More commonly, only some variables are observed, so variational inference approximates the posterior over exogenous variables with a trainable guide function. section 9.3.3

Changing femur length

Given femur length 44 cm and height 165 cm, ask what height would result if femur length were 46 cm. Condition the Pyro model on the observations, optimize a guide with SVI and Trace_ELBO, extract the updated exogenous distribution, then run the hypothetical world. section 9.3.3

Semantic image editing

For an image of a person wearing glasses, abduct a latent representation, intervene to remove glasses, and predict a new image. A causal model aims to preserve image elements not downstream of the edit. section 9.4

Figure 9.12 The parallel world graph for the femur length counterfactual
figure

Use the parallel-world graph to trace the observed case, intervention, shared exogenous variables, and hypothetical outcome. section 9.3.3

How Causal AI covers it

How deep it goes
Defines abduction, action, and prediction, then implements abduction with variational inference while deferring identification questions.
Examples
Uses femur-length height estimation and semantic image editing, including removing glasses while preserving unaffected image concepts.
What it assumes
Assumes an SCM and modeling assumptions, while introducing the abduction, action, and prediction workflow explicitly.
What you can do after
Apply it via Pyro, variational inference, or a deep generative model to produce hypothetical numerical or media outcomes.
How it connects
Connects structural causal models, ideal interventions, parallel-world graphs, variational inference, normalizing flows, and deep generative models.

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.