Structural comparison metrics
- class pyagrum.StructuralMetrics
Compares two graphs of the same type and size, computing precision, recall, F-score, SHD and SID metrics at both the skeleton level (ignoring orientation) and the arc/edge level (including orientation).
After calling
compare(), the confusion-matrix accessors (tp(),fp(),fn(),tn()and their_skeletonvariants) become available, as do all derived metrics.- StructuralMetrics() -> StructuralMetrics
default constructor
Example
import pyagrum as gum
ref = gum.fastBN("A->B->C;A->C")
test = gum.fastBN("A->B;C->B;A->C")
comp = gum.StructuralMetrics()
comp.compare(ref, test)
comp.precision()
# 1.0
comp.sid(ref, test)
# 2.0
Scientific notes
StructuralMetrics compares a learned graph to a reference one. Each pair of nodes is classified by its state in the reference and in the learned graph (arc, undirected edge, or nothing; Bayesian networks are compared through their essential graphs). For the graph, a true positive is a pair with the same arc or the same edge; a false positive a pair linked in the learned graph but not in the same way (extra link, wrong orientation, arc instead of edge or the reverse); a false negative a missing link. The skeleton measures ignore the orientations. Precision, recall and F-score follow (\(F = 2PR/(P+R)\), 0 when undefined).
The structural Hamming distance (SHD) is the number of pairs counted as false positives or false negatives, i.e. the number of additions, removals and changes of orientation that turn one graph into the other [1]. The structural intervention distance (SID) [2] counts, between two DAGs, the ordered pairs \((i, j)\) for which adjusting on the parents of \(i\) in the learned DAG does not give the effect of an intervention on \(i\) on \(j\) in the reference DAG; it is asymmetric, and 0 when the learned DAG is the reference with more arcs.
Methods
Compare two graphs of the same type and equal size, populating the internal confusion matrix used by all metric accessors. |
|
F1-score at the arc/edge level: harmonic mean of precision and recall. |
|
F1-score at the skeleton level: harmonic mean of skeleton precision and recall. |
|
Number of false negatives at the arc/edge level (arcs/edges present in ref but missing from test). |
|
Number of false negatives at the skeleton level (undirected edges present in the ref skeleton but missing from the test skeleton). |
|
Number of false positives at the arc/edge level (extra or misoriented arcs/edges in the test graph). |
|
Number of false positives at the skeleton level (extra undirected edges in the test skeleton). |
|
Precision at the arc/edge level (orientation included): TP / (TP + FP). |
|
Precision at the skeleton level: TP / (TP + FP). |
|
Recall at the arc/edge level (orientation included): TP / (TP + FN). |
|
Recall at the skeleton level: TP / (TP + FN). |
|
Structural Hamming Distance: number of arc/edge insertions, deletions and reversals needed to transform the test graph into the ref graph. |
|
Structural Hamming Distance at the skeleton level: number of edge insertions and deletions needed to transform the test skeleton into the ref skeleton. |
|
Compute the Structural Intervention Distance (SID) between two DAGs. |
|
Number of true negatives at the arc/edge level (pairs correctly absent from both ref and test). |
|
Number of true negatives at the skeleton level (pairs correctly absent from both ref and test skeletons). |
|
Number of true positives at the arc/edge level (correctly predicted arcs or edges, orientation included for directed graphs). |
|
Number of true positives at the skeleton level (undirected edges correctly predicted, ignoring orientation). |
See also
pyagrum.lib.bn_vs_bn.GraphicalBNComparatora higher-level, Bayesian-network-oriented wrapper around
pyagrum.StructuralMetrics(see Comparison of Bayesian networks).
References of the members
Jonas Peters and Peter Bühlmann. Structural intervention distance for evaluating causal graphs. Neural Computation, 27(3):771–799, 2015. URL: https://arxiv.org/abs/1306.1043, doi:10.1162/NECO_a_00708.