NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Ultrametric Cluster Hierarchies: I Want ‘em All!

Andrew Draganov, Pascal Weber, Rasmus Skibdahl Melanchton Jørgensen, Anna Beer, Claudia Plant, Ira AssentNeurIPS 2025

TL;DR

This paper reveals a surprising theoretical property: in ultrametric spaces (where distances satisfy the strong triangle inequality), NP-hard clustering problems like k-means and k-median can be solved optimally in the time it takes to sort $n$ values. The authors introduce the SHiP framework, which allows researchers to instantly generate and explore a vast library of optimal hierarchical clusterings once an initial data representation is built.

What Problem Does This Paper Address?

Clustering is often a tedious "guess and check" process. If you run HDBSCAN and it fails to find the right clusters, you might switch to k-means. If that fails, you might try Ward’s method. Each switch requires re-processing the data with a different, often computationally expensive, algorithm.

Furthermore, while hierarchical clustering is great for exploration, it is usually treated as distinct from "center-based" clustering (like k-means). Center-based methods are notoriously difficult (NP-hard) in general Euclidean space. The authors address this divide by showing that if we view our data through the lens of ultrametrics—distances where the distance between two points is determined by their lowest common ancestor in a tree—the complexity of these problems collapses, and the two worlds of clustering merge.

Methods

To bridge this gap, the authors introduce the SHiP (Similarity-Hierarchy-Partitioning) framework.

The SHiP Framework

The process follows three core steps:

  1. Fit an Ultrametric: Convert the dataset into a "relaxed ultrametric" representation. This is often done using structures like KD-trees, Cover trees, or the density-connectivity distance (dc-dist) used in HDBSCAN.
  2. Choose a Hierarchy: The paper proves that for any ultrametric, the optimal solutions for k-center, k-median, and k-means are themselves hierarchical. They provide an algorithm that reduces these tasks to a simple sorting problem over the tree's internal nodes.
  3. Extract a Partition: Once the hierarchy is built, users can use the "Elbow Method," thresholding, or stability objectives to pick the best flat partition.

The mathematical heavy lifting involves proving that $(k, z)$-clustering objectives (which generalize k-means and k-median) in an ultrametric can be reduced to the k-center problem in a relaxed ultrametric. In this specific geometry, the "farthest-first traversal" algorithm—usually just a 2-approximation in Euclidean space—becomes perfectly optimal.

Key Insights and Ideas

  • Clustering as Sorting: The most profound insight is that in an ultrametric, finding the optimal centers for all possible values of $k$ (from 1 to $n$) takes only $O(n \log n)$ time. Essentially, the "best" clusters are just the branches of the tree sorted by their "cost-decrease" value.
  • "Free" Exploration: Because the hierarchy construction is so fast, a user can compute one ultrametric and then instantly "flip" between a k-means view, a k-median view, and a density-based view of the same data.
  • Guaranteed Convexity: The authors prove that in this setting, the "Elbow Plot" (cost vs. number of clusters) is guaranteed to be convex. This removes the ambiguity often found in standard k-means elbow plots, making it much easier to automatically select the "correct" number of clusters.
  • Relaxed Ultrametrics: By allowing $d(x, x) > 0$, the authors extend classical ultrametric theory to include density-based methods, where the "distance" of a point to itself can represent the local density.

Key Results

  • Speed: The efficiency gains are massive. While fitting the initial ultrametric takes a few seconds, building the k-means hierarchy and extracting the partition takes mere milliseconds.
Execution Time Comparison
  • Performance: SHiP-derived clusterings consistently matched or outperformed state-of-the-art algorithms across 2D synthetic data, tabular data, and image benchmarks. For example, on the Boxes dataset, the DC-tree with k-median achieved an Adjusted Rand Index (ARI) of 99.3, significantly beating standard Euclidean k-means (93.5) and AMD-DBSCAN (63.9).
  • Efficiency: The authors showed that their algorithm is "tight"—you cannot find all optimal solutions faster than the time it takes to sort the values.

Limitations and Future Work

  • Dependence on the Initial Metric: The quality of the final clustering is heavily dependent on the quality of the initial ultrametric. If the KD-tree or Cover tree doesn't capture the data's structure well, the optimal k-means solution on that tree will still be poor.
  • The Bottleneck: While the clustering is fast, fitting the initial ultrametric remains the computational bottleneck ($O(n^2)$ for some high-quality metrics).
  • Future Directions: The authors suggest that future research should focus on developing faster algorithms for fitting ultrametrics that more accurately model complex, high-dimensional data distributions. They also hint at potential connections to spectral clustering.

Summary updated

BibTeX
@inproceedings{draganov2025ultrametric,
  author = {Andrew Draganov and Pascal Weber and Rasmus Skibdahl Melanchton Jørgensen and Anna Beer and Claudia Plant and Ira Assent},
  title = {{Ultrametric Cluster Hierarchies: I Want ‘em All!}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=E0033NpFm0},
}
Figure