Skip to main content

Baseline algorithms and analytics tools for Causal Discovery.

Project description

Latest version 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.

Baseline Algorithms

Find the following baseline algorithms in CausalDisco/baselines.py

  • R²-SortnRegress
  • Var-SortnRegress
  • Random-SortnRegress

Analytics Tools

Find the following analytics tools in CausalDisco/analytics.py

  • R²-sortability
  • Var-sortability
  • order_alignment

Sources

If you find our algorithms useful please consider citing

@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 36 (NeurIPS)}},
    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 34 (NeurIPS)}},
    year = {2021},
    doi = {10.48550/arXiv.2102.13647},
}

A Simple Example

# --- sample data from a linear SCM:

import numpy as np
from scipy import linalg

d = 10
W = np.diag(np.ones(d-1), 1)
X = np.random.randn(10000, d).dot(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,
    snr_sortability
)

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

# --- run baselines and print results:

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

print(
    f'True\n{W}\n'
    '--- randomRegress ---\n'
    f'Recovered:\n{1.0*(random_sort_regress(X)!=0)}\n'
    f'Recovered standardized:\n{1.0*(random_sort_regress(X_std)!=0)}\n'
    '--- varSortnRegress ---\n'
    f'Recovered:\n{1.0*(var_sort_regress(X)!=0)}\n'
    f'Recovered standardized:\n{1.0*(var_sort_regress(X_std)!=0)}\n'
    '--- r2SortnRegress ---\n'
    f'Recovered:\n{1.0*(r2_sort_regress(X)!=0)}\n'
    f'Recovered standardized:\n{1.0*(r2_sort_regress(X_std)!=0)}\n'
)

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

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

causaldisco-0.2.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

causaldisco-0.2.1-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file causaldisco-0.2.1.tar.gz.

File metadata

  • Download URL: causaldisco-0.2.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for causaldisco-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3c914efeaa3e47c98ddbf62d30b3a2f22a5dd4cdb06c5d97f957913470e9a964
MD5 c3f70d1d951cf3fac08489f1472ac2cd
BLAKE2b-256 3a0bb6cddbb143a609e165e51165ce5b377365cc19da414f8541e7c950002d25

See more details on using hashes here.

File details

Details for the file causaldisco-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: causaldisco-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for causaldisco-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bb6f68532f98b54d5a5245ef3ec324c71744b38346c0e97c585515e98e8f4eea
MD5 3f9e4cc44ba3656a809941aeb5a0adac
BLAKE2b-256 a94c361bafce2ca43e5c1f87e9bccaa1f6a0936d30737986d58b059cdd74fb51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page