Skip to main content

Recursive causal discovery framework

Project description

Welcome to RCD

RCD is a Python library for Recursive Causal Discovery. This package provides efficient implementations of algorithms that recursively learn a causal graph from observational data. RCD focuses on user-friendliness with a well-documented and uniform interface. Moreover, its modular design allows for the integration and expansion of other algorithms and models within the package.

How to cite:

If you use RCD in a scientific publication, we would appreciate citations to the following paper:

Mokhtarian, Ehsan, Sepehr Elahi, Sina Akbari, and Negar Kiyavash. "Recursive Causal Discovery." arXiv preprint arXiv:2403.09300 (2024).

Link to the paper: arXiv

BibTeX entry:

@article{mokhtarian2024recursive,
  title={Recursive Causal Discovery},
  author={Mokhtarian, Ehsan and Elahi, Sepehr and Akbari, Sina and Kiyavash, Negar},
  journal={arXiv preprint arXiv:2024},
  year={2024}
}

GitHub:

The source code is available on GitHub.

Website:

Documentation are available on RCD website.

Installation

The package is available on PyPI and can be installed using pip:

pip install rcd

Basic usage

The following snipped creates a random directed acyclic graph (DAG) and generates Gaussian data from it. Then, it uses one of the algorithms provided in our package, RSL-D, to learn the skeleton of the DAG from the data. Finally, it compares the learned skeleton to the true skeleton and computes the F1 score based on the edges.

from rcd import RSLDiamondFree
from rcd.utilities.ci_tests import *
from rcd.utilities.data_graph_generation import *
from rcd.utilities.utils import f1_score_edges

n = 100
p = n ** (-0.85)
adj_mat = gen_er_dag_adj_mat(n, p)

# generate data from the DAG
data_df = gen_gaussian_data(adj_mat, 1000)

# run rsl-D
ci_test = lambda x, y, z, data: fisher_z(x, y, z, data, significance_level=2 / n ** 2)
rsl_d = RSLDiamondFree(ci_test)

learned_skeleton = rsl_d.learn_and_get_skeleton(data_df)

# compare the learned skeleton to the true skeleton
true_skeleton = nx.from_numpy_array(adj_mat, create_using=nx.Graph)

# compute F1 score
precision, recall, f1_score = f1_score_edges(true_skeleton, learned_skeleton, return_only_f1=False)
print(f'Precision: {precision}, Recall: {recall}, F1 score: {f1_score}')

License

This project is provided under the BSD license.

BSD 2-Clause License

Copyright (c) 2024, EPFL
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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

rcd-0.2.1.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

rcd-0.2.1-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rcd-0.2.1.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/24.2.0

File hashes

Hashes for rcd-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7a229b4dd8f771e947286ceae97edd199ba29dedbc3f2d813c3df8bf0287f362
MD5 d19f644df616e851c73e08459bf5e17f
BLAKE2b-256 aa30bed2c2084e771ea742604e1fde183402dc8ecbd20ff753feebc39ec26708

See more details on using hashes here.

File details

Details for the file rcd-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: rcd-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/24.2.0

File hashes

Hashes for rcd-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f04b8b8bdef0e1d63f6d72848b41fc61afbd0d9c73020aac293022a5f8a69441
MD5 9251df7bc0f642a2d2030e09c1455005
BLAKE2b-256 41dc241deb080edf231fe3c6c7e441f83c3fa092f02487dc0633aafd4e0b89e8

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