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
Metadata
Release files for bnmetrics 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bnmetrics-0.2.2.tar.gz | 632.4 kB | With provenance | Details for bnmetrics-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bnmetrics-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for bnmetrics-0.2.2-py3-none-any.whl |
Total release size: 676.8 kB
Release files / bnmetrics-0.2.2.tar.gz
| Download URL | bnmetrics-0.2.2.tar.gz |
|---|---|
| Size | 632.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
736ca8a1aa9f9695fc6fe907356e84640fc5de0433a91c12b593faf71a0025d4
|
|
BLAKE2b-256 checksum How to use checksums |
cbc9188bec7b94bd9c92111c4a7b213689892d0b074b023644e83ce8c1293f3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 17, 2026.
Transparency logRelease files / bnmetrics-0.2.2-py3-none-any.whl
| Download URL | bnmetrics-0.2.2-py3-none-any.whl |
|---|---|
| Size | 44.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5f1b01112074b81e2107d5bf756a3a36a734305ea82ad848090e3a1a0756100
|
|
BLAKE2b-256 checksum How to use checksums |
3030d51aa89339b5657fe9f916c16668e80083b8016739afe4ec7024346c285c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 17, 2026.
Transparency logSecurity for bnmetrics 0.2.2
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.
Attestation for bnmetrics-0.2.2.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 May 17, 2026.
Transparency logA 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.