Skip to main content

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.

Python License: MIT Documentation

Features

  • Descriptive metricscount_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 metricsshd, hd, f1, precision, recall, true_positives, false_positives, false_negatives, count_additions, count_deletions, count_reversals.
  • Structural Intervention Distancesid() after Peters & Bühlmann (2015), returning the SID together with bounds for CPDAG comparison.
  • Markov-blanket scopingmarkov_blanket(g, var) returns a sub-GraphLike that can be passed back to any metric.
  • Multi-metric comparisoncompare(true, estimate) produces a Comparison exposing every descriptive and comparative metric in a single call, with optional pandas export.
  • Visualisation (optional viz extra) — 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

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

MIT

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

bnmetrics-0.2.2.tar.gz (632.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bnmetrics-0.2.2-py3-none-any.whl (44.4 kB view details)

Uploaded Python 3

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

Hashes for bnmetrics-0.2.2.tar.gz
Algorithm Hash digest
SHA256 736ca8a1aa9f9695fc6fe907356e84640fc5de0433a91c12b593faf71a0025d4
MD5 6cbace111170841f58f1517890f6fd3f
BLAKE2b-256 cbc9188bec7b94bd9c92111c4a7b213689892d0b074b023644e83ce8c1293f3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bnmetrics-0.2.2.tar.gz:

Publisher: release.yml on averinpa/constraint-based-causal-discovery-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for bnmetrics-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5f1b01112074b81e2107d5bf756a3a36a734305ea82ad848090e3a1a0756100
MD5 32b4ed8f13bd1e63376d25f2aa990b0d
BLAKE2b-256 3030d51aa89339b5657fe9f916c16668e80083b8016739afe4ec7024346c285c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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