BanditPAM++: Faster k-medoids Clustering

Mo Tiwari, Ryan Kang, Donghyun Lee, Sebastian Thrun, Chris Piech, Ilan Shomorony, Martin Jinye Zhang

Abstract

$k$-medoids clustering is a robust alternative to $k$-means, offering improved interpretability and flexibility with distance metrics. However, its computational cost has historically limited its application to large datasets. While BanditPAM reduced this complexity to $O(kn \log n)$, it still scaled linearly with the number of clusters $k$. This paper introduces BanditPAM++, which leverages a new theoretical framework—Sequential, Permutation-Invariant Multi-Armed Bandit (SPIMAB)—to eliminate the $k$ dependence. By utilizing Virtual Arms (VA) and Permutation-Invariant Caching (PIC), BanditPAM++ achieves a theoretical $O(k)$ speedup and up to 10x empirical speedup over state-of-the-art methods while maintaining identical clustering quality.

Introduction

Clustering is a fundamental task in data science, yet the ubiquitous $k$-means algorithm faces two significant limitations: interpretability and flexibility. In $k$-means, cluster centers are centroids—mathematical averages that often do not correspond to actual data points. Furthermore, $k$-means is generally restricted to Euclidean distance, making it unsuitable for non-vectorial data like text or graphs.

$k$-medoids clustering addresses these issues by requiring cluster centers (medoids) to be actual observations from the dataset and allowing for any arbitrary distance metric. Despite these advantages, $k$-medoids has been hindered by its computational intensity. The classic Partitioning Around Medoids (PAM) algorithm scales quadratically ($O(n^2)$) with the number of data points. Recent advancements like BanditPAM utilized multi-armed bandit theory to achieve nearly linear complexity ($O(kn \log n)$), but the scaling factor $k$ remained a bottleneck for large-scale applications with many clusters.

Methodology: The SPIMAB Framework

BanditPAM++ introduces a new theoretical structure called a Sequential, Permutation-Invariant Multi-Armed Bandit (SPIMAB). This framework enables two primary algorithmic innovations that significantly reduce the computational overhead of the "SWAP" phase, where the algorithm evaluates whether replacing a current medoid with a new candidate point reduces total loss.

1. Virtual Arms (VA)

In previous bandit-based approaches, every potential swap of a medoid for a candidate point was treated as an independent "arm" to be pulled. BanditPAM++ recognizes a fundamental redundancy: for a given candidate point, the change in loss is identical for $k-1$ of the medoids because most medoids are "far" from any specific point. By treating these as "virtual arms," the algorithm can update statistics for all $k$ potential swaps using a constant number of distance calculations. This effectively removes the $k$ factor from the complexity of the swap phase.

2. Permutation-Invariant Caching (PIC)

Iterative algorithms typically treat each step as a new problem. BanditPAM++ utilizes a fixed, random permutation of the dataset for sampling across iterations. Because the underlying data distribution remains constant, the algorithm can cache distance results. If a distance between two points is calculated in an early iteration, it can be instantly retrieved in subsequent iterations. This "information reuse" drastically reduces wall-clock runtime without compromising the statistical validity of the bandit mechanism.

Experimental Evaluation

The researchers evaluated BanditPAM++ against several benchmarks to demonstrate its versatility across different distance metrics:

  • MNIST: 70,000 handwritten digits using $L_2$ (Euclidean) distance.
  • CIFAR10: 60,000 color images using $L_1$ (Manhattan) distance.
  • 20 Newsgroups: Approximately 18,000 text posts using Cosine distance.

Key Results and Insights

The primary contribution of BanditPAM++ is its ability to deliver high-performance clustering without the "approximation" trade-off. It is mathematically guaranteed to return the same results as the original PAM algorithm with high probability.

  • Efficiency Gains: On the CIFAR10 dataset, BanditPAM++ demonstrated a 10x speedup over the original BanditPAM.
  • Complexity Reduction: The algorithm moves from $O(kn \log n)$ to $O(n \log n)$ per iteration. As the number of clusters ($k$) increases, the performance gap between BanditPAM++ and competing methods widens, making it the ideal choice for fine-grained clustering tasks.
  • Practical Accessibility: The authors have released a high-performance C++ implementation with Python and R wrappers, facilitating immediate adoption by the broader research community.

Limitations and Future Directions

While BanditPAM++ represents a significant leap forward, its performance is tied to the "arm gap"—the statistical margin between optimal and sub-optimal swaps. In datasets where many swaps yield nearly identical improvements, the bandit mechanism may require more samples to distinguish between them. Additionally, the theoretical guarantees assume that the distribution of distances is sub-Gaussian; while common in real-world data, extremely heavy-tailed distributions may impact performance.

Looking ahead, the SPIMAB framework suggests broader applications. The principles of virtual arms and permutation-invariant caching could potentially be applied to other iterative machine learning problems, such as hyperparameter optimization or feature selection, where redundant calculations currently limit scalability.

Summary updated

BibTeX
@inproceedings{tiwari2023banditpam,
  author = {Mo Tiwari and Ryan Kang and Donghyun Lee and Sebastian Thrun and Chris Piech and Ilan Shomorony and Martin Jinye Zhang},
  title = {{BanditPAM++: Faster k-medoids Clustering}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=4hiPRTXe9J},
}
Figure