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:

  1. Rung 1 (Seeing): Observational joint distribution $P(Z, X, Y)$ subject to confounding and Simpson's Paradox.
  2. Rung 2 (Doing): Interventional distribution $P(Y \mid \text{do}(X = x^*))$ via do-calculus graph surgery.
  3. 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}$:

Z1:=Ο΅Z1,Z2:=Ο΅Z2Z_1 := \epsilon_{Z_1}, \quad Z_2 := \epsilon_{Z_2} X:=fX(Z1,Z2)+Ο΅XX := f_X(Z_1, Z_2) + \epsilon_X Y:=fY(X,Z1,Z2)+Ο΅YY := f_Y(X, Z_1, Z_2) + \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:

MX=xβˆ—:X:=xβˆ—,Y:=fY(xβˆ—,Z1,Z2)+Ο΅Y\mathcal{M}_{X=x^*}: \quad X := x^*, \quad Y := f_Y(x^*, Z_1, Z_2) + \epsilon_Y

The resulting interventional distribution matches the Backdoor Adjustment Formula:

P(Y=y∣do(X=xβˆ—))=∫P(Y=y∣X=xβˆ—,Z=z)P(z)dzP(Y = y \mid \text{do}(X = x^*)) = \int P(Y = y \mid X = x^*, \mathbf{Z} = \mathbf{z}) P(\mathbf{z}) d\mathbf{z}

2. Counterfactual Abduction-Action-Prediction Theorem

For any observed individual unit with evidence $\mathbf{v} = (z_1, z_2, x, y)$:

  1. Abduction: Compute unique latent exogenous shock $\hat{\epsilon}_Y = y - f_Y(x, z_1, z_2)$.
  2. Action: Replace structural equation for $X$ with $X := x'$.
  3. Prediction: Compute counterfactual outcome $Y_{X=x'} = f_Y(x', z_1, z_2) + \hat{\epsilon}_Y$.

Guaranteed Counterfactual Consistency Axiom: YX=xobs(u)≑yobs(Error=0.00Γ—100)Y_{X=x^{\text{obs}}}(u) \equiv y^{\text{obs}} \quad (\text{Error} = 0.00 \times 10^0)


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
Safetensors
Model size
150 params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

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-benchmarks
    self-reported
    0.000
  • Counterfactual Abduction Consistency Error on At1uri/causal-counterfactual-benchmarks
    self-reported
    0.000
  • Confounder Invariance Suppression on At1uri/causal-counterfactual-benchmarks
    self-reported
    0.001