9 The general counterfactual inference algorithm

 

This chapter covers

  • Implementing the general counterfactual inference algorithm
  • Directly implementing a parallel world DAG as a causal graphical model
  • Using a variational inference to implement the algorithm
  • Building counterfactual deep generative models of images

The previous chapter taught you how to formalize counterfactuals and use the parallel world graph to reason across possible worlds. In this chapter, I’ll introduce an algorithm for inferring counterfactual queries. Then I’ll present three case studies showing implementations of the algorithm using different probabilistic ML approaches.

I call the algorithm we’ll discuss in this chapter the “general” algorithm for probabilistic counterfactual inference because you can infer any counterfactual query with this algorithm. The catch is that you need an SCM. Moreover, differences between your SCM and the ground-truth SCM can lead to inaccuracies in your counterfactual inferences. We’ll look more closely at this issue when we discuss identification in chapter 10, where you’ll also learn ways of inferring counterfactuals without knowing the ground-truth SCM. In this chapter, you’ll see the power of this SCM-based approach, especially in machine learning.

9.1 Algorithm walkthrough

In this section, we’ll do a high-level walkthrough of the general algorithm probabilistic counterfactual inference. The algorithm has three steps commonly called abduction, action, and prediction:

9.1.1 Abduction: Infer the exogenous variables given the observed endogenous variables

9.1.2 Action: Implementing the hypothetical causes

9.1.3 Prediction: Inferring hypothetical outcomes

9.1.4 Counterfactual Monte Carlo

9.1.5 Introduction to the case studies

9.2 Case study 1: Monty Hall problem

9.2.1 Specifying the exogenous variables

9.2.2 Specifying the assignment functions for the endogenous variables

9.2.3 Building the parallel world graphical model

9.2.4 Running the counterfactual inference algorithm

9.3 Case study 2: Counterfactual variational inference

9.3.1 Building the model

9.3.2 Implementing an intervention with pyro.do

9.3.3 Implementing the abduction step with variational inference