liveBook · Manning

What you will learn in Causal AI

by Robert Osazuwa Ness
Foreword by Lindsay Edwards

Chapter by chapter

Chapter 1: Why causal AI

1.1 What is causal AI? · 1.2 How this book approaches causal inference · 1.2.1 Emphasis on AI · 1.2.2 Focus on tech, retail, and business · 1.2.3 Parallel world counterfactuals and other queries beyond causal effects · 1.2.4 An assumption of commodification of inference · 1.2.5 Breaking down theory with code · 1.3 Causality’s role in modern AI workflows · 1.3.1 Better data science · 1.3.2 Better attribution, credit assignment, and root cause analysis · 1.3.3 More robust, decomposable, and explainable models · 1.3.4 Fairer AI · 1.4 How causality is driving the next AI wave · 1.4.1 Causal representation learning · 1.4.2 Causal reinforcement learning · 1.4.3 Large language models and foundation models · 1.5 A machine learning-themed primer on causality · 1.5.1 Queries, probabilities, and statistics · 1.5.2 Causality and MNIST · 1.5.3 Causal queries, probabilities, and statistics · 1.6 Summary

What you learn in chapter 1 →

Chapter 2: A primer on probabilistic generative modeling

2.1 Primer on probability · 2.1.1 Random variables and probability · 2.1.2 Probability distributions and distribution functions · 2.1.3 Joint probability and conditional probability · 2.1.4 The chain rule, the law of total probability, and Bayes Rule · 2.1.5 Markovian assumptions and Markov kernels · 2.1.6 Parameters · 2.1.7 Canonical classes of probability distribution · 2.1.8 Visualizing distributions · 2.1.9 Independence and conditional independence · 2.1.10 Expected value · 2.2 Computational probability · 2.2.1 The physical interpretation of probability · 2.2.2 Random generation · 2.2.3 Coding random processes · 2.2.4 Monte Carlo simulation and expectation · 2.2.5 Programming probabilistic inference · 2.3 Data, populations, statistics, and models · 2.3.1 Probability distributions as models for populations · 2.3.2 From the observed data to the data generating process · 2.3.3 Statistical tests for independence · 2.3.4 Statistical estimation of model parameters · 2.4 Determinism and subjective probability · 2.4.1 Determinism · 2.4.2 Subjective probability · 2.5 Summary

What you learn in chapter 2 →

Chapter 3: Building a causal graphical model

3.1 Introducing the causal DAG · 3.1.1 Case study: A causal model for transportation · 3.1.2 Why use a causal DAG? · 3.1.3 DAGs are useful in communicating and visualizing causal assumptions · 3.1.4 We have many tools for computing over DAGs · 3.1.5 Causal DAGs can represent time · 3.1.6 DAGs link causality to conditional independence · 3.1.7 DAGs can provide scaffolding for probabilistic ML models · 3.1.8 Training a model on the causal DAG · 3.1.9 Different techniques for parameter learning · 3.1.10 Learning parameters when there are latent variables · 3.1.11 Inference with a trained causal probabilistic machine learning model · 3.2 Causal invariance and parameter modularity · 3.2.1 Independence of mechanism and parameter modularity · 3.2.2 Causal transfer learning, data fusion, and invariant prediction · 3.2.3 Fitting parameters with common sense · 3.3 Your causal question scopes the DAG · 3.3.1 Selecting variables for inclusion in the DAG · 3.3.2 Including variables in causal DAGs by their role in inference · 3.4 Looking ahead: Model testing and combining causal graphs with deep learning · 3.5 Summary

What you learn in chapter 3 →

Chapter 4: Testing the DAG with causal constraints

4.1 How causality induces conditional independence · 4.1.1 Colliders · 4.1.2 Abstracting independence with a causal graph · 4.2 D-separation and conditional independence · 4.2.1 D-separation: A gateway to simplified causal analysis · 4.2.2 Examples of d-separating multiple paths · 4.2.3 D-separation in code · 4.3 Refuting a causal DAG · 4.3.1 Revisiting the causal Markov property · 4.3.2 Refutation using conditional independence tests · 4.3.3 Some tests are more important than others · 4.4 Caveats with conditional independence testing · 4.4.1 Statistical tests always have some chance of error · 4.4.2 Testing causal DAGs with traditional CI tests is flawed · 4.4.3 p-values vary with the size of the data · 4.4.4 The problem of multiple comparisons · 4.4.5 Conditional independence testing struggles in machine learning settings · 4.4.6 Final thoughts · 4.5 Refuting a causal DAG given latent variables · 4.5.1 An example of a testable implication that works with latent variables · 4.5.2 Libraries and perspectives on testing functional constraints · 4.5.3 Testing a functional constraint · 4.5.4 Final thoughts on testable implications · 4.6 Primer on (the perils of) causal discovery · 4.6.1 Approaches to causal discovery · 4.6.2 Causal discovery, causal faithfulness, and latent variable assumptions · 4.6.3 Equivalence classes and PDAGs · 4.6.4 How to think about causal discovery · 4.7 Summary

What you learn in chapter 4 →

Chapter 5: Connecting causality and deep learning

5.1 A causal model of a computer vision problem · 5.1.1 Leveraging the universal function approximator · 5.1.2 Causal abstraction and plate models · 5.2 Training a neural causal model · 5.2.1 Setting up the training data · 5.2.2 Setting up the variational autoencoder · 5.2.3 The training procedure · 5.2.4 Evaluating training · 5.2.5 How should we causally interpret Z? · 5.2.6 Advantages of this causal interpretation · 5.3 Using causal inference to enhance deep learning · 5.3.1 Independence of mechanism as an inductive bias · 5.3.2 Case study: Semi-supervised learning · 5.3.3 Demystifying deep learning with causality · 5.4 Summary

What you learn in chapter 5 →

Chapter 6: Structural causal models

6.1 From a general causal graphical model to an SCM · 6.1.1 Forensics case study · 6.1.2 Converting to an SCM via reparameterization · 6.1.3 Formalizing the new model · 6.1.4 A discrete, imperative example of an SCM · 6.1.5 Why use SCMs? · 6.1.6 Differences from related approaches · 6.1.7 Causal determinism and implications to how we model · 6.2 Equivalence between SCMs · 6.2.1 Reparameterization is not enough · 6.2.2 Uniqueness and equivalence of SCMs · 6.3 Implementing SCMs for rule-based systems · 6.3.1 Case study: The Monty Hall problem · 6.3.2 A causal DAG for the Monty Hall problem · 6.3.3 Implementing Monty Hall as an SCM with pgmpy · 6.3.4 Exogenous variables in the rule-based system · 6.3.5 Applications of SCM-modeling of rule-based systems · 6.4 Training an SCM on data · 6.4.1 What assignment functions should I choose? · 6.4.2 How should I model the exogenous variable distributions? · 6.4.3 Additive models: A popular choice for SCM modeling · 6.4.4 Linear Gaussian additive model · 6.4.5 Linear non-Gaussian additive models · 6.4.6 Nonlinear additive noise models · 6.4.7 Training additive model SCMs with regression tools · 6.4.8 Beyond the additive model · 6.5 Combining SCMs with deep learning · 6.5.1 Implementing and training an SCM with basic PyTorch · 6.5.2 Training an SCM with probabilistic PyTorch · 6.5.3 Neural SCMs and normalizing flows · 6.6 Summary

What you learn in chapter 6 →

Chapter 7: Interventions and causal effects

7.1 Case studies of interventions · 7.1.1 Case study: Predicting the weather vs. business performance · 7.1.2 Case study: Credit fraud detection · 7.1.3 Case study: Statistical analysis for an online role-playing game · 7.1.4 From randomized experiments to interventions · 7.1.5 From observations to experiments · 7.1.6 From experiments to interventions · 7.1.7 Recap · 7.2 The ideal intervention and intervention operator · 7.2.1 Intervention operators · 7.2.2 Ideal interventions in structural causal models · 7.2.3 Graph surgery: The ideal intervention in causal DAGs and causal graphical models · 7.2.4 Graph surgery and d-separation · 7.2.5 Ideal interventions and causal Markov kernels · 7.2.6 Ideal interventions in a causal program · 7.3 Intervention variables and distributions · 7.3.1 “Do” and counterfactual notation · 7.3.2 When causal notation reduces to traditional notation · 7.3.3 Causal models represent all intervention distributions · 7.4 Interventions and causal effects · 7.4.1 Average treatment effects with binary causes · 7.4.2 Average treatment effect with categorical causes · 7.4.3 Average treatment effect for continuous causes · 7.4.4 Conditional average treatment effect · 7.4.5 Statistical measures of association and causality · 7.4.6 Causality and regression models · 7.5 Stochastic interventions · 7.5.1 Random assignment in an experiment is a stochastic intervention · 7.5.2 Intervention policies · 7.6 Practical considerations in modeling interventions · 7.6.1 Reasoning about interventions that we can’t do in reality · 7.6.2 Refutation and real-world interventions · 7.6.3 “No causation without manipulation” · 7.6.4 Modeling “non-ideal” interventions · 7.7 Summary

What you learn in chapter 7 →

Chapter 8: Counterfactuals and parallel worlds

8.1 Motivating counterfactual reasoning · 8.1.1 Online gaming · 8.1.2 The streaming wars · 8.1.3 Counterfactuals analysis of machine learning models · 8.1.4 Regret and why do we care about what “would have happened?” · 8.1.5 Reinforcement learning and automated decision-making · 8.1.6 Steps to answering a counterfactual query · 8.2 Symbolic representation of counterfactuals · 8.2.1 Hypothetical statements and questions · 8.2.2 Facts filter hypotheticals to a subpopulation · 8.2.3 Conditional hypotheticals, interventions, and simulation · 8.2.4 Counterfactual statements · 8.2.5 The consistency rule · 8.2.6 More examples · 8.3 Binary counterfactuals · 8.3.1 Probabilities of causation · 8.3.2 Probabilities of causation and attribution · 8.3.3 Binary counterfactuals and uplift modeling · 8.4 Possible worlds and parallel world graphs · 8.4.1 Potential outcomes in possible worlds · 8.4.2 The parallel world graph · 8.4.3 Applying the hypothetical condition via graph surgery · 8.4.4 Reasoning across more than two possible worlds · 8.4.5 Rule of thumb: Hypothetical worlds should be simpler · 8.5 Summary

What you learn in chapter 8 →

Chapter 9: The general counterfactual inference algorithm

9.1 Algorithm walkthrough · 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 · 9.3.4 Implementing the action and prediction steps · 9.4 Case study 3: Counterfactual image generation with a deep generative model · 9.4.1 The dSprites data · 9.4.2 Assumptions needed for counterfactual image generation · 9.5 Summary

What you learn in chapter 9 →

Chapter 10: Identification and the causal hierarchy

10.1 The causal hierarchy · 10.1.1 Where questions and queries fall on the hierarchy · 10.1.2 Where models and assumptions fall on the hierarchy · 10.1.3 Where data falls on the hierarchy · 10.1.4 The causal hierarchy theorem · 10.2 Identification and the causal inference workflow · 10.2.1 Defining identification · 10.2.2 The causal inference workflow · 10.2.3 Separating identification and estimation · 10.3 Identification with backdoor adjustment · 10.3.1 The backdoor adjustment formula · 10.3.2 Demystifying the back door · 10.4 Graphical identification with the do-calculus · 10.4.1 Demystifying the do-calculus · 10.4.2 Using the do-calculus for backdoor identification · 10.5 Graphical identification algorithms · 10.5.1 Case study: The front-door estimand · 10.5.2 Demystifying the front door · 10.6 General counterfactual identification · 10.6.1 The problem with the general algorithm for counterfactual inference · 10.6.2 Example: Monotonicity and the probabilities of causation · 10.7 Graphical counterfactual identification · 10.7.1 Effect of treatment on the treated · 10.7.2 Identification over the counterfactual graph · 10.7.3 Counterfactual identification with single-world intervention graphs · 10.7.4 Identification with SWIGs · 10.7.5 The single-world assumption · 10.8 Identification and probabilistic inference · 10.9 Partial identification · 10.10 Summary

What you learn in chapter 10 →

Chapter 11: Building a causal inference workflow

11.1 Step 1: Select the query · 11.2 Step 2: Build the model · 11.3 Step 3: Identify the estimand · 11.3.1 The backdoor adjustment estimand · 11.3.2 The instrumental variable estimand · 11.3.3 The front-door adjustment estimand · 11.3.4 Choosing estimands and reducing “DAG anxiety” · 11.3.5 When you don’t have identification · 11.4 Step 4: Estimate the estimand · 11.4.1 Linear regression estimation of the backdoor estimand · 11.4.2 Propensity score estimators of the backdoor estimand · 11.4.3 Backdoor estimation with machine learning · 11.4.4 Front-door estimation · 11.4.5 Instrumental variable methods · 11.4.6 Comparing and selecting estimators · 11.5 Step 5: Refutation · 11.5.1 Data size reduction · 11.5.2 Adding a dummy confounder · 11.5.3 Replacing treatment with a dummy · 11.5.4 Replacing outcome with a dummy outcome · 11.5.5 Testing robustness to unmodeled confounders · 11.6 Causal inference with causal generative models · 11.6.1 Transformations for causal inference · 11.6.2 Steps for inferring a causal query with a causal generative model · 11.6.3 Extending inference to estimation · 11.6.4 A VAE-inspired model for causal inference · 11.6.5 Setting up posterior inference with SVI · 11.6.6 Posterior predictive inference of the ATE · 11.6.7 On the identifiability of the Bayesian causal generative inference · 11.6.8 Closing thoughts on causal latent variable models · 11.7 Summary

What you learn in chapter 11 →

Chapter 12: Causal decisions and reinforcement learning

12.1 A causal primer on decision theory · 12.1.1 Utility, reward, loss, and cost · 12.1.2 Uncertainty comes from other causes · 12.2 Causal decision theory · 12.2.1 Decisions as a level 2 query · 12.2.2 Causal characterization of decision rules and policies · 12.2.3 Causal probabilistic decision-modeling and admissibility · 12.2.4 The deceptive alignment of argmax values of causal and non-causal expectations · 12.2.5 Newcomb’s paradox · 12.2.6 Newcomb’s paradox with a causal model · 12.2.7 Introspection in causal decision theory · 12.3 Causal DAGs and sequential decisions · 12.3.1 Bandit feedback · 12.3.2 Contextual bandit feedback · 12.3.3 Delayed feedback · 12.3.4 Causal queries on a sequential model · 12.4 Policies as stochastic interventions · 12.4.1 Examples in sequential decision-making · 12.4.2 How policies can introduce confounding · 12.5 Causal reinforcement learning · 12.5.1 Connecting causality and Markov decision processes · 12.5.2 The MDP as a causal DAG · 12.5.3 Partially observable MDPs · 12.5.4 Policy in an MDP · 12.5.5 Causal Bellman equation · 12.6 Counterfactual reasoning for decision-theory · 12.6.1 Counterfactual policy evaluation · 12.6.2 Counterfactual regret minimization · 12.6.3 Making level 3 assumptions in decision problems · 12.7 Summary

What you learn in chapter 12 →

Chapter 13: Causality and large language models

13.1 LLMs as a causal knowledgebase · 13.1.1 Building a causal DAG · 13.1.2 Generating code for DAGs, models, and causal analyses · 13.1.3 Explanations and mechanism · 13.1.4 The causal frame problem and AI alignment · 13.1.5 Understanding and contextualizing causal concepts · 13.1.6 Formalization of causal queries · 13.1.7 Beware: LLMs hallucinate · 13.2 A causality-themed LLM primer · 13.2.1 A probabilistic ML view of LLMs · 13.2.2 The attention mechanism · 13.2.3 From tokens to causal representation · 13.2.4 Hallucination, attention, and causal identification · 13.3 Forging your own causal LLM · 13.3.1 An LLM for script writing · 13.3.2 Using pretrained models for causal Markov kernels · 13.3.3 Sampling from the interventional and observational distributions · 13.3.4 Closing thoughts · 13.4 Summary

What you learn in chapter 13 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.