Abstract
Hierarchical clustering is a fundamental task often used to discover meaningful structures in data, such as phylogenetic trees, taxonomies of concepts, subtypes of cancer, and cascades of particle decays in particle physics. Typically approximate algorithms are used for inference due to the combinatorial number of possible hierarchical clusterings. In contrast to existing methods, we present novel dynamic-programming algorithms for exact inference in hierarchical clustering based on a novel trellis data structure, and we prove that we can exactly compute the partition function, maximum likelihood hierarchy, and marginal probabilities of sub-hierarchies and clusters. Our algorithms scale in time and space proportional to the powerset of $N$ elements which is super-exponentially more efficient than explicitly considering each of the (2N-3)!! possible hierarchies. Also, for larger datasets where our exact algorithms become infeasible, we introduce an approximate algorithm based on a sparse trellis that compares well to other benchmarks. Exact methods are relevant to data analyses in particle physics and for finding correlations among gene expression in cancer genomics, and we give examples in both areas, where our algorithms outperform greedy and beam search baselines. In addition, we consider Dasgupta's cost with synthetic data.
Introduction: The Combinatorial Explosion
Hierarchical clustering is a cornerstone of data science, used to reconstruct everything from evolutionary trees to the decay chains of subatomic particles. However, it suffers from a massive "combinatorial explosion." For a dataset of just 10 points, there are over 34 million possible binary tree structures; for 20 points, that number jumps to roughly $8 \times 10^{20}$.
Because the search space is so vast, researchers almost always rely on approximate algorithms like greedy agglomerative clustering (linkage methods) or beam search. These methods are fast but often get stuck in local optima and cannot provide a "partition function"—a value necessary to calculate the actual probability of a specific tree or to sample trees from a posterior distribution. This research aims to bridge the gap between "fast but heuristic" and "exact but impossible."
The Hierarchical Cluster Trellis
The core contribution of this work is the Hierarchical Cluster Trellis, a directed acyclic graph (DAG) where each vertex represents a subset of the data. By framing hierarchical clustering as an energy-based model, the authors use dynamic programming to recursively compute the partition function ($Z$) and the Maximum A Posteriori (MAP) tree.
While the number of possible trees is $(2N-3)!!$, the number of subsets is only $2^N$. The resulting algorithm runs in $O(3^N)$ time. While still exponential, it is "super-exponentially" more efficient than brute force, allowing for exact inference on small, critical datasets. The "aha moment" is realizing that you don't need to iterate over every tree to find the best one. By memoizing the best sub-trees for every possible subset of data, you can build the optimal global tree from the bottom up.
For larger datasets where $O(3^N)$ is too slow, the authors introduce a Sparse Trellis. This is "seeded" with a subset of promising hierarchies (generated by simulators or beam search). This sparse trellis allows the algorithm to explore a much richer space than a simple greedy search while remaining computationally feasible. Furthermore, the trellis structure allows for exact sampling of hierarchies directly from the posterior distribution in a top-down manner, ensuring that the probability of picking a tree is exactly proportional to its likelihood.
Experimental Results
The approach was evaluated across three distinct domains:
- Synthetic Data (Dasgupta’s Cost): Used to test the algorithm against a well-known theoretical cost function. The trellis identified an optimal tree with a cost of 40.08, whereas the greedy approach failed, yielding a cost of 44.08.
- Jet Physics (Ginkgo): Using the Ginkgo510 dataset (5,000 simulated "jets" with 5 to 10 leaves), the trellis consistently found hierarchies with higher log-likelihoods than beam search (improving by ~0.4) and greedy search (improving by ~1.5). Interestingly, a sparse trellis with a "sparsity index" of only 2% could nearly match the performance of the full, exact trellis.
- Cancer Genomics (pam50): On a real-world dataset of gene expression levels for breast cancer subtypes ($n=12$), the MAP tree produced a more consistent topology for certain cancer subtypes compared to greedy methods, potentially offering better insights into disease progression.
Conclusion and Future Work
The cluster trellis provides a powerful framework for exact inference in hierarchical clustering. For $N=20$, the trellis requires roughly $3 \times 10^9$ operations—a task easily handled by a modern laptop—whereas enumerating all trees would require $10^{22}$ operations.
However, the $O(3^N)$ complexity remains a limitation, making exact inference impractical for datasets much larger than $N=30$. Future work will explore better "building strategies" for sparse seeding and extensions to k-ary trees, where nodes can have more than two children.
Summary updated