otlingam.utils.disorder

disorder(causal_order, adjacency_matrix)[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 is a topological order of the true DAG.

Parameters:
  • causal_order (np.typing.ArrayLike) – Node permutation from source to sink.

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

Returns:

Number of reversed true edges.

Return type:

int

Raises:

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