Skip to main content

Latest version Tests License: BSD Downloads

CausalDisco 🪩

CausalDisco provides baseline algorithms and analytics tools for Causal Discovery in Python. The package can be installed by running pip install CausalDisco. Additional information can be found in the documentation.

Functionality

Baseline algorithms can be found in CausalDisco/baselines.py:

  • Var-SortnRegress
  • R²-SortnRegress
  • rel-SortnRegress

Analytics tools can be found in CausalDisco/analytics.py:

  • Var-sortability
  • R²-sortability
  • rel-sortability (empirical and oracle number of relatives)

Each sortability can compute order alignment over edges, ancestor-descendant pairs, or path lengths.

Random DAG models can be found in CausalDisco/graphs.py:

  • Erdős–Rényi
  • scale-free / Barabási–Albert
  • time series: ER-based summary graphs, unrolled into DAGs

Sources

If you find our algorithms useful please consider citing

  1. Beware of the Simulated DAG!
  2. A Scale-Invariant Sorting Criterion to Find a Causal Order in Additive Noise Models
  3. A Topological Sorting Criterion for Random Causal Directed Acyclic Graphs
@inproceedings{reisach2026topological,
    title = {{A Topological Sorting Criterion for Random Causal Directed Acyclic Graphs}},
    author = {Alexander G. Reisach and Antoine Chambaz and Gilles Blanchard and Sebastian Weichwald},
    booktitle = {Advances in Neural Information Processing Systems},
    year = {2026},
    doi = {10.48550/arXiv.2605.06288},
}

@inproceedings{reisach2023scale,
    title = {A Scale-Invariant Sorting Criterion to Find a Causal Order in Additive Noise Models},
    author = {Alexander G. Reisach and Myriam Tami and Christof Seiler and Antoine Chambaz and Sebastian Weichwald},
    booktitle = {Advances in Neural Information Processing Systems},
    year = {2023},
    doi = {10.48550/arXiv.2303.18211},
}

@inproceedings{reisach2021beware,
    title = {Beware of the Simulated DAG! Causal Discovery Benchmarks May Be Easy to Game},
    author = {Alexander G. Reisach and Christof Seiler and Sebastian Weichwald},
    booktitle = {Advances in Neural Information Processing Systems},
    year = {2021},
    doi = {10.48550/arXiv.2102.13647},
}

A Simple Example

# --- sample data from a linear SCM on a random DAG:

import numpy as np
from CausalDisco.graphs import ER_DAG

rng = np.random.default_rng(0)
d = 10
B = ER_DAG(d, 2, shuffle=True, rng=rng)
W = B * rng.choice([-1, 1], size=(d, d)) * rng.uniform(.5, 2, size=(d, d))
X = rng.standard_normal((10000, d)).dot(np.linalg.inv(np.eye(d) - W))
X_std = (X - np.mean(X, axis=0))/np.std(X, axis=0)

# --- run analytics and print results:

from CausalDisco.analytics import (
    var_sortability,
    r2_sortability,
    rel_sortability,
)

print(
    f'var-sortability={var_sortability(X, W):.2f}\n'
    f'R^2-sortability={r2_sortability(X, W):.2f}\n'
    f'rel-sortability={rel_sortability(X, W):.2f}'
)

# --- run baselines and print the structural Hamming distance (SHD)

from gadjid import shd

from CausalDisco.baselines import (
    random_sort_regress,
    var_sort_regress,
    r2_sort_regress,
    rel_sort_regress,
)

def SHD(W_hat):
    return shd(B.astype(np.int8), (W_hat != 0).astype(np.int8))[1]

for name, method in [
    ('randomSortnRegress', random_sort_regress),
    ('varSortnRegress', var_sort_regress),
    ('r2SortnRegress', r2_sort_regress),
    ('relSortnRegress', rel_sort_regress),
]:
    print(
        f'--- {name} ---\n'
        f'SHD: {SHD(method(X))}\n'
        f'SHD standardized: {SHD(method(X_std))}'
    )

Shout out to Anne Helby Petersen for coming up with the "causal disco" naming idea (check out her causalDisco package providing tools for causal discovery on observational data in R).

Metadata

Release files for CausalDisco 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CausalDisco 0.3.0
File Size Uploaded Provenance Actions
causaldisco-0.3.0.tar.gz 11.4 kB Without provenance Details for causaldisco-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for CausalDisco 0.3.0
File Interpreter ABI Platform Actions
causaldisco-0.3.0-py3-none-any.whl Python 3 none any Details for causaldisco-0.3.0-py3-none-any.whl

Total release size: 25.3 kB

Release files / causaldisco-0.3.0.tar.gz

Download URL causaldisco-0.3.0.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b465cc4d269d003d72bfc94e511b4a6b5efd04ea1703a3670707a790ec75f1a6
BLAKE2b-256 checksum
How to use checksums
6e44beaafc3c7b7ab8270b998169411c9e9d773a77b5c619d5d953e3c560c32b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / causaldisco-0.3.0-py3-none-any.whl

Download URL causaldisco-0.3.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6d66980b3d14952a5d451ab8ac7b330dbd6730d401fd054ca874564a69d550a
BLAKE2b-256 checksum
How to use checksums
42647ef3955e08fa4e549e48cd2dc1d20edf05ce12d5bcbf6eff68f0fa8458a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for CausalDisco 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page