bnmetrics.protocol

GraphLike Protocol — the cross-package contract for graph input.

Classes

GraphLike

A graph backed by a square int8 endpoint-mark matrix.

Module Contents

class bnmetrics.protocol.GraphLike[source]

Bases: Protocol

A graph backed by a square int8 endpoint-mark matrix.

Conformance is duck-typed: any object that exposes the three attributes below satisfies the Protocol. No inheritance, no import of bnmetrics required. cbcd’s DAG, CPDAG, PAG instances conform with zero adaptation.

The required attributes are:

  • n_vars — number of variables (rows / columns of endpoints).

  • endpoints — square (n_vars, n_vars) endpoint-mark matrix following the bnmetrics.EndpointMark convention. Must be an attribute, not a property — bnmetrics metric code reads this in hot loops.

  • var_names — optional human-readable variable names; None means index-only.

endpoints: numpy.typing.NDArray[numpy.int8]
n_vars: int
var_names: tuple[str, Ellipsis] | None