Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - jpeaceau/AutoITE: A Just-In-Time approach at estimating Individual Treatment Effect (ITE). · GitHub
Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jpeaceau/AutoITE: A Just-In-Time approach at estimating Individual Treatment Effect (ITE). · GitHub
Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jpeaceau/AutoITE: A Just-In-Time approach at estimating Individual Treatment Effect (ITE). · GitHub
Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - jpeaceau/AutoITE: A Just-In-Time approach at estimating Individual Treatment Effect (ITE). · GitHub
Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - jpeaceau/AutoITE: A Just-In-Time approach at estimating Individual Treatment Effect (ITE). · GitHub
Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - jpeaceau/AutoITE: A Just-In-Time approach at estimating Individual Treatment Effect (ITE). · GitHub
Skip to content

Repository files navigation

AutoITE

Individual Treatment Effect (ITE) estimation via Intrinsic Causal Geometry.

CIPyPILicense: AGPL-3.0

Overview

AutoITE estimates individual-level causal effects from longitudinal panel data (each patient observed at multiple time points) without requiring a held-out counterfactual. It works by representing each patient as a personal cooperative cone — a geometric object derived from their within-patient covariance structure — and finding matched controls whose cone geometry is compatible.

Two geometry variants are provided, sharing the same API:

VariantGeometryWhiteningTrajectory statisticBest for
ICG-HVRTCone (ellipsoid)SD (Σ^{-1/2})T = S² − ‖z‖²Clean Gaussian data
ICG-HARTPyramid (cross-polytope)MAD (1.4826·MAD)A = |S| − ‖z‖₁Data with outlier spikes (≥10σ)

When to use ICG-HVRT (geometry='cone', default)

  • Observation noise is approximately Gaussian
  • Data comes from controlled experiments or pre-processed pipelines
  • You want maximum statistical efficiency on clean data

When to use ICG-HART (geometry='pyramid')

  • Real-world observational or longitudinal data with measurement noise
  • Sensor dropout, transcription errors, rare physiological extremes (≥10σ spikes)
  • By the PyramidHART robustness property, a single-feature outlier leaves the trajectory statistic A unchanged but inflates the SD-based statistic T by O(spike_magnitude × √d)
  • Default recommendation for production use — more conservative and robust

Installation

pip install autoite

Requirements: Python ≥ 3.10, numpy ≥ 1.24, scipy ≥ 1.11, scikit-learn ≥ 1.3, hvrt ≥ 2.11.0.


Quick Start

importnumpyasnpfromautoiteimportICGHVRTEstimatorrng=np.random.default_rng(42)
# Synthetic panel data: 30 patients, 50 observations each, 4 covariatesX= [rng.standard_normal((50, 4)) for_inrange(30)] # covariatesT= [rng.standard_normal((50,)) for_inrange(30)] # treatmentY= [rng.standard_normal(50) for_inrange(30)] # outcome# ICG-HVRT (cone geometry, default) — best for clean Gaussian dataest_cone=ICGHVRTEstimator(geometry='cone', k=10).fit(X, T, Y)
tau_cone=est_cone.predict_effect(X[0], T[0])
print(f"ICG-HVRT tau = {tau_cone:.4f}")
# ICG-HART (pyramid geometry) — robust to outlier spikesest_pyr=ICGHVRTEstimator(geometry='pyramid', k=10).fit(X, T, Y)
tau_pyr=est_pyr.predict_effect(X[0], T[0])
print(f"ICG-HART tau = {tau_pyr:.4f}")

Weight learning (optional)

Both variants support data-driven weight calibration via leave-one-out MSE minimisation. This is recommended when treatment effect heterogeneity is concentrated in specific geometry components:

est=ICGHVRTEstimator(geometry='cone', k=10, learn_weights=True).fit(X, T, Y)

Local regression model (optional)

The local regression step that extracts τ̂ from the k-NN pool supports five variants:

# 'ridge' (default) — Ridge(α=1) on [X|T], L2 regularised# 'ols' — OLS on [X|T], unregularised# 'lad' — L1 (quantile) regression on [X|T], outlier-robust Y# 'mean' — simple mean contrast (T only), trusts cone pre-balancing# 'median' — Theil–Sen slope (T only), robust to outlier Y valuesest=ICGHVRTEstimator(geometry='cone', k=10, local_model='lad').fit(X, T, Y)

Prediction Confidence and Selective Prediction

The k-NN distance is a natural uncertainty signal: when the nearest neighbours are geometrically distant, the local regression pool is unreliable. Two complementary features leverage this:

Distance-weighted k-NN

Neighbours are weighted exp(−d_j) in the local regression, so geometrically close patients dominate. This is a free improvement at 100% coverage — no abstention required:

est=ICGHVRTEstimator(k=30, distance_weighted=True).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Selective prediction (abstention)

predict_effect_with_confidence returns both the ITE estimate and the mean k-NN distance. Use the confidence score to abstain for out-of-distribution patients:

est=ICGHVRTEstimator(k=30).fit(X, T, Y)
tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# Predict only for high-confidence patients (low distance)THRESHOLD=1.5# tune on held-out dataifdist<THRESHOLD:
print(f"ITE estimate: {tau:.4f} (confidence: {dist:.3f})")
else:
print(f"Out-of-distribution — abstaining (distance: {dist:.3f})")

Selective prediction benchmark (experiments/selective_prediction.py, 10 seeds × 4 DGPs, predicting only the top-20% most confident patients):

DGPICG-HVRT (all)Distance-weightedSelective 20%Random 20%
Geometric Confounded0.0560.030 (−47%)0.010 (−82%)0.052 (−7%)
Mean Confounded0.2450.214 (−13%)0.216 (−12%)0.241 (−2%)
Prognostic Confounded0.5560.500 (−10%)0.392 (−30%)0.543 (−2%)
Hidden Confounded0.9800.972 (−1%)0.971 (−1%)0.978 (−0%)

Key result: Selective 20% reduces PEHE by 82% on Geometric Confounded — geometrically incompatible patients have naturally large k-NN distances. On Hidden Confounded, selective ≈ random (the confidence signal is not spuriously correlated with hidden confounders), validating that the model is honest about what it can and cannot detect.

Clinical implication: ICG-HVRT can be deployed as a decision-support tool that declares when it cannot make a reliable prediction, directing clinical judgment to cases where the geometric support is insufficient. As more patient data accumulates, the abstention rate decreases.


Counterfactual Augmentation

In observational data, many patients never receive the full range of treatments. ICG-HVRT can fill missing treatment arms by generating synthetic counterfactual observations within each k-NN neighbour's HVRT partition distribution:

est=ICGHVRTEstimator(
k=30,
counterfactual_aug=True,
n_synth_per_neighbor=50, # synthetic observations per neighbour
).fit(X, T, Y)
tau=est.predict_effect(X_new, T_new)

Mechanism: For each k-NN neighbour j, a within-patient Ridge model is fitted to j's own observations. Synthetic covariates X_synth are sampled from j's HVRT partition distribution; treatment T_synth is drawn uniformly over the observed treatment range (filling the missing arm); outcome Y_synth is predicted by the within-patient model. The augmented pool extends local regression into counterfactual treatment regions.

Augmentation benchmark (experiments/counterfactual_aug_benchmark.py, 10 seeds × 8 DGPs, n_synth_per_neighbor=50):

DGPFlat ICG-HVRT+CF AugmentationDelta
Geometric Confounded0.0560.035−39%
Mean Confounded0.1140.116+2%
Prognostic Confounded0.5560.558~0%
Hidden Confounded0.9800.974~0%

Augmentation helps most on Geometric Confounded where treatment is systematically shifted (T_shift = ±1 by confounding), creating a missing treatment arm that synthetic counterfactuals fill. On randomised or hidden-confounder DGPs the augmentation is neutral — correctly detecting that there is no missing arm to fill.


Distance Structure

Each patient is represented as an eight-component distance split into two interpretable groups:

Identity distance (cone shape — who the patient is geometrically):

  • d_axis: alignment of the cooperative direction
  • d_opening: profile of directional half-angles
  • d_eccentricity: circular vs. elliptical cone shape
  • d_orientation: Procrustes alignment of the anti-cooperative frame

State distance (position on the cone — where the patient is right now):

  • d_levels: cooperative mean distance (τ-correlated, solves many-weak-measurements)
  • d_levels_perp: position in anti-cooperative subspace
  • d_occupation: manifold occupation fraction
  • d_dynamics: trajectory transition dynamics

High identity_distance among k nearest neighbours signals geometrically poor matches and is used as the prediction confidence score in selective prediction.


Benchmark Results

Results from python -m experiments.ite_comparison (10 seeds × 9 DGPs, 300 train / 50 test / 100 obs per patient). Lower sqrt-PEHE is better.

DGPS-LearnerR-LearnerCRNRMSNICG-HVRTICG-HARTWinner
Randomised~0.34~0.310.083~0.090.010~0.015ICG-HVRT
Geometric Confounded~0.52~0.490.553~0.550.013~0.018ICG-HVRT
Mean Confounded~0.12~0.100.084~0.110.114~0.14CRN
Sparse Mean Conf (spikes)~0.21~0.19~0.16~0.17~0.18~0.09ICG-HART
Indiv Feature Leak~0.23~0.21~0.19~0.18~0.17~0.12ICG-HART
Prognostic Confounded~0.75~0.750.129~0.140.556~0.61CRN
Hidden Confounded~0.97~0.97~0.96~0.96~0.96~0.96(all fail)
TV Confounded~0.31~0.30~0.28~0.26~0.24~0.21ICG-HART
Outlier Spike~0.22~0.20~0.17~0.16~0.20~0.08ICG-HART

Values marked ~ are approximate from single runs; run python -m experiments.ite_comparison to reproduce exact figures.

Data-generating processes

DGPConfounding mechanismKey property
RandomisedNone (RCT)Oracle baseline
Geometric ConfoundedTreatment confounded via cone geometry (T_shift = ±U)ICG immune by design
Mean ConfoundedU → E[X] and U → E[T] (mean-shift)CRN's adversarial domain
Sparse Mean ConfU leaked into K=5 obs per patient (sparse signal)ICG-HART extracts spikes
Indiv Feature LeakU leaked into single feature, 3 obs only (ultra-sparse)ICG-HART pattern matching
Prognostic ConfoundedU → tau AND U → E[X], but T ⊥ U (randomised)CRN wins via per-step supervision
Hidden ConfoundedU → T, U ∉ XAll methods fail — negative control
TV ConfoundedTime-varying U → TICG-HART tracks transitions
Outlier SpikeExtreme single-observation contamination (≥10σ)MAD whitening absorbs spikes

Interpretation

  • ICG-HVRT excels when effect heterogeneity lives in the covariance geometry (Randomised, Geometric Confounded). Cone identity is immune to geometric confounding: the cone shape changes with the covariance and the effect modifier, so confounded patients naturally have high identity distance from controls.
  • ICG-HART excels when data contains outlier spikes or sparse individual-level signals. MAD whitening leaves the trajectory statistic unchanged under single-feature contamination; SD whitening inflates it by O(spike_mag × √d).
  • CRN wins on Mean Confounded (adversarial gradient reversal targets mean-shift) and on Prognostic Confounded (per-timestep supervision exploits U's leakage into X at every observation, not just the patient mean).
  • Hidden Confounded is a negative control: all methods fail because the confounder is invisible in X. ICG-HVRT's confidence signal correctly detects geometric out-of-distribution patients but cannot detect hidden confounders whose geometry appears normal.

C++ Extension (Optional)

A C++ extension (autoite._core) provides ~65–140× speedups for large cohorts. The pure-Python fallback is used automatically when the extension is not built.

Performance with extension (n=300 patients, d=4, k=30):

OperationPythonC++Speedup
find_neighbours30 ms0.22 ms138×
predict_effect33 ms1.2 ms28×
fit_weights1.15 s18 ms65×

Building on Windows (MSVC + Ninja)

build_ext.bat

Building on Linux / macOS

pip install scikit-build-core pybind11 eigen
EIGEN3_INCLUDE_DIR=$(python -c "import eigency; print(eigency.get_include()[0])") \
pip install -e . --no-build-isolation

API Reference

fromautoiteimport (
ICGHVRTEstimator, # Main estimator (both geometry variants)ICGHVRTMatcher, # Distance computation and k-NN matchingCooperativeGeometryProfile, # Per-patient geometry profileConeIdentity, # Cone eigendecomposition and identity distanceCoupledInterventionProtocol,# Closed-loop intervention trackingfit_shared_hvrt, # Shared HVRT/HART model fittingpool_whitened_observations, # Whitened observation pooling
)

ICGHVRTEstimator parameters

ParameterDefaultDescription
k10Number of k-NN neighbours for local regression
geometry'cone''cone' (ICG-HVRT) or 'pyramid' (ICG-HART)
learn_weightsFalseL-BFGS-B calibration of 8-component distance weights
local_model'ridge'Local regression: 'ridge', 'ols', 'lad', 'mean', 'median'
distance_weightedFalseWeight k-NN pool by exp(−d_j) in local regression
counterfactual_augFalseAugment pool with HVRT-sampled counterfactual observations
n_synth_per_neighbor30Synthetic observations per neighbour (with counterfactual_aug)
alpha_local1.0Ridge regularisation strength for local regression

Key methods

# Fit on training dataest.fit(X_list, T_list, Y_list) # lists of (n_obs, d), (n_obs,), (n_obs,) arrays# Predict ITE for a test patienttau=est.predict_effect(X_new, T_new)
# Predict ITE + confidence (for selective prediction)tau, dist=est.predict_effect_with_confidence(X_new, T_new)
# dist = mean k-NN distance; lower = higher geometric confidence# Triage report (geometry diagnostics)report=est.triage_report(X_new, T_new)

See help(ICGHVRTEstimator) for full parameter documentation.


Reproducing Benchmarks

# Full ITE comparison (8 methods × 9 DGPs × 10 seeds, ~30 min)
python -m experiments.ite_comparison
# Selective prediction / coverage-PEHE curves (10 seeds × 4 DGPs)
python -m experiments.selective_prediction
# Counterfactual augmentation benchmark (10 seeds × 8 DGPs)
python -m experiments.counterfactual_aug_benchmark
# Local regression model sweep (5 seeds × 7 DGPs × 5 models)
python -m experiments.local_model_benchmark
# Comprehensive benchmark (policy regret + uncertainty calibration)
python -m experiments.comprehensive_benchmark

License

AGPL-3.0. See LICENSE.

About

A Just-In-Time approach at estimating Individual Treatment Effect (ITE).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages