otlingam.utils.disorder

disorder(adjacency_matrix_true, causal_order_pred)[source]

Counts true edges reversed by a causal order.

Let \(\hat{\sigma}\) be the estimated order. The disorder is given by

\[\begin{split}\begin{aligned} \mathrm{dis}(\hat{\sigma}) &= \#\left\{ (k, j) : B^\star_{jk} \neq 0, \\ &\quad \hat{\sigma}^{-1}(k) > \hat{\sigma}^{-1}(j) \right\}. \end{aligned}\end{split}\]

It is zero exactly when causal_order_pred is a topological order of the true DAG.

Parameters:
  • adjacency_matrix_true (np.typing.ArrayLike) – Ground-truth weighted adjacency matrix whose entry \(B_{jk}\) represents the edge \(k \to j\).

  • causal_order_pred (np.typing.ArrayLike) – Estimated node permutation from source to sink.

Returns:

Number of reversed true edges.

Return type:

int

Raises:

ValueError – If the matrix is not square or causal_order_pred is not a permutation.