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.1.2.tar.gz (84.9 kB view details)

Uploaded Source

Built Distribution

rcd-0.1.2-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rcd-0.1.2.tar.gz
  • Upload date:
  • Size: 84.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.3.0

File hashes

Hashes for rcd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7e53170ca1957a25af0c6d42cea87cddbb6d6159f447d719ab1085375fd435cc
MD5 b6831141b0e96fb931c6d5cb296803af
BLAKE2b-256 79cad72ba02d3c43d5d1b379c32a0c1564bcf0b01930c7b294909b5985b04968

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rcd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.2 Darwin/23.3.0

File hashes

Hashes for rcd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7283c434dd022ec222cb454f5974029b14f69d3a3448301537de7fb504a8439f
MD5 d526a211d2f6f558f6d7c0964bbf724b
BLAKE2b-256 d9984374e23d41f596e13516baddf92208e3688bb37f9d8f934f8e76a1c2068c

See more details on using hashes here.

Supported by

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