Algorithms for Causal Discovery under Distribution Change
Project description
CausalChange
Implementations of causal discovery algorithms for settings in which causal mechanisms may change across contexts, regimes, or time. Available methods are
- TOPIC for score-based causal DAG discovery from tabular data in topological order [2],
- LINC for causal discovery from multiple contexts, i.e., multiple tabular datasets with distribution shifts [1],
- SpaceTime for temporal causal discovery and changepoint detection in time series or multi-context time series [3].
Setup
Conda
Use the following to create a conda environment and install the package,
conda create -n causalchange python=3.10 -y
conda activate causalchange
pip install -e .
For running the notebooks, install a Jupyter kernel,
pip install ipykernel
python -m ipykernel install --user --name causalchange --display-name "Python (cc)"
Optional dependencies
Some functionality needs additional packages, ruptures for changepoint detection in SpaceTime,
hyppo, causal-learn for kernelized tests.
Demos
The notebooks under notebooks/ show basic usage on small synthetic examples.
Algorithms
Tabular causal discovery with TOPIC
TOPIC [2] is a score-based causal discovery method for tabular data that searches over topological orders. In this library it is implemented as a modular graph search backend and can be combined with different local MDL scores.
import pandas as pd
from causalchange.causal_change import CausalChange
from causalchange.config.cc_types import (
ContextAggregation,
DataMode,
GraphSearch,
ScoreType,
)
X = pd.DataFrame(...)
cc = CausalChange(
data_mode=DataMode.IID,
graph_search=GraphSearch.TOPIC,
score_type=ScoreType.LIN,
aggregation=ContextAggregation.SKIP,
)
cc.fit(X)
print(cc.graph_.edges())
Multi-context tabular data with LINC
For tabular data from multiple contexts, the library supports an extension of TOPIC to multiple contexts
using the ideas described in the LINC paper [1].
For tabular data with multiple contexts, the context column is specified through context_col.
cc = CausalChange(
data_mode=DataMode.CONTEXTS,
graph_search=GraphSearch.TOPIC,
score_type=ScoreType.LIN,
aggregation=ContextAggregation.LINC,
context_col="context",
)
cc.fit(X)
Temporal multi-context data is handled separately through SpaceTime.
Time series causal discovery with SpaceTime
SpaceTime is a score-based causal discovery method for time series, optionally with multiple contexts and changepoints.
The current implementation supports both single time series as well as multi-context time series.
For this, use DataMode.TIME or DataMode.TIME_CONTEXTS.
from causalchange.config.cc_config import ChangepointMode
cc = CausalChange(
data_mode=DataMode.TIME_CONTEXTS,
graph_search=GraphSearch.GLOBE,
score_type=ScoreType.LIN,
aggregation=ContextAggregation.SKIP,
context_col="context",
tau_max=2,
changepoints=ChangepointMode.DETECT,
d_min=20,
pelt_penalty=1.0,
detect_contexts=True,
detect_regimes=True,
)
cc.fit(X)
SpaceTime uses temporal nodes of the form
("x0", 0) # current time
("x0", 1) # lag 1
("x0", 2) # lag 2
and learns directed edges into lag-0 variables. For example, (("x0", 1), ("x1", 0)) means x0(t-1) -> x1(t).
Tests
Run the full test suite with
pytest
Run linting and formatting with
ruff check .
ruff format .
Before committing, the repository uses pre-commit hooks.
pre-commit run --all-files
References
[1] Mameche, S., Kaltenpoth, D., and Vreeken, J. Learning Causal Models under Independent Changes. NeurIPS, 2023.
[2] Xu, S., Mameche, S., and Vreeken, J. Information-theoretic Causal Discovery in Topological Order. AISTATS, 2025.
[3] Mameche, S., Cornanguer, L., Ninad, U., and Vreeken, J. SpaceTime: Causal Discovery from Non-stationary Time Series. AAAI, 2025.
[4] Mameche, S., Kalofolias, J., and Vreeken, J. Causal Mixture Models: Characterization and Discovery. NeurIPS, 2025.
Project details
Release history Release notifications | RSS feed
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 causalchange-0.1.0.tar.gz.
File metadata
- Download URL: causalchange-0.1.0.tar.gz
- Upload date:
- Size: 44.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cbe4e06ad692fffdfbc1220fc071f82de3a19614ded622248a4b0f7071aeef5
|
|
| MD5 |
eeda3d110715ee0531366dd4645ccc26
|
|
| BLAKE2b-256 |
4b882cdccec3d418d59601368120159ec980300e7e044c4d2bf644baf295d39f
|
File details
Details for the file causalchange-0.1.0-py3-none-any.whl.
File metadata
- Download URL: causalchange-0.1.0-py3-none-any.whl
- Upload date:
- Size: 56.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3077213557921f5ba2acb34286df37c8c3bf06112057bc903a955ba9d0eb041b
|
|
| MD5 |
217bec323dc522407797b8de47b182d5
|
|
| BLAKE2b-256 |
3353aea9fc7cc2279a3c1898c6516b9b65bd8e320bb5e8b952eb89b7660424ed
|