otlingam.utils.shd

shd(adjacency_matrix_true, adjacency_matrix_pred)[source]

Computes structural Hamming distance between two directed graphs.

The adjacency matrices follow the LiNGAM convention, where entry (j, k) represents the directed edge \(k \to j\). A missing edge, an extra edge, and a reversed edge each contribute one unit to the structural Hamming distance.

Parameters:
  • adjacency_matrix_true (np.typing.ArrayLike) – Ground-truth weighted adjacency matrix.

  • adjacency_matrix_pred (np.typing.ArrayLike) – Estimated weighted adjacency matrix.

Returns:

Structural Hamming distance.

Return type:

int

Raises:

ValueError – If either matrix is not square or the shapes differ.