A package for Actual Causes Identification
Project description
Actual Causes Identification — actualcauses
Description
actualcauses is a Python package to identify actual causes (Halpern–Pearl style) in deterministic or stochastic systems.
It implements approximate algorithms with adjustable precision introduced in the paper:
Searching for actual causes: approximate algorithms with adjustable precision (Reyd, Diaconescu, Dessalles).
Preprint: arXiv:2507.07857
The package is designed for explainability and causal analysis of autonomous / AI-based systems: given a system model, a context, and a target consequence, it searches for exact or approximate actual causes.
Installation
pip install actualcauses
For local development:
git clone https://github.com/SamuelReyd/ActualCausesIdentification
cd ActualCausesIdentification
python -m pip install -e ".[dev]"
Core concepts (v1.0.0)
SCM
An SCM object represents a Structural Causal Model:
- V: endogenous variables (names)
- U: exogenous variables (names)
- D: variable domains
- u: a context (values for exogenous variables)
- dag: optional causal graph (for algorithms that exploit structure)
- model: a system model (see
SystemModelclass) used to evaluate interventions
Once created, you call:
scm.find_causes(...)
scm.show_identification_result()
System models (SystemModel, BaseNumpyModel, …)
A system model defines how the system responds to interventions.
For simple Python models, subclass SystemModel and implement call(u, e).
For accelerated / vectorized evaluation, subclass BaseNumpyModel (and optionally its stochastic variants).
Quickstart (Suzzy rock-throwing example)
The package provides a ready-to-run example SCM:
from actualcauses import suzzy_example_scm
# Identify causes with two algorithms (Beam Search / ISI)
suzzy_example_scm.find_causes(ISI=False, max_steps=5, beam_size=20, epsilon=0.05, early_stop=False, verbose=2)
suzzy_example_scm.show_identification_result()
suzzy_example_scm.find_causes(ISI=True, max_steps=5, beam_size=20, epsilon=0.05, early_stop=False, verbose=2)
suzzy_example_scm.show_identification_result()
A complete runnable version is in examples/quickstart.py.
See the examples/ folder for additional scenarios and advanced usage.
Minimal custom SCM example (deterministic)
This mirrors examples/custom_scm.py (forest fire scenario). The important part is implementing a SystemModel and passing it to SCM.
from actualcauses import SCM, SystemModel
class ForestFireModel(SystemModel):
def __init__(self, disjunctive=True):
super().__init__(
phi=lambda s: s[-1], # consequence predicate (example: last variable)
psi=lambda s: sum(s), # heuristic used by search
)
self.disjunctive = disjunctive
def __call__(self, u, e):
md, l = u
e = dict(e)
MD = e.get("MD", md)
L = e.get("L", l)
if self.disjunctive:
FF = e.get("FF", int(L or MD))
else:
FF = e.get("FF", int(L and MD))
self.n_calls += 1
return [MD, L, FF]
scm = SCM(
V=("MD", "L", "FF"),
U=("md", "l"),
D=(0, 1),
u=(1, 1),
model=ForestFireModel(disjunctive=True),
dag={"MD": [], "L": [], "FF": ["MD", "L"]},
)
scm.find_causes()
scm.show_identification_result()
Algorithms (high level)
The package provides:
-
Beam-search style identification for (approximate) actual causes.
-
ISI (Iterative Subinstance Identification) that can exploit a DAG to restrict search to relevant ancestors.
-
LUCB-based estimation for stochastic models, to allocate samples adaptively.
Exact knobs/parameters are exposed via SCM.find_causes(...). Notable usefull parameters include beam_size (integer), ISI (boolean), max_steps(integer), and early_stop (boolean). Algorithm have 3 level of verbosity (accessible via verbose=...).
Examples
The examples/ folder contains scripts intended to be read and modified:
- quickstart.py — Minimal end-to-end run using suzzy_example_scm.
- custom_scm.py — Implement a custom basic SCM and identify actual causes.
- custom_heuristic.py — Use different heuristics (psi) with a fixed system model and SCM.
- vectorized_system_model.py — Use BaseNumpyModel to accelerate identification by vectorizing intervention evaluation.
- stochastic_system_model.py — Stochastic evaluation with a naive average estimator and the LUCB estimator.
Run any example from the repository root, e.g.:
python examples/quickstart.py
License
MIT License. See LICENSE.
Citation
If you use this software in academic work, please cite:
Reyd, S., Diaconescu, A., & Dessalles, J. (2025). Searching for actual causes: Approximate algorithms with adjustable precision. arXiv:2507.07857.
@misc{reyd2025searchingactualcausesapproximate,
title = {Searching for actual causes: Approximate algorithms with adjustable precision},
author = {Samuel Reyd and Ada Diaconescu and Jean-Louis Dessalles},
year = {2025},
eprint = {2507.07857},
archivePrefix= {arXiv},
primaryClass = {cs.AI},
url = {https://arxiv.org/abs/2507.07857}
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file actualcauses-1.0.1.tar.gz.
File metadata
- Download URL: actualcauses-1.0.1.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c20b8ccb112cb9e3753131ccb7c00eb3d3d84e9db5fef0fe82a6c2b8e4930441
|
|
| MD5 |
aed98ae61218233fbdb8e99a783fe67f
|
|
| BLAKE2b-256 |
fafb31571f66d372e2231efede0996f25283b672139d9d92c2bf324eeaf3a7f9
|
Provenance
The following attestation bundles were made for actualcauses-1.0.1.tar.gz:
Publisher:
publish.yml on SamuelReyd/ActualCausesIdentification
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
actualcauses-1.0.1.tar.gz -
Subject digest:
c20b8ccb112cb9e3753131ccb7c00eb3d3d84e9db5fef0fe82a6c2b8e4930441 - Sigstore transparency entry: 843097126
- Sigstore integration time:
-
Permalink:
SamuelReyd/ActualCausesIdentification@69472dcaccc5ee0270f606c390476e4ebc191476 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/SamuelReyd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69472dcaccc5ee0270f606c390476e4ebc191476 -
Trigger Event:
push
-
Statement type:
File details
Details for the file actualcauses-1.0.1-py3-none-any.whl.
File metadata
- Download URL: actualcauses-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa6c2968c6c422734cf0e0a7d4229677f99fa2838e5142200871bebb97b5a87b
|
|
| MD5 |
060a0e1a12e3914d4a80331f3389efb0
|
|
| BLAKE2b-256 |
9b9040baeacb433f64182358bb647139cef52bfd2007c7d0581f73d49ecfbb54
|
Provenance
The following attestation bundles were made for actualcauses-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on SamuelReyd/ActualCausesIdentification
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
actualcauses-1.0.1-py3-none-any.whl -
Subject digest:
fa6c2968c6c422734cf0e0a7d4229677f99fa2838e5142200871bebb97b5a87b - Sigstore transparency entry: 843097188
- Sigstore integration time:
-
Permalink:
SamuelReyd/ActualCausesIdentification@69472dcaccc5ee0270f606c390476e4ebc191476 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/SamuelReyd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@69472dcaccc5ee0270f606c390476e4ebc191476 -
Trigger Event:
push
-
Statement type: