Skip to main content

BCSL Python

Python port of the Bootstrap-based Causal Structure Learning Algorithm. Depends on the causal-learn package for scoring.

Installation

pip install bcsl-python causal-learn

Usage

import numpy as np

from bcsl import BCSL

# Generate synthetic data for testing
n_samples = 200

# Independent variables
Var1 = np.random.normal(0, 1, n_samples)
Var2 = np.random.normal(0, 1, n_samples)

# Dependent variables
Var3 = 2 * Var1 + np.random.normal(0, 1, n_samples)  # Var3 depends on Var1
Var4 = 0.5 * Var2 + np.random.normal(0, 1, n_samples)  # Var4 depends on Var2
Var5 = (
        Var3 + Var4 + np.random.normal(0, 1, n_samples)
)  # Var5 depends on Var3 and Var4
data = pd.DataFrame(
    {"Var1": Var1, "Var2": Var2, "Var3": Var3, "Var4": Var4, "Var5": Var5}
)
bcsl = BCSL(data, num_bootstrap_samples=4)

# Step 1: Learn local skeletons using HITON-PC
local_skeletons = bcsl.learn_local_skeleton()
print("Local Skeletons:", local_skeletons)

# Step 2: Resolve asymmetric edges using bootstrap
undirected_graph = bcsl.combine_local_to_global_skeleton()
print("Global Skeleton (resolved):", bcsl.global_skeleton)
print("Undirected Graph:", undirected_graph)

# Step 3: Orient edges using BDeu and hill-climbing
dag = bcsl.orient_edges()
print("Final DAG:", dag)

Reference

Xianjie Guo, Yujie Wang, Xiaoling Huang, Shuai Yang, and Kui Yu. 2022. Bootstrap-based Causal Structure Learning. In Proceedings of the 31st ACM International Conference on Information & Knowledge Management (CIKM '22). Association for Computing Machinery, New York, NY, USA, 656–665. https://doi.org/10.1145/3511808.3557249

Metadata

Release files for bcsl-python 0.8.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 bcsl-python 0.8.0
File Size Uploaded
bcsl_python-0.8.0.tar.gz 19.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bcsl-python 0.8.0
File Interpreter ABI Platform
bcsl_python-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.5 kB

Release files / bcsl_python-0.8.0.tar.gz

Download URL bcsl_python-0.8.0.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5f6d8186d6839b2d2adeeba57b8be459fc7fa47921a1f56e08209ab113bb405e
BLAKE2b-256 checksum
How to use checksums
3f4e452397c74a7535104aba9563268487b319ceafde7a7ca4aa49613f05aebb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / bcsl_python-0.8.0-py3-none-any.whl

Download URL bcsl_python-0.8.0-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
703d7a7aab610ca1c1f006191e4eaa0b9ce543fc23c86f7455bfd56fee10c729
BLAKE2b-256 checksum
How to use checksums
bbebae6372cb2812f5c72705da06acb2e6849f0b6e3543b247ec7c42fefba3bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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