A Language for Counterfactual Generative Models

Zenna Tavares, James Koppel, Xin Zhang, Ria Das, Armando Solar-Lezama

Overview

OMEGAC is a new probabilistic programming language (PPL) that makes "what-if" reasoning a first-class citizen. By combining a novel do operator with lazy evaluation, it allows researchers to perform complex counterfactual inferences on universal simulation models—like asking if a car crash would have been avoided at a lower speed—without manually rewriting the underlying code.

The Challenge of Causal Reasoning

Causal reasoning, specifically counterfactual inference, is the art of asking: "Given that event $A$ happened, what would have occurred if $B$ had been different?" Traditionally, this is done using Causal Graphical Models (CGMs). While powerful, CGMs are essentially "straight-line" programs; they cannot easily handle the loops, recursion, or complex data structures found in modern simulations.

Existing probabilistic languages can handle uncertainty, but they struggle with counterfactuals. To simulate a "what-if" scenario in a standard PPL, a programmer usually has to manually duplicate their model (the "twin-network" construction), which is error-prone and doesn't scale. The authors address this by creating a language where interventions are built into the semantics, allowing for "surgical" modifications to a running simulation.

Introducing OMEGAC

The authors introduce OMEGAC, a Turing-universal PPL. Its core innovations include:

  1. The do Operator: Borrowing from Judea Pearl’s causal calculus, OMEGAC introduces a do(X → x) operator. This allows a user to retroactively change the value of a variable $X$ to $x$ within an expression.
  2. Lazy Evaluation: This is the "secret sauce." In a standard "eager" language, once a variable is calculated, its value is fixed. OMEGAC uses lazy evaluation, storing variables as "closures" (the expression plus its environment). When a do intervention occurs, the language performs retroactive updating, creating a new environment where the intervened variable is rebound, and all downstream dependencies are re-evaluated automatically.
  3. $\lambda_C$ Calculus: The authors provide a formal mathematical foundation for these semantics, proving that the do operator is not merely "syntactic sugar" (a simple macro) but actually increases the expressive power of the language.

Case Studies

The paper demonstrates OMEGAC through several sophisticated case studies rather than a single training dataset:

  • Car-Crash Model: A custom simulation using ray-marching for rendering and basic physics to model a driver, a pedestrian, and an obstacle.
Top-down view of the car crash simulation
  • OhioT1DM Dataset: A real-world dataset containing continuous glucose monitoring, food intake, and insulin data for Type 1 Diabetes patients, used to model counterfactual health outcomes.
  • Synthetic Migration Model: A Markov Decision Process (MDP) simulating islanders moving between different regions to test counterfactual planning.

Key Insights

  • Counterfactuals as Nested Expressions: A counterfactual is elegantly expressed as $(Y | \text{do}(X \to x)) | E$. This structure first uses evidence $E$ from the real world to update the model's hidden states, and then applies the intervention $x$ to see the hypothetical outcome $Y$.
  • Intervention as Environment Manipulation: Instead of changing the code, OMEGAC changes the context in which the code runs. This allows for "non-atomic" interventions, such as changing a variable to be a function of its former self (e.g., "What if the driver's reaction time was 20% faster?").
  • The Proof of Power: The authors use a technique from programming language theory (Felleisen’s proof) to show that do provides a form of dynamic scoping that cannot be replicated in standard functional languages without significant overhead.

Results and Applications

  • Car Crash Attribution: In a simulated crash, OMEGAC inferred the driver's velocity from a single video frame. It then showed that even if the driver had obeyed the speed limit (intervening on CarV → 14), the crash likely would have happened anyway because the obstacle occluded the pedestrian until it was too late.
Histograms showing the distance between the pedestrian and car under different counterfactual scenarios
  • Glucose Management: The model successfully queried whether a hypoglycemic episode could have been avoided if a patient had eaten at a different time, providing a posterior distribution over "optimal" intervention times.
  • But-for Causality: The authors implemented a formal "but-for" test (e.g., "But for the obstacle, would the driver have seen the pedestrian?"). By using gradient-based optimization over the do operator, they could automatically identify which specific variables were the "causes" of an event.

Limitations and Future Work

  • Causal Discovery: OMEGAC requires the user to provide the causal model (the simulation). It cannot currently "learn" the causal structure from raw data; it only performs inference on a given structure.
  • Scoping Constraints: Intervening on variables that are internal to a function (and not exposed in the current scope) remains a challenge. The authors suggest that future versions might need more advanced reflection mechanisms to "reach inside" functions.
  • Performance: While lazy evaluation enables these causal features, it can be slower than eager evaluation. Optimizing the "retroactive updating" process for massive simulations is a noted area for future research.

Summary updated

BibTeX
@inproceedings{tavares2021language,
  author = {Zenna Tavares and James Koppel and Xin Zhang and Ria Das and Armando Solar-Lezama},
  title = {{A Language for Counterfactual Generative Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=5VG5oM84_DA},
}
Figure