Cluster Trellis: Data Structures & Algorithms for Exact Inference in Hierarchical Clustering

Sebastian Macaluso, Craig S. Greenberg, Nicholas Monath, Ji Ah Lee, Patrick Flaherty, Kyle Cranmer, Andrew McGregor, Andrew McCallumAISTATS 2021

Abstract

Hierarchical clustering is a fundamental task often used to discover meaningful structures in data. Due to the combinatorial number of possible hierarchical clusterings, approximate algorithms are typically used for inference. 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 out-performs greedy and beam search baselines.

Introduction

Hierarchical clustering is a cornerstone of data science, used to map everything from the evolution of species to the decay of subatomic particles. However, the number of possible ways to build a tree grows at a staggering rate—specifically $(2N-3)!!$ for $N$ items. For just 20 data points, there are over $10^{22}$ possible trees. Because of this combinatorial explosion, researchers usually settle for "good enough" greedy algorithms or approximate simulations.

A new approach, the Cluster Trellis, enables exact inference—finding the absolute best tree and calculating total probabilities—without checking every single tree. By shifting the focus from the space of all trees to the space of all possible clusters, the complexity is reduced from double-factorial to $O(3^N)$, making exact solutions feasible for small datasets and providing a powerful sparse approximation for larger ones.

The Cluster Trellis Framework

The core innovation is the Cluster Trellis, a dynamic programming data structure. Instead of representing every tree, the trellis is a Directed Acyclic Graph (DAG) where each node represents a unique subset (cluster) of the data. Edges represent parent-child relationships.

The mapping from a specific hierarchical tree to its representation within the Cluster Trellis.

Dynamic Programming for Exact Inference

The partition function $Z(X)$ and the Maximum A Posteriori (MAP) tree can be computed recursively. Because many different trees share the same sub-clusters, the trellis allows for "memoization" (saving) the results of sub-problems. This recursive structure is what allows the algorithm to bypass the exhaustive enumeration of trees.

Comparison between exhaustive computation and the efficient trellis-based recursive approach.

For $N > 20$, where the full trellis becomes computationally expensive, a Sparse Trellis can be used. By seeding the trellis with nodes from several approximate trees (e.g., from a beam search), the algorithm considers every possible tree that can be formed using those specific clusters. This often discovers "hybrid" trees that are superior to any of the individual seeds.

Evaluation and Results

The authors evaluated the Cluster Trellis on three distinct types of data:

  • Synthetic Benchmarks: On Dasgupta’s Cost Synthetic Graph, the trellis found the optimal tree (cost 40.08) while standard greedy methods failed (cost 44.08).
  • Jet Physics: Using the Ginkgo dataset, which simulates subatomic particle showers, the trellis-based MAP consistently outperformed beam search and greedy methods in recovering the true latent decay structure.
  • Cancer Genomics: In the pam50 dataset, the exact MAP tree provided a more consistent and biologically plausible clustering of cancer subtypes compared to greedy agglomerative methods.

The results demonstrate that a sparse trellis with a "sparsity index" of only ~2% can achieve near-exact performance, significantly outperforming traditional search baselines.

Conclusion and Future Work

The Cluster Trellis provides a mathematically rigorous way to perform exact inference in hierarchical clustering. While the $O(3^N)$ complexity limits the exact method to approximately $N=20$ on modern hardware, the sparse trellis extension offers a scalable and high-performance alternative for larger datasets. Future work may involve extending the framework to k-ary trees and optimizing the strategies for seeding sparse trellises.

Code is available at: https://github.com/SebastianMacaluso/ClusterTrellis

Summary updated

BibTeX
@inproceedings{macaluso2021cluster,
  author = {Sebastian Macaluso and Craig S. Greenberg and Nicholas Monath and Ji Ah Lee and Patrick Flaherty and Kyle Cranmer and Andrew McGregor and Andrew McCallum},
  title = {{Cluster Trellis: Data Structures \& Algorithms for Exact Inference in Hierarchical Clustering}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2021},
  url = {https://openreview.net/forum?id=BqviNeKIb9},
}
Figure