Skip to main content

causalbase

CI Docs PyPI Python DOI License

causalbase learns the structure of Bayesian networks from data. GES and XGES return the Markov equivalence class of the network; the searches over variable orders and over DAGs, and the exact search, return a single DAG; RCD returns the causal order and coefficients of a linear model with non-Gaussian noise, found from the higher-order cumulants of continuous data. Scores and graph routines are compiled with Numba, so GES learns a network of a thousand variables in seconds.

Estimator Data Search
GES Discrete (BDeu, BIC) or continuous (Gaussian BIC, BGe) Greedy equivalence search (Chickering, 2002)
XGES The same Extremely greedy equivalence search (Nazaret and Blei, 2024), which also deletes and reverses edges as it goes
OrderSearch The same Iterated local search over variable orders, each local search ended by GES or XGES
FLOP The same FLOP's search over orders (Wienöbst, Henckel and Weichwald, 2026)
HillClimbing The same Hill climbing or tabu search over DAGs, with restarts
ExactSearch The same The network of highest score, by dynamic programming, or the best one under a parent limit, by integer programming
RCD Continuous, linear with non-Gaussian noise The causal order from higher-order cumulants, then the coefficients by adaptive lasso; HC-LiNGAM and HC (Chen et al., 2025) are among its settings

Every estimator follows scikit-learn's conventions (hyperparameters in the constructor, fit to learn, results ending in an underscore) without depending on it, so clone, GridSearchCV and pipelines work, and score(X) is the log likelihood of held-out rows. BDeu comes with two structure priors, a Bernoulli prior on each possible parent and Tetrad 7.6.5's, whose scores it reproduces. Every estimator but RCD takes the score by name, criterion="bdeu" (the default), "bic", "gaussian_bic" or "bge", with the same score parameters, fit(X, initial_graph=None) and n_jobs.

Installation

pip install causalbase

causalbase needs Python 3.10 or later, NumPy, pandas and Numba. The integer program of ExactSearch under a parent limit also needs SCIP, through PySCIPOpt:

pip install "causalbase[exact]"

The kernels are compiled the first time they are used and cached on disk, so the first fit in a new environment takes a few seconds longer than the next ones.

Quick start

from causalbase import GES
from causalbase.datasets import load_alarm
from causalbase.metrics import shd

bundle = load_alarm()  # 37 variables, 5000 rows, bundled with the package

model = GES().fit(bundle.data)  # also takes a DataFrame or an array
model.adjacency_  # the learned CPDAG, with the variable names
shd(bundle.truth, model.dag_)  # structural Hamming distance to the true network

Every distinct value of a column is a level, so a numeric column is read as categories. Continuous data takes criterion="gaussian_bic" or criterion="bge", in any estimator.

Besides the five bundled networks, fetch_network downloads from Zenodo 100 samples of each of the 24 discrete networks of bnlearn's repository and of the 202 of bnRep, and keeps them in a local cache:

from causalbase.datasets import fetch_network

bundle = fetch_network("pathfinder", sample=3)  # data, true DAG and network

The searches over orders and over DAGs return one network:

from causalbase import OrderSearch

model = OrderSearch(polish="xges", time_limit=60, random_state=0).fit(bundle.data)
model.dag_, model.score_

Behind each estimator there is a function that takes the score and returns a SearchResult (dag and its class cpdag, score, n_iter, trace, info), for those who want to choose the starting point, the limits or the score object themselves:

from causalbase.order import order_search
from causalbase.scores import BDeuScore

score = BDeuScore(bundle.data, prior="tetrad")
result = order_search(score, polish="xges", max_iter=20, random_state=0)
result.dag, result.score, result.info["accepted"]

causalbase.order also has the pieces the order searches are built from (OrderScorer, InsertionSearch, IteratedLocalSearch, pair_polish), and causalbase.search.ges, xges and hill_climbing, causalbase.order.flop and causalbase.exact.exact_search are the functions behind the other estimators.

Speed

GES counts in compiled code, checks paths and completes the CPDAG over neighbour lists, and re-scores after each step only the part of the graph the step changed. On a laptop it learns andes (223 variables, 5000 rows) in under half a second and munin (1041 variables) in about 4 s; causal-learn's GES takes 53 s on alarm and does not finish andes in half an hour. The benchmarks have the full tables, for every estimator.

Documentation

Learning from data spread across sites that cannot share it is the job of fedcausal, which is built on causalbase.

Development

git clone https://github.com/ptorrijos99/causalbase
cd causalbase
pip install -e ".[dev]"
pytest

CONTRIBUTING.md has the checks a pull request must pass and how the tests are written; the documentation builds with pip install -e ".[docs]" and sphinx-build -b html docs docs/_build/html.

Citation

If you use causalbase in a scientific publication, please cite:

@software{causalbase,
  author = {Torrijos, Pablo and G{\'a}mez, Jos{\'e} A. and Puerta, Jos{\'e} M.},
  title = {causalbase: Bayesian network structure learning and causal discovery},
  year = {2026},
  doi = {10.5281/zenodo.24594415},
  url = {https://github.com/ptorrijos99/causalbase}
}

The DOI always resolves to the latest version; every release also has its own DOI on Zenodo. The same information is in CITATION.cff, which GitHub shows as "Cite this repository".

References

  • Zou, H. (2006). The adaptive lasso and its oracle properties. Journal of the American Statistical Association, 101(476), 1418-1429.
  • Chickering, D. M. (1995). A transformational characterization of equivalent Bayesian network structures. UAI '95, 87-98.
  • Chickering, D. M. (2002). Optimal structure identification with greedy search. Journal of Machine Learning Research, 3, 507-554.
  • Silander, T., & Myllymäki, P. (2006). A simple approach for finding the globally optimal Bayesian network structure. UAI '06.
  • Cussens, J. (2011). Bayesian network learning with cutting planes. UAI '11.
  • Bartlett, M., & Cussens, J. (2017). Integer linear programming for the Bayesian network structure learning problem. Artificial Intelligence, 244, 258-271.
  • Ramsey, J., Glymour, M., Sanchez-Romero, R., & Glymour, C. (2017). A million variables and more: the Fast Greedy Equivalence Search algorithm for learning high-dimensional graphical causal models. International Journal of Data Science and Analytics, 3(2), 121-129.
  • Nazaret, A., & Blei, D. (2024). Extremely greedy equivalence search. UAI 2024, PMLR 244, 2716-2745.
  • Chen, W., et al. (2025). Higher order cumulants-based method for direct and efficient causal discovery. IEEE Transactions on Neural Networks and Learning Systems.
  • Torrijos, P., Stella, F., Gámez, J. A., & Puerta, J. M. (2026). Federated causal discovery via regression-directed cumulants. Probabilistic Graphical Models (PGM 2026).
  • Wienöbst, M., Henckel, L., & Weichwald, S. (2026). Embracing discrete search: A reasonable approach to causal structure learning. ICLR 2026.

License

MIT. See LICENSE, and NOTICE for the bundled networks.

Metadata

Release files for causalbase 0.2.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 causalbase 0.2.0
File Size Uploaded Provenance Actions
causalbase-0.2.0.tar.gz 1.0 MB With provenance Details for causalbase-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.3 MB

Release files / causalbase-0.2.0.tar.gz

Download URL causalbase-0.2.0.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
b99ea37f3a08efba25881d6bd098172a07b0844e206e22b0a69814092f565a28
BLAKE2b-256 checksum
How to use checksums
e02e9b926ccee01852379d43957d5b26fc5606184f0ec0f0a832c5fe53a816d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / causalbase-0.2.0-py3-none-any.whl

Download URL causalbase-0.2.0-py3-none-any.whl
Size 330.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6e2b3d4a5b9936294f21074d36ea2b0f9c78ef88b05491571a99accf489b984
BLAKE2b-256 checksum
How to use checksums
0246fbd226cddfa0c2fb0ecdcf10c9b4e301dd418154ad3bf9313d1a77f2c87c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for causalbase 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for causalbase-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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