Title: A Brief Introduction to Do-Calculus - PyImageSearch

URL Source: https://pyimagesearch.com/2023/11/27/a-brief-introduction-to-do-calculus/

Published Time: 2023-11-27T14:00:00+00:00

Markdown Content:
* * *

**Table of Contents**
---------------------

*   [A Brief Introduction to Do-Calculus](#h2BPTitle)

*   [Definitions](#h3Definitions)

*   [Definition 1](#h4Definition1)
*   [Definition 2](#h4Definition2)

*   [The Rules of Do-Calculus](#h3Rules)

*   [Rule 1: Insertion/Deletion of Observation](#h4Rule1)
*   [Rule 2: Action/Observation Exchange](#h4Rule2)
*   [Rule 3: Insertion/Deletion of Action](#h4Rule3)

*   [Summary](#h2Summary)

*   [References](#h3References)
*   [Citation Information](#h3Citation)

* * *

This lesson is the 4th in a 5-part series on **Causality in Machine Learning**:

1.  [_Introduction to Causality in Machine Learning_](https://pyimg.co/3sa8x)
2.  [_Best Machine Learning Datasets_](https://pyimg.co/cds9g)
3.  [_Tools and Methodologies for Studying Causal Effects_](https://pyimg.co/pkm2j)
4.  [**_A Brief Introduction to Do-Calculus_**](https://pyimg.co/h3q2n) **(this tutorial)**
5.  _Studying Causal Effect with Microsoft’s Do-Why Library_

[![Image 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20603%20500'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2023/11/do-calculus-featured.png)

**To learn how to get started with `do-calculus` for causality, _just keep reading._**

* * *

[**A Brief Introduction to Do-Calculus**](#TOC-h2BPTitle)
---------------------------------------------------------

Welcome back to Part 4 of the series on **Causality in Machine Learning**. The previous two parts introduced us to the [world of causal inference](https://pyimg.co/3sa8x) and the [various methodologies involved](https://pyimg.co/pkm2j).

In this part, we will discuss a very popular and useful method known as the `do-calculus` developed by Judea Pearl in 1995. It was developed to propose a foolproof methodology for the identification of causal effects in non-parametric models.

Well, that’s a mouthful. What do we mean by that?

In simple words, this means to identify the effect or effects for a particular cause from data that is continuous rather than having discrete values.

We have learned in the previous blogs that it is impossible to do Causal Inference without having some form of intervention on the provided data. To facilitate this, `do-calculus` introduces a mathematical operator called ![Image 2: \text{do}(x)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2037%2018'%3E%3C/svg%3E), which simulates intervention by removing certain functions from the model and replacing them with a constant ![Image 3: X=x](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2046%2011'%3E%3C/svg%3E). To understand how this plays out, we will first have to look at some of the definitions introduced by Pearl.

* * *

### [**Definitions**](#TOC-h3Definitions)

* * *

#### [**Definition 1**](#TOC-h4Definition1)

The probability distribution of the outcome ![Image 4: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) after the intervention is given by the equation:

![Image 5: P_M(y \mid \text{do}(x)) = P_{M_x}(y)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20168%2018'%3E%3C/svg%3E)

where the distribution of the outcome ![Image 6: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) is defined as the probability assigned by the model ![Image 7: M_x](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2014'%3E%3C/svg%3E) to each outcome level ![Image 8: Y=y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2043%2014'%3E%3C/svg%3E).

* * *

#### [**Definition 2**](#TOC-h4Definition2)

This part discusses when and under what conditions a causal query (whether a variable or a group of variables is the cause for a given effect or not) is identifiable.

Given a set of assumptions (![Image 9: A](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E)) that satisfy two fully specified models (![Image 10: M_1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2021%2015'%3E%3C/svg%3E) and ![Image 11: M_2](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2022%2014'%3E%3C/svg%3E)), the following is the criteria for identifiability:

![Image 12: P(M_1) = P(M_2) \Rightarrow Q(M_1) = Q(M_2)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20259%2018'%3E%3C/svg%3E)

This means that whatever the details of the models are, if the distribution of the two models given the same set of assumptions (![Image 13: A](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E)) are equal, then it follows that the causal query for the two models should also be equal. This can be extended to mean that a causal query, under such circumstances, can be expressed in terms of the parameters of ![Image 14: P](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E).

* * *

### [**The Rules of Do-Calculus**](#TOC-h3Rules)

Now that we have learned about the definitions of `do-calculus`, let us familiarize ourselves with the three rules that govern the mathematics of `do-calculus`. But first, we need to understand the necessity of these rules.

In the previous section, we learned under what conditions a causal query will be identifiable, and we also saw how to formulate an expression in terms of a do-expression (e.g., ![Image 15: P_M(y \mid \text{do}(x)) = P_{M_x}(y)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20168%2018'%3E%3C/svg%3E)). So, when a causal query is given to us in the form of a do-expression, there are actual mathematical steps that can be taken to resolve it and find out whether the query is identifiable or not.

Consider the following directed acyclic graph in **Figure 1** (![Image 16: G](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E)) where ![Image 17: X](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2011'%3E%3C/svg%3E), ![Image 18: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E), ![Image 19: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E), and ![Image 20: W](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2018%2011'%3E%3C/svg%3E) are arbitrary disjoint nodes. ![Image 21: G{}_{\overline{X}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E) is the manipulated graph where all incoming edges to ![Image 22: X](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2011'%3E%3C/svg%3E) have been removed.

[![Image 23](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20443'%3E%3C/svg%3E)](https://lh7-us.googleusercontent.com/iW-hwGNftSqRaVwddZQyIFEl_ItyBJojBP5rcZC-sV28PKU-C26IUmLT8XEuebW33oGsqeHXoRaZ6yrNIYmxFESbgNhXIr5Aj6aUZrJUoc772CtyFLpWaNWRsdOuRTo-SRVBd78ig1fpBvKMNHUMfTU)

**Figure 1:** Original and manipulated graphs (source: image by the authors).

Similarly, ![Image 24: G_{\underline{X}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E) is the manipulated graph where all outgoing edges to ![Image 25: X](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2011'%3E%3C/svg%3E) have been removed, as shown in **Figure 2**.

[![Image 26](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20700%20482'%3E%3C/svg%3E)](https://lh7-us.googleusercontent.com/BtBNYdtltWgRMr9MOpKd0UofB5Xiu37LxHyKXbsILjmOLxxSZ-qhl9U4o53viSaFVnVg-w_4fm7BJgj8b0m165MwTV-iKxlbTXOrOSGYZUdanGyqcUdevWMDwArIeyj1uNnGaScJGJ_aZ_W9h8yf3Zc)

**Figure 2:** Outgoing graphs (source: image by the authors).

Another useful notation to get familiarized with is the concept of ![Image 27: d](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E)\-separation (![Image 28: \perp\!\!\!\perp](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2017%2012'%3E%3C/svg%3E)). In very simple words, given the graph, ![Image 29: a \rightarrow c \rightarrow b](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2074%2011'%3E%3C/svg%3E), the expression ![Image 30:  a \perp\!\!\!\perp b \mid c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2063%2017'%3E%3C/svg%3E) means that ![Image 31: a](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%207'%3E%3C/svg%3E) is conditionally independent of ![Image 32: b](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%2011'%3E%3C/svg%3E) given ![Image 33: c](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%207%207'%3E%3C/svg%3E).

To understand ![Image 34: d](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E)\-separation in a more detailed manner, have a look at this single-page [explanation](http://bayes.cs.ucla.edu/BOOK-2K/d-sep.html#:~:text=d%2Dseparation%20is%20a%20criterion,ness%22%20or%20%22separation%22.).

* * *

#### [**Rule 1: Insertion/Deletion of Observation**](#TOC-h4Rule1)

![Image 35: P(y \mid \text{do}(x),z,w) = P(y \mid \text{do}(x),w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20248%2018'%3E%3C/svg%3E) if ![Image 36: (Y \perp\!\!\!\perp Z \mid X,W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20115%2018'%3E%3C/svg%3E) for ![Image 37: G{}_{\overline{X}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E).

This means that if ![Image 38: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) is ![Image 39: d](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E)\-separated from ![Image 40: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) given ![Image 41: X](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2011'%3E%3C/svg%3E) and ![Image 42: W](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2018%2011'%3E%3C/svg%3E), then the expression of probability ![Image 43: P(y \mid \text{do}(x),z,w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20120%2018'%3E%3C/svg%3E) resolves to ![Image 44: P(y \mid \text{do}(x),w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20105%2018'%3E%3C/svg%3E). An easier way to understand this is by getting rid of the do-operators on both sides of the equality sign.

![Image 45: P(y \mid z,w) = P(y \mid w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20156%2018'%3E%3C/svg%3E) if ![Image 46: (Y \perp\!\!\!\perp Z \mid W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2094%2018'%3E%3C/svg%3E) for ![Image 47: G](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E)

The above expression simply implies conditional independence within the variables in the distribution given regular ![Image 48: d](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E)\-separation.

* * *

#### [**Rule 2: Action/Observation Exchange**](#TOC-h4Rule2)

![Image 49: P(y \mid \text{do}(x),\text{do}(z),w) = P(y \mid \text{do}(x),z,w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20294%2018'%3E%3C/svg%3E) if ![Image 50: (Y \perp\!\!\!\perp Z \mid X,W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20115%2018'%3E%3C/svg%3E) for ![Image 51: G{}_{\overline{X}\underline{Z}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2032%2018'%3E%3C/svg%3E).

To simplify the expression above, let us again remove ![Image 52: \text{do}(x)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2037%2018'%3E%3C/svg%3E) or consider ![Image 53: X](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2011'%3E%3C/svg%3E) to be an empty set.

![Image 54: P(y \mid \text{do}(z),w) = P(y \mid z,w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20201%2018'%3E%3C/svg%3E) if ![Image 55: (Y \perp\!\!\!\perp Z \mid W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2094%2018'%3E%3C/svg%3E) for ![Image 56: G_{\underline{Z}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2016'%3E%3C/svg%3E).

This expression refers to the backdoor-adjustment criteria that we saw in [Part 3](https://pyimg.co/pkm2j). Therefore, this rule gives us the interventional distribution for the backdoor adjustment criteria.

* * *

#### [**Rule 3: Insertion/Deletion of Action**](#TOC-h4Rule3)

![Image 57: P(y \mid \text{do}(x), \text{do}(z),w) = P(y \mid \text{do}(x),w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20278%2018'%3E%3C/svg%3E) if ![Image 58: (Y \perp\!\!\!\perp Z \mid X,W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20115%2018'%3E%3C/svg%3E) for ![Image 59: G{}_{\overline{X}\, \overline{Z(W)}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2056%2019'%3E%3C/svg%3E)

where ![Image 60: Z(W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2041%2018'%3E%3C/svg%3E) is the set of ![Image 61: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) nodes that are not ancestors of any ![Image 62: W](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2018%2011'%3E%3C/svg%3E) node in ![Image 63: G{}_{\overline{X}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2016'%3E%3C/svg%3E).

Again, for the sake of simplification, let us remove the ![Image 64: \text{do}(x)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2037%2018'%3E%3C/svg%3E) operator from the above expression.

![Image 65: P(y \mid \text{do}(z),w) = P(y \mid w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20186%2018'%3E%3C/svg%3E) if ![Image 66: (Y \perp\!\!\!\perp Z \mid W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2094%2018'%3E%3C/svg%3E) for ![Image 67: G{}_{\overline{Z(W)}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2019'%3E%3C/svg%3E)

Let’s pause here and really understand what this means. On the paper, it means that we can remove the intervention term ![Image 68: \text{do}(z)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2037%2018'%3E%3C/svg%3E) provided there is no causal association flowing from ![Image 69: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) to ![Image 70: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) ![Image 71: (Y \perp\!\!\!\perp Z \mid W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2094%2018'%3E%3C/svg%3E) in the graph ![Image 72: G{}_{\overline{Z(W)}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2045%2019'%3E%3C/svg%3E).

But that’s not all. We have a strange term called ![Image 73: Z(W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2041%2018'%3E%3C/svg%3E), which doesn’t quite fit in.

The simplified expression should have been:

![Image 74: P(y \mid \text{do}(z),w) = P(y \mid w)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20186%2018'%3E%3C/svg%3E) if ![Image 75: (Y \perp\!\!\!\perp Z \mid W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2094%2018'%3E%3C/svg%3E) for ![Image 76: G{}_{\overline{Z}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2016'%3E%3C/svg%3E)

where removal of incoming edges to ![Image 77: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) should result in the ![Image 78: d](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%209%2011'%3E%3C/svg%3E)\-separation of ![Image 79: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) and ![Image 80: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E), and no causal association should flow from ![Image 81: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) to ![Image 82: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E). However, instead of this simple term, we end up with an expression containing ![Image 83: Z(W)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2041%2018'%3E%3C/svg%3E). To understand this better, let us consider **Figure 3**:

Now, the intuitive idea is to remove incoming edges to ![Image 84: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) (![Image 85: G{}_{\overline{Z}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2016'%3E%3C/svg%3E)). But if we do that, then we risk changing the distribution of ![Image 86: Y](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E) altogether through the backdoor path consisting of ![Image 87: U](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E) and ![Image 88: V](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2011'%3E%3C/svg%3E).

Instead, what we can do is take a sub-node of ![Image 89: Z](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2012%2011'%3E%3C/svg%3E), say ![Image 90: Z_2](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2017%2014'%3E%3C/svg%3E), which is not an ancestor of any node in ![Image 91: W](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2018%2011'%3E%3C/svg%3E), and then remove all the incoming edges to it (![Image 92: G{}_{\overline{Z_2}}](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2028%2017'%3E%3C/svg%3E)). This is shown in **Figure 4**.

[![Image 93](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20524%20500'%3E%3C/svg%3E)](https://lh7-us.googleusercontent.com/xxpqInb1-1e5tMnrAt4978olkJNEbowKPesbjnh2Ur1EkOgkJMF2AjvKy3a9gVuGl72_8bmCECOXHg2UMoWhP3GtiJ1spfuQ13VtBiaQ0sU0wQhHWGkWRujX9vYftKHmbMijkKnC0jcBKVRdXw86vTg)

**Figure 4:** Removing incoming edges (source: image by the authors).

* * *

### What's next? We recommend [PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend).

**Course information:**  
84 total classes • 114+ hours of on-demand code walkthrough videos • Last updated: February 2024  
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled

**I strongly believe that if you had the right teacher you could _master_ computer vision and deep learning.**

Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?

That’s _not_ the case.

All you need to master computer vision and deep learning is for someone to explain things to you in _simple, intuitive_ terms. _And that’s exactly what I do_. My mission is to change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to _successfully_ and _confidently_ apply computer vision to your work, research, and projects. Join me in computer vision mastery.

**Inside PyImageSearch University you'll find:**

*   ✓ **84 courses** on essential computer vision, deep learning, and OpenCV topics
*   ✓ **84 Certificates** of Completion
*   ✓ **114+ hours** of on-demand video
*   ✓ **Brand new courses released _regularly_**, ensuring you can keep up with state-of-the-art techniques
*   ✓ **Pre-configured Jupyter Notebooks in Google Colab**
*   ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
*   ✓ Access to **centralized code repos for _all_ 536+ tutorials** on PyImageSearch
*   ✓ **Easy one-click downloads** for code, datasets, pre-trained models, etc.
*   ✓ **Access** on mobile, laptop, desktop, etc.

[Click here to join PyImageSearch University](https://pyimagesearch.com/pyimagesearch-university/?utm_source=blogPost&utm_medium=bottomBanner&utm_campaign=What%27s%20next%3F%20I%20recommend)

* * *

[**Summary**](#TOC-h2Summary)
-----------------------------

The rules and definitions of `do-calculus` provide a general structure for identifying Causal queries. The final query ![Image 94: Q](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2014'%3E%3C/svg%3E) should be free of any do-operator. This can be achieved by repeatedly applying the three rules. It is also complete, meaning if there exists a Causal Query ![Image 95: Q](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2013%2014'%3E%3C/svg%3E) that is identifiable, then it can be identified using `do-calculus`.

This lesson was aimed at introducing `do-calculus` very briefly and laying down the rules of the game. The idea is not to intimidate any newcomer with a whole lot of mathematical jargon but to provide insight into an essentially simple yet powerful framework for causal inference.

* * *

### [**References**](#TOC-h3References)

*   [The Do-Calculus Revisited by Judea Pearl](https://fermatslibrary.com/p/ebe0e889)
*   [Pearl’s Do-Calculus by Brady Neal](https://www.youtube.com/watch?v=M-mF6bXlxHI)

* * *

### [**Citation Information**](#TOC-h3Citation)

**A. R. Gosthipaty and R. Raha.** “A Brief Introduction to Do-Calculus,” _PyImageSearch_, P. Chugh, S. Huot, and K. Kidriavsteva, eds., 2023, [https://pyimg.co/h3q2n](https://pyimg.co/h3q2n)

@incollection{ARG-RR\_2023\_IntroDoCalculus,
  author = {Aritra Roy Gosthipaty and Ritwik Raha},
  title = {A Brief Introduction to Do-Calculus},
  booktitle = {PyImageSearch},
  editor = {Puneet Chugh and Susan Huot and Kseniia Kidriavsteva},
  year = {2023},
  url = {https://pyimg.co/h3q2n},
}

* * *

![Image 96: Featured Image](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20500%20276'%3E%3C/svg%3E)

### Unleash the potential of computer vision with Roboflow - Free!

*   Step into the realm of the future by [signing up or logging into your Roboflow account](https://roboflow.com/?ref=pyimagesearch). Unlock a wealth of innovative dataset libraries and revolutionize your computer vision operations.
*   Jumpstart your journey by choosing from our broad array of datasets, or benefit from PyimageSearch’s comprehensive library, crafted to cater to a wide range of requirements.
*   Transfer your data to Roboflow in any of the 40+ compatible formats. Leverage cutting-edge model architectures for training, and deploy seamlessly across diverse platforms, including API, NVIDIA, browser, iOS, and beyond. Integrate our platform effortlessly with your applications or your favorite third-party tools.
*   Equip yourself with the ability to train a potent computer vision model in a mere afternoon. With a few images, you can import data from any source via API, annotate images using our superior cloud-hosted tool, kickstart model training with a single click, and deploy the model via a hosted API endpoint. Tailor your process by opting for a code-centric approach, leveraging our intuitive, cloud-based UI, or combining both to fit your unique needs.
*   Embark on your journey today with absolutely no credit card required. Step into the future with Roboflow.

[Join Roboflow Now](https://roboflow.com/?ref=pyimagesearch)

* * *

![Image 97](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20410%20567'%3E%3C/svg%3E)

#### Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF

Enter your email address below to **join the PyImageSearch Newsletter** and **download my FREE 17-page Resource Guide PDF** on Computer Vision, OpenCV, and Deep Learning.