

Hamming distances between two graphs
Source: R/metrics.R, R/jlbind-wrappers.R
Description
hd() is the skeleton Hamming distance: the number of node pairs on which cg1 and cg2 disagree about whether an edge is present, ignoring edge type and orientation. shd() is the Structural Hamming Distance: the number of node pairs on which they disagree at all, about the presence of an edge or about its marks, weighting both kinds of mismatch equally.
Usage
Arguments
cg1, cg2
|
Graphs created with cgraph(), of any class, with the same nodes.
|
normalized
|
If TRUE, divide by the number of node pairs, n * (n - 1) / 2, giving a value in [0, 1].
|
Details
The two graphs must have the same nodes, but may be of different classes. SHD was originally defined for PDAGs; shd() extends it naturally to any pair of graphs.
To compare causal discovery algorithms against a known true graph, first convert the truth to the class the algorithms estimate: dag_to_cpdag() for algorithms returning a CPDAG (such as PC), mag_to_pag() for ones returning a PAG (such as FCI). Otherwise edges the algorithm correctly leaves unoriented count as mistakes. If an estimate is an MPDAG built from background knowledge, apply the same knowledge to the true CPDAG with apply_background_knowledge().
Value
A number: the count of disagreeing node pairs, or its share of all node pairs if normalized = TRUE.
References
Tsamardinos I, Brown LE, Aliferis CF (2006). “The max-min hill-climbing Bayesian network structure learning algorithm.” Machine Learning, 65, 31–78. doi:10.1007/s10994-006-6889-7.