adjusted_rand_index

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

adjusted_rand_index(reference: ndarray, moving: ndarray, *, mask: ndarray | None = None) → float[source]

Chance-corrected partition agreement (Hubert–Arabie ARI).

Compares two integer label maps on the same grid. Background 0 is ignored: only voxels labelled on both sides (and inside mask, when given) enter the contingency table. The score does not need a Hungarian remapping; permuting habitat ids leaves ARI unchanged.

The work is one bincount over those voxels plus an O(K^2) reduction of the contingency table, so typical ROI sizes (10⁴–10⁶ voxels, K ≤ 10) finish in milliseconds.

Parameters:
  • reference (np.ndarray) – Reference integer labels. 0 is background.

  • moving (np.ndarray) – Moving integer labels, same shape as reference.

  • mask (Optional[np.ndarray]) – Optional boolean ROI. When set, voxels outside it are dropped before the contingency is built.

Returns:

ARI in [-1, 1]. Random agreement is near 0; identical partitions (up to id permutation) are 1. NaN when fewer than two jointly labelled voxels remain.

Return type:

float

Raises:

ValueError – If the arrays (or mask) have different shapes.

Examples using habit.kernels.adjusted_rand_index

Precise voxel features

Precise voxel features