StructuralMetrics.compare

StructuralMetrics.compare(*args)

Compare two graphs of the same type and equal size, populating the internal confusion matrix used by all metric accessors.

The following overloads are available:

  • compare(DiGraph, DiGraph) — nodes matched by NodeId (no alignment).

  • compare(UndiGraph, UndiGraph) — nodes matched by NodeId (no alignment).

  • compare(PDAG, PDAG) — nodes matched by NodeId (no alignment).

  • compare(BayesNet, BayesNet) — nodes matched by variable name; comparison runs on the corresponding essential graphs (CPDAGs).

  • compare(BayesNet, PDAG) — ref BN is converted to its essential graph first.

  • compare(PDAG, BayesNet) — test BN is converted to its essential graph first.

For a DAG-level comparison of two BayesNets, align NodeIds manually (e.g. by building an aligned BN by variable name) and call compare(DiGraph, DiGraph) with bn.dag(). SID (see sid()) is the only metric that natively operates on the DAGs of BayesNets.

Parameters:
  • ref – Reference graph (DiGraph, UndiGraph, PDAG, or BayesNet).

  • test – Graph to evaluate against the reference (same type as ref, or PDAG when ref is a BayesNet and vice-versa).

Raises:
Return type:

None

Example

import pyagrum as gum

ref = gum.fastDAG("A->B->C;A->D")
test = gum.fastDAG("A->B;C->B;A->D")  # B->C is reversed
sm = gum.StructuralMetrics()
sm.compare(ref, test)
sm.shd()
# 1.0
bn1 = gum.fastBN("A->B->C")
bn2 = gum.fastBN("C->B->A")  # same essential graph
sm.compare(bn1, bn2)
sm.shd()
# 0.0

Class

StructuralMetrics