Bayesian network metrics: SHD, F1, SID, and per-Markov-blanket comparisons over DAGs, CPDAGs, and PAGs.
Project description
bnmetrics: Bayesian Network Metrics
bnmetrics is a Python library for evaluating, comparing, and visualising
DAGs, CPDAGs, and PAGs — descriptive structural metrics, comparative
metrics including SHD, HD, F1, and SID, and Markov-blanket-scoped
analysis, with optional graphviz and plotly visualisations.
bnmetrics is part of the constraint-based causal discovery
suite
alongside cbcd (algorithms), citk (CI tests), and dagsampler
(simulator). Any object satisfying the bnmetrics.GraphLike Protocol —
including cbcd's DAG, CPDAG, and PAG instances — drives every
metric without imports between the packages.
Features
- Descriptive metrics —
count_edges,count_nodes,count_colliders,count_root_nodes,count_leaf_nodes,count_isolated_nodes,count_directed_arcs,count_undirected_arcs,count_bidirected_arcs,count_circle_edges,count_reversible_arcs,in_degree,out_degree. - Comparative metrics —
shd,hd,f1,precision,recall,true_positives,false_positives,false_negatives,count_additions,count_deletions,count_reversals. - Structural Intervention Distance —
sid()after Peters & Bühlmann (2015), returning the SID together with bounds for CPDAG comparison. - Markov-blanket scoping —
markov_blanket(g, var)returns a sub-GraphLikethat can be passed back to any metric. - Multi-metric comparison —
compare(true, estimate)produces aComparisonexposing every descriptive and comparative metric in a single call, with optional pandas export. - Visualisation (optional
vizextra) — side-by-side graphviz comparison with true-positive highlighting and a plotly heatmap for SID's incorrect-edge matrix.
Installation
pip install bnmetrics # core (numpy only)
pip install bnmetrics[viz] # + graphviz, plotly, ipython
pip install bnmetrics[networkx] # + networkx (DiGraph adapter input)
pip install bnmetrics[pandas] # + pandas (compare().to_dataframe())
Documentation
- Full documentation is hosted on GitHub Pages.
- Examples — runnable Jupyter notebooks.
- CHANGELOG.
Acknowledgements
bnmetrics is the Python successor to
DAGMetrics, an R package by
the same author for analysing Bayesian networks in microbial
abundance data (Averin et al.,
2025). The metric
definitions — Hamming distance, structural Hamming distance, F1,
additions / deletions / reversals, reversible-arc counts, the
Markov-blanket subgraph construction — are derivative of the R
original.
The Structural Intervention Distance follows Peters & Bühlmann (2015); the implementation operates directly on the int8 endpoint-mark matrix used throughout the suite.
bnmetrics v0.2.x is a full Python rewrite around a canonical (n, n)
int8 endpoint-mark matrix matching cbcd's representation.
Cross-package interop with cbcd and dagsampler is via the
structural bnmetrics.GraphLike Protocol — no imports between the
packages.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bnmetrics-0.2.2.tar.gz.
File metadata
- Download URL: bnmetrics-0.2.2.tar.gz
- Upload date:
- Size: 632.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
736ca8a1aa9f9695fc6fe907356e84640fc5de0433a91c12b593faf71a0025d4
|
|
| MD5 |
6cbace111170841f58f1517890f6fd3f
|
|
| BLAKE2b-256 |
cbc9188bec7b94bd9c92111c4a7b213689892d0b074b023644e83ce8c1293f3d
|
Provenance
The following attestation bundles were made for bnmetrics-0.2.2.tar.gz:
Publisher:
release.yml on averinpa/constraint-based-causal-discovery-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bnmetrics-0.2.2.tar.gz -
Subject digest:
736ca8a1aa9f9695fc6fe907356e84640fc5de0433a91c12b593faf71a0025d4 - Sigstore transparency entry: 1562066905
- Sigstore integration time:
-
Permalink:
averinpa/constraint-based-causal-discovery-suite@f4f3c2b6313a9da2a08831df5f78dcafcd90740d -
Branch / Tag:
refs/tags/bnmetrics-v0.2.2 - Owner: https://github.com/averinpa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f4f3c2b6313a9da2a08831df5f78dcafcd90740d -
Trigger Event:
push
-
Statement type:
File details
Details for the file bnmetrics-0.2.2-py3-none-any.whl.
File metadata
- Download URL: bnmetrics-0.2.2-py3-none-any.whl
- Upload date:
- Size: 44.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5f1b01112074b81e2107d5bf756a3a36a734305ea82ad848090e3a1a0756100
|
|
| MD5 |
32b4ed8f13bd1e63376d25f2aa990b0d
|
|
| BLAKE2b-256 |
3030d51aa89339b5657fe9f916c16668e80083b8016739afe4ec7024346c285c
|
Provenance
The following attestation bundles were made for bnmetrics-0.2.2-py3-none-any.whl:
Publisher:
release.yml on averinpa/constraint-based-causal-discovery-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bnmetrics-0.2.2-py3-none-any.whl -
Subject digest:
e5f1b01112074b81e2107d5bf756a3a36a734305ea82ad848090e3a1a0756100 - Sigstore transparency entry: 1562066993
- Sigstore integration time:
-
Permalink:
averinpa/constraint-based-causal-discovery-suite@f4f3c2b6313a9da2a08831df5f78dcafcd90740d -
Branch / Tag:
refs/tags/bnmetrics-v0.2.2 - Owner: https://github.com/averinpa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f4f3c2b6313a9da2a08831df5f78dcafcd90740d -
Trigger Event:
push
-
Statement type: