Examples: Classical Causal Models
Relevant source files
The following files were used as context for generating this wiki page:
The DeepCausality project provides a comprehensive suite of examples demonstrating how classical causal models—such as Structural Causal Models (SCM), Dynamic Bayesian Networks (DBN), and Granger Causality—are expressed using the framework's dynamic causality primitives. While the project is built upon the Effect Propagation Process (EPP) for dynamic, adaptive, and emergent causality, it maintains full compatibility with classical frameworks by treating them as specific configurations of the Causaloid and CausalMonad structures.
These examples serve as a bridge for developers familiar with Pearl’s Ladder of Causation, illustrating how to map association, intervention, and counterfactual reasoning into the monadic pipelines of DeepCausality. By utilizing the PropagatingEffect and Intervenable traits, the library can express all major frameworks of classical computational causality while extending them with high-precision numerical support and context-aware reasoning.
Sources: README.md:15-18, README.md:46-48, AGENTS.md:131-135
Core Primitives for Classical Modeling
Classical causal models are implemented using three primary components within DeepCausality. The framework treats causality as a "spacetime-agnostic functional dependency," allowing static classical structures to be modeled as specialized instances of these primitives.
Causaloid and CausalMonad
The Causaloid acts as a polymorphic container for causal functions, while the CausalMonad handles the sequencing through Kleisli composition.
- Structural Representation: SCMs and DBNs often utilize the
Causaloidin its Graph form to represent cross-influencing dependencies. - Sequential Reasoning: Temporal models like DBNs or Granger causality are typically modeled using
CausalMonadbind-chains to propagate effects through time steps.
Sources: README.md:94-114, AGENTS.md:141-143
The Propagating Effect Carrier
All classical examples utilize the PropagatingEffect carrier to manage the flow of values, errors, and audit logs across the model.
| Type | Purpose | Channels |
|---|---|---|
PropagatingEffect<T> | Stateless effect propagation | Value, Error, Log |
PropagatingProcess<T> | Stateful effect propagation | Value, State, Context, Error, Log |
Sources: README.md:116-121, examples/material_examples/README.md:73-77
Pearl's Ladder of Causation
DeepCausality explicitly implements Pearl's Ladder of Causation through monadic composition. The following diagram illustrates how a causal chain is evaluated and subsequently modified via intervention.
The diagram shows the mapping of Pearl's Rungs to the PropagatingEffect pipeline.
Sources: README.md:21-44
Implementation Example: Counterfactual Intervention
In a classical SCM context, a counterfactual is modeled by taking an observed causal chain and forcing a value at a specific node using the .intervene() method. This preserves the audit log of the original observation while recalculating subsequent effects based on the forced state.
// Intervention: Replace value MID-CHAIN with do(BloodLevel := 3.0)
let intervened = PropagatingEffect::pure(10.0_f64)
.bind(|dose, _, _| PropagatingEffect::pure(dose * 0.8))
.intervene(3.0) // Force value mid-chain
.bind(|level, _, _| PropagatingEffect::pure(level - 2.0))
.bind(|level, _, _| {
let response = if level > 5.0 { "Effective" } else { "Ineffective" };
PropagatingEffect::pure(response)
});
Sources: README.md:31-41
Dynamic Bayesian Networks (DBN) and Temporal Models
Temporal models like DBNs are represented in DeepCausality through stateful propagation. Unlike static DBNs, the PropagatingProcess allows the causal structure itself to evolve as the system crosses thresholds (e.g., regime changes in physical systems).
Temporal Flow Architecture
The following sequence diagram illustrates how a temporal causal model processes state and context across multiple steps.
The DBN-style flow demonstrates state and context threading through a monadic bind-chain.
Sources: README.md:123-128, openspec/changes/archive/physics_examples.md:10-25
Example: Regime-Switching Models
A common application of classical temporal modeling within the framework is switching physics kernels based on a state context. For instance, an orbital mechanics model may transition from Newtonian to Relativistic gravity as a distance threshold is crossed.
| Step | Logic | API / Component |
|---|---|---|
| Regime Check | Compare distance $r$ against $r_s$ | schwarzschild_radius |
| Newtonian Path | Calculate orbital velocity | orbital_velocity |
| Relativistic Path | Calculate time dilation | time_dilation_angle |
Sources: openspec/changes/archive/physics_examples.md:20-35, README.md:123-125
Causal Discovery and Structural Modeling
Classical models often start with data discovery. The project includes the deep_causality_discovery crate, which provides a Domain Specific Language (DSL) to close the loop from raw data to structural causal models.
The Causal Discovery pipeline automates the generation of classical causal structures from data.
Sources: openspec/changes/archive/2026-05-15-rebuild-website-astro/design.md:150-165, README.md:141-143
Summary
The classical causal model examples in DeepCausality demonstrate the framework's ability to encapsulate traditional SCM, DBN, and do-calculus within a modern, monadic Rust architecture. By leveraging PropagatingEffect for sequencing and Causaloid for structure, the project provides a unified environment where classical assumptions of static causality can coexist with—and transition into—dynamic and emergent causal systems.
Sources: README.md:46-48, AGENTS.md:131-135