antecedent.counterfactual

GCM counterfactual helpers.

1"""GCM counterfactual helpers."""
2
3from __future__ import annotations
4
5from ._native import FittedGcm, GcmIteResult, counterfactual_ite, fit_gcm
6
7__all__ = ["FittedGcm", "GcmIteResult", "counterfactual_ite", "fit_gcm"]
class FittedGcm:

Fitted GCM retained across Python calls (fit once, sample / attribute many times).

Model, data, and names are [Arc]-shared so GIL-detached methods clone handles instead of deep-copying the fitted session on every click.

def mechanism_kinds(self, /):

Selected mechanism family id per variable name.

def sample_do(self, /, interventions, n, *, seed=0, threads=1):

Interventional ancestral sample under hard do values.

def counterfactual_ite(self, /, treatment, outcome, active, control, *, seed=0, threads=1):

Unit-level ITE under hard interventions on treatment.

def attribute_path_specific( self, /, treatment, outcome, *, path_nodes=None, max_paths=64, max_len=16, seed=0, threads=1):
def attribute_paths( self, /, sources, outcome, *, max_paths=64, max_len=16, seed=0, threads=1):
def attribute_distribution_change( self, /, outcome, baseline_start, baseline_end, comparison_start, comparison_end, *, n_samples=500, seed=0, threads=1):
def attribute_distribution_change_robust( self, /, outcome, baseline_start, baseline_end, comparison_start, comparison_end, *, n_samples=500, seed=0, threads=1):
def attribute_structure_change( self, /, comparison_edges, outcome, baseline_start, baseline_end, comparison_start, comparison_end, *, n_samples=500, seed=0, threads=1):
def attribute_unit_change(self, /, outcome, *, max_units=0, seed=0, threads=1):
def attribute_feature_relevance(self, /, outcome, *, delta=1.0, n_samples=200, seed=0, threads=1):
def anomaly_attribution(self, /, outcomes, *, max_units=0):
def mechanism_change_detection( self, /, baseline_start, baseline_end, comparison_start, comparison_end, *, seed=0, threads=1):
def rank_root_causes(self, /, attribution, *, seed=0, threads=1):
n_assignments
names
class GcmIteResult:

Result of a GCM counterfactual ITE (single boundary crossing).

unit_effects

Per-unit treatment effects (float64 NumPy array).

n_units
n_assignments
mean_ite
noise_inference
def counterfactual_ite( names, columns, edges, treatment, outcome, active, control, *, seed=0, threads=1):

Fit a linear-Gaussian GCM and return mean ITE under hard interventions.

Crosses the Python boundary once: NumPy columns + edges in, arrays out.

def fit_gcm(names, columns, edges, *, threads=1):

Fit a linear-Gaussian GCM; return a reusable [FittedGcm].