Reproducing the paper
causalig works with any differentiable model and any user-supplied causal graph; the
Quickstart is all you need for your own data. The repository additionally contains the code for
the paper’s synthetic CATE benchmark:
the
experiments/package holds the data simulation, models, metrics and plots;scripts/holds one runner per experiment, plus a script that reports on its results.
The Dyngen and IFN-β experiments are not included. Their setup is described in the paper’s appendix.
Setup
git clone https://github.com/sifrimlab/CausalIG.git
cd CausalIG
pip install -e ".[shap,experiments]"
experiments/ is not installed as a package. Run the scripts, and the example below, from the
repository root.
Running an experiment from Python
CausalAttributionExperiment runs a full experiment:
it simulates a random DAG and SCM;
it trains a Lasso model on the data;
it computes attributions with the requested methods;
it scores them against the conditional average treatment effect (CATE) of each feature.
import numpy as np
from experiments.synthetic import CausalAttributionExperiment
from experiments.config.experiment import SyntheticExperimentConfig
num_features = 100
config = SyntheticExperimentConfig(
num_features=num_features,
num_causal=20,
num_samples=100, # number of samples explained (as in the paper)
noise_multiplier=0.1,
structural=True, # true SCM as surrogate applies each mechanism to the given parent values (as all paper scripts do)
ordering=np.arange(num_features), # required: topological feature ordering
attribution_n_baselines=10, # required for CEG: number of baseline samples
attribution_dim_chunk_size=25, # caps GPU memory (~2 GB here); raise it if you have more
output_dir="results/example", # results/ is git-ignored
)
experiment = CausalAttributionExperiment(config)
results = experiment.run(names=['CIG', 'CEG', 'IG'])
Main configuration fields
SyntheticExperimentConfig is a dataclass defined in experiments/config/experiment.py; see that
file for the full list of fields. The ones you are most likely to change:
Field |
Default |
Meaning |
|---|---|---|
|
|
Graph size, and how many features truly drive the outcome. |
|
|
Samples explained (the first |
|
|
Scale of the SCM noise. |
|
|
Limits the DAG depth. The paper’s scripts use |
|
|
Topological order of the features. Required. |
|
|
|
|
|
Structural mode for the oracle surrogate. Set |
|
|
Training settings for the learned surrogate. |
|
|
Total gradient steps. CEG divides them across its baselines. |
|
|
Number of CEG baselines. Required for CEG. |
|
|
Memory knobs (see Rules of thumb for large d). |
|
|
Corrupt the graph given to the methods ( |
|
CUDA if available |
Compute device. |
|
|
Where results and logs are written. |
Scripts
Each experiment is a run_*.py script with hardcoded parameters at the top. Edit them, then run
python scripts/run_*.py. Each one has a companion plot_*.py or print_*.py script with a
--results-dir option.
What it tests |
Run |
Report |
|---|---|---|
Attribution quality vs. CATE ground truth, across feature-count scale |
|
|
Robustness to removed, reversed or spurious causal graph edges |
|
|
How well attributions satisfy the completeness axiom |
|
|
Completeness-delta convergence vs. number of integration steps |
|
|
How completeness delta is distributed across individual explained samples, not just averaged |
(reuses the results of |
|
CIG with a trained surrogate vs. the true SCM as surrogate |
|
|
Whether the additive |
|
|
All run_*.py scripts write to results/<experiment>/ in the repository root, which is git-ignored. The
plot_* and print_* scripts read from there by default, so they can be run from any directory.