API reference

andrey.metrics.score#

andrey.metrics.score(output, truth)[source]#

Score an estimated result against ground truth with the family-appropriate metrics.

output and truth may each be a StructureOutput, a Structure, or a raw adjacency, and must index the same variables in the same order (a label or node-count mismatch raises). A latent structure is scored on its clustering alone, since latent node indices are not aligned across the two graphs; CDNOD’s appended domain node and similar extra variables must be dropped by the caller first.

Returns:

A flat, JSON-safe dict whose family names the structures’ kind. Every metric whose inputs both structures carry is present; the rest are absent.

  • Every graph: skeleton_precision, skeleton_recall, skeleton_f1, arrowhead_precision, arrowhead_recall, arrowhead_f1, and shd.

  • dag adds mec_shd and mec_arrowhead_f1, scored through the CPDAGs for methods identified only up to their equivalence class, and order_* and coefficient_mae when an ordering or weights are present.

  • pag adds shd_endpoint and confounder_precision, confounder_recall, and confounder_f1.

  • digraph keeps the base metrics only: it has no CPDAG, and a 2-cycle claims no latent confounder. Comparing a digraph with a pag raises.

  • latent: latent_cluster_ari, n_latents_estimated, and n_latents_true.

  • temporal: per_lag, contemporaneous, lagged, and summary, each nested, plus coefficient_mae_per_lag.

Return type:

dict[str, object]

Examples

>>> import numpy as np
>>> score(np.array([[0, 1], [0, 0]]), np.array([[0, 1], [0, 0]]))["family"]
'dag'