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
0is ignored: only voxels labelled on both sides (and insidemask, when given) enter the contingency table. The score does not need a Hungarian remapping; permuting habitat ids leaves ARI unchanged.The work is one
bincountover those voxels plus anO(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.
0is 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 near0; identical partitions (up to id permutation) are1.NaNwhen fewer than two jointly labelled voxels remain.- Return type:
- Raises:
ValueError – If the arrays (or
mask) have different shapes.