This crate demonstrates how the DeepCausality library, which implements the Effect Propagation Process (EPP), models the three rungs of Judea Pearl's Ladder of Causation. Each rung represents a different level of causal reasoning, and this example shows how the EPP's unique architecture addresses each one.
The examples are separated into three files, each corresponding to a rung on the ladder:
rung1_association.rsrung2_intervention.rsrung3_counterfactual.rs
From the root of the deep_causality project, run:
cargo run -p classical_causality_examples --example scm_example- File:
rung1_association.rs - Goal: Demonstrates simple observational inference. It answers the question: "Given that we observe X, what is the likelihood of Y?" (i.e.,
P(Y|X)).
Association is modeled as a straightforward evaluation of a CausaloidGraph. The graph represents the assumed causal chain (Smoking -> Tar -> Cancer). We provide an initial PropagatingEffect representing the observation (e.g., high nicotine levels), and the graph's evaluation propagates this effect to determine the associated outcome (cancer risk).
This aligns with Rung 1 by showing how the system processes passive observations to find statistical associations within the model.
- File:
rung2_intervention.rs - Goal: Demonstrates taking an action based on an observation. It answers the question: "What would Y be if we do X?" (i.e.,
P(Y|do(X))).
Intervention is modeled using the Causal State Machine (CSM).
- A
CausalStateis defined, with its condition for activation being the result of the causal graph (e.g., "High Cancer Risk" is true). - A
CausalActionis defined, which represents the real-world intervention (e.g., prescribing therapy). - The CSM links the state to the action. When the CSM is evaluated with an effect that makes the state true, it automatically fires the action.
This aligns with Rung 2 by providing a formal mechanism to move from inference to a deterministic, real-world action.
- File:
rung3_counterfactual.rs - Goal: Demonstrates reasoning about alternate possibilities. It answers the retrospective question: "What would Y have been, had X been different?"
The EPP models counterfactuals not by surgically altering the causal model itself, but through Contextual Alternation.
- A Factual Context is created to represent the observed reality (e.g., a person who smokes and has high tar).
- A Counterfactual Context is created by cloning the factual one and then modifying a specific past condition (e.g., setting the smoking level to low, but leaving the tar level high).
- The exact same
Causaloid(representing the causal laws) is evaluated against both contexts.
This example shows that even if we imagine the person had not smoked, their cancer risk remains high because the direct consequence (tar) is still present in the counterfactual world. This demonstrates the EPP's powerful ability to reason about alternative realities by separating causal logic from the context it operates on.
For more information on the EPP, please see chapter 5 in the EPP document: https://github.com/deepcausality-rs/papers/blob/main/effect_propagation_process/epp.pdf