causaldag.classes.dag.DAG.shd

DAG.shd(other) → int[source]

Compute the structural Hamming distance between this DAG and the DAG other.

Parameters:other – the DAG to which the SHD will be computed.
Returns:The structural Hamming distance between G_1 and G_2 is the minimum number of arc additions, deletions, and reversals required to transform G_1 into G_2 (and vice versa).
Return type:int

Example

>>> import causaldag as cd
>>> g1 = cd.DAG(arcs={(1, 2), (2, 3)})
>>> g2 = cd.DAG(arcs={(2, 1), (2, 3)})
>>> g1.shd(g2)
1