Efficient Centroid-Linkage Clustering

Mohammadhossein Bateni, Laxman Dhulipala, Willem Fletcher, Kishen N Gowda, D Ellis Hershkowitz, Rajesh Jayaram, Jakub Lacki

Hierarchical Agglomerative Clustering (HAC) is a staple of data science, found in every major library from SciPy to scikit-learn. It’s intuitive: start with every point in its own cluster and repeatedly merge the "closest" pairs until you have a single tree. However, HAC has a notorious "speed limit." For most versions, including Centroid-Linkage (where distance is measured between cluster centers), the algorithm takes $O(n^2)$ time. In a world of billion-point datasets, quadratic time is essentially a "do not enter" sign.

A paper presented at NeurIPS 2024, "Efficient Centroid-Linkage Clustering" by Bateni et al., provides a way to bypass this bottleneck. By allowing for a small amount of approximation, the authors deliver a subquadratic algorithm that is both theoretically grounded and blazingly fast in practice.

The Core Challenge: Non-Monotonicity and Adaptive Updates

The primary bottleneck of HAC is the "closest pair" problem. To merge the two closest clusters, you theoretically need to check all $O(n^2)$ possible pairs. In high-dimensional spaces, there is no known way to do this faster than quadratic time without making mistakes.

While approximation algorithms exist for other types of HAC (like Ward or Average-Linkage), Centroid-Linkage is uniquely difficult. In other methods, the distance between clusters usually stays the same or increases as you merge them. In Centroid-Linkage, the distance between two clusters can actually decrease after a merge.

An illustration of non-monotonicity in centroid-linkage: after merging two points at distance 1, a third point can be arbitrarily close ($\epsilon$) to the new centroid.

This "non-monotonic" behavior breaks many standard optimization tricks. Furthermore, most randomized data structures for finding nearest neighbors assume "oblivious" updates—meaning the points you add or delete don't depend on the answers the data structure just gave you. But HAC is the definition of adaptive: the next clusters you merge (the update) are chosen specifically because they were the result of the previous nearest-neighbor search (the query). This creates a feedback loop that can cause standard randomized algorithms to fail.

A Subquadratic Solution

The authors present the first subquadratic-time algorithm for $c$-approximate Centroid-Linkage HAC, running in roughly $n^{1+O(1/c^2)}$ time. They tackle the problem with a two-pronged approach:

  1. A New Meta-Algorithm: They designed a framework that reduces the HAC process to a sequence of dynamic Approximate Nearest Neighbor Search (ANNS) calls. Instead of searching for the absolute closest pair, the algorithm maintains a priority queue of "nearby" candidates and only refreshes them when necessary.
  2. Adaptive-Robust ANNS: This is the major theoretical contribution. They developed a "merge-and-reduce" data structure that uses "covering nets" (a way to represent space with a discrete set of points) to shield the algorithm from adaptive bias. This ensures that even if the merges depend on previous query results, the approximation guarantees hold.
Standard centroid-linkage merge sequence, demonstrating how new cluster centers are geometrically calculated.

For the empirical side, rather than using the theoretical LSH-based structure, they adapted DiskANN (Vamana), a state-of-the-art graph-based ANNS library. They introduced a clever "neighborhood union" strategy: when two clusters merge, the new centroid inherits and prunes the neighbors of its parents, avoiding a total re-index.

Key Results and Insights

The algorithm was tested on a wide variety of benchmarks, ranging from small UCI datasets to massive-scale sets like sift-1M (1 million points).

  • Massive Speedups: On a single core, the algorithm achieved up to a 36× speedup over the fastcluster library (a highly optimized exact baseline). When scaled to 192 cores, the speedup reached a staggering 175×.
  • High Fidelity: The results show that you don't need exact nearest neighbors to get a "good" hierarchy. Across all datasets, the Adjusted Rand Index (ARI) and Normalized Mutual Information (NMI) remained very high. For a typical approximation factor ($\epsilon = 0.1$), the scores were almost indistinguishable from the exact baseline (within 7%).
  • Handling Stale Merges: In their heap-based approach, many "closest pair" candidates in the queue become "stale" because one of the clusters involved gets merged into something else. They found that roughly 60% of merges are "stale," and handling these lazily is a massive contributor to their speedup.

Limitations and Future Work

While groundbreaking, the authors note a few limitations. First, there is a theory-practice gap: the $n^{1+O(1/c^2)}$ proof relies on Locality-Sensitive Hashing, while the practical experiments use faster, but harder-to-prove, Graph-based methods. Second, while the implementation is parallelized and shows great scaling, a "theoretically efficient" parallel algorithm for approximate centroid HAC remains an open question. Finally, the specific optimizations for non-monotonic distances are unique to Centroid-Linkage, though the adaptive ANNS structure itself could be applied more broadly.

Summary updated

BibTeX
@inproceedings{bateni2024efficient,
  author = {Mohammadhossein Bateni and Laxman Dhulipala and Willem Fletcher and Kishen N Gowda and D Ellis Hershkowitz and Rajesh Jayaram and Jakub Lacki},
  title = {{Efficient Centroid-Linkage Clustering}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=5VE1iLeYOz},
}
Figure