The Adjusted Rand Index (ARI) quantifies how similar two different groupings (clusterings) of the same set of items are — for example, comparing a k-means clustering of the DCA latent space against the known, ground-truth cell type labels.
The basic idea (Rand Index, before adjustment): For every pair of items (e.g. every pair of cells), check whether the two clusterings agree on whether they belong to the same cluster or to different clusters. The Rand Index is simply the fraction of pairs on which the two clusterings agree.
Why “adjusted”? Even two completely random, unrelated clusterings will agree on many pairs purely by chance — especially when there are only a few clusters. The Adjusted Rand Index corrects for this chance agreement.
Given a contingency table with entries \(n_{ij}\) (number of items placed in cluster \(i\) by the first clustering and group \(j\) by the second), row sums \(a_i = \sum_j n_{ij}\), column sums \(b_j = \sum_i n_{ij}\), and total \(n\):
\[
\text{ARI} = \frac{\displaystyle\sum_{ij} \binom{n_{ij}}{2} - \left[\sum_i \binom{a_i}{2} \sum_j \binom{b_j}{2}\right] \Big/ \binom{n}{2}}{\dfrac{1}{2}\left[\sum_i \binom{a_i}{2} + \sum_j \binom{b_j}{2}\right] - \left[\sum_i \binom{a_i}{2} \sum_j \binom{b_j}{2}\right] \Big/ \binom{n}{2}}
\]
Each \(\binom{\cdot}{2}\) term counts pairs of items: \(\sum_{ij}\binom{n_{ij}}{2}\) counts pairs that fall in the same group under both clusterings, while the row/column sums count pairs that fall in the same group under each clustering individually. The formula subtracts off the number of co-occurring pairs expected purely by chance, and normalizes so that:
\[
\text{ARI} = 1 \quad \Rightarrow \quad \text{perfect agreement between the two clusterings}
\] \[
\text{ARI} = 0 \quad \Rightarrow \quad \text{agreement no better than expected from two random clusterings}
\] \[
\text{ARI} < 0 \quad \Rightarrow \quad \text{agreement worse than random (rare in practice)}
\]
In this exercise: A high k-means ARI against seurat_annotations means that clustering the latent space alone (without ever seeing the true cell type labels during training) recovers groups that closely match the real, biologically known cell types — evidence that the autoencoder has learned meaningful structure rather than just noise.