Structural Causal Model (SCM) Engine (At1uri/causal-structural-equation-engine)
A research-grade Structural Causal Model (SCM) engine implementing Judea Pearl's complete 3-Tier Causal Hierarchy:
- Rung 1 (Seeing): Observational joint distribution $P(Z, X, Y)$ subject to confounding and Simpson's Paradox.
- Rung 2 (Doing): Interventional distribution $P(Y \mid \text{do}(X = x^*))$ via do-calculus graph surgery.
- Rung 3 (Imagining): Unit-level counterfactual potential outcomes $Y_{X=x'}(u)$ via 3-step abduction-action-prediction.
Mathematical Architecture
Let $\mathcal{M} = \langle \mathbf{V}, \mathbf{U}, \mathcal{F}, P(\mathbf{U}) \rangle$ be a 4-variable nonlinear additive noise SCM over observed variables $\mathbf{V} = {Z_1, Z_2, X, Y}$ and independent exogenous noise variables $\mathbf{U} = {\epsilon_{Z_1}, \epsilon_{Z_2}, \epsilon_X, \epsilon_Y}$:
1. Interventional Graph Surgery ($\text{do}(X = x^*)$)
Under an external policy intervention $\text{do}(X = x^*)$, the structural equation for $X$ is replaced by the constant $x^*$, and all incoming parental arrows $\text{PA}_X \to X$ are severed:
The resulting interventional distribution matches the Backdoor Adjustment Formula:
2. Counterfactual Abduction-Action-Prediction Theorem
For any observed individual unit with evidence $\mathbf{v} = (z_1, z_2, x, y)$:
- Abduction: Compute unique latent exogenous shock $\hat{\epsilon}_Y = y - f_Y(x, z_1, z_2)$.
- Action: Replace structural equation for $X$ with $X := x'$.
- Prediction: Compute counterfactual outcome $Y_{X=x'} = f_Y(x', z_1, z_2) + \hat{\epsilon}_Y$.
Guaranteed Counterfactual Consistency Axiom:
Model Specifications
| Parameter | Value |
|---|---|
| Variables | $Z_1, Z_2$ (Confounders), $X$ (Treatment), $Y$ (Outcome) |
| Structural Functions | $f_X: \mathbb{R}^2 \to \mathbb{R}$, $f_Y: \mathbb{R}^3 \to \mathbb{R}$ (MLP with $\tanh$) |
| Exogenous Noise | Additive Gaussian $\mathcal{N}(0, \sigma^2)$ |
| True Causal ATE | $+2.2098$ |
| Naive Observational Slope | $+0.3869$ (Confounding bias: $-1.8229$) |
| Counterfactual Consistency Error | $0.00 \times 10^0$ (Exact) |
| Weights Format | model.safetensors |
Quickstart & Usage
from scm_model import StructuralCausalModel
# Load pretrained SCM engine
scm = StructuralCausalModel.from_pretrained(".")
# 1. Observational Sampling (Seeing)
obs = scm.sample_observational(n_samples=5)
print("Observed Treatment X:", obs["x"][:3])
# 2. Intervene via do-calculus (Doing)
int_data = scm.intervene(do_x_val=1.5, n_samples=1000)
print(f"E[Y | do(X=1.5)]: {int_data['y'].mean():.4f}")
# 3. Counterfactual Query (Imagining)
# "Given unit observed with X=0.6, Y=1.62, what would Y be if X was 2.0?"
cf = scm.counterfactual(obs_z1=0.5, obs_z2=-0.14, obs_x=0.6, obs_y=1.62, cf_x_val=2.0)
print(f"Counterfactual Outcome Y_{{X=2.0}}: {cf['counterfactual_y']:.4f}")
Developed by Ramprasad Atluri (At1uri).
- Downloads last month
- 20
Space using At1uri/causal-structural-equation-engine 1
Collection including At1uri/causal-structural-equation-engine
Evaluation results
- Average Treatment Effect Estimation Error (ATE MSE) on At1uri/causal-counterfactual-benchmarksself-reported0.000
- Counterfactual Abduction Consistency Error on At1uri/causal-counterfactual-benchmarksself-reported0.000
- Confounder Invariance Suppression on At1uri/causal-counterfactual-benchmarksself-reported0.001