EKM: An exact, polynomial-time algorithm for the k-medoids problem

Xi He, Max A. LittlearXiv 2024 · DOI

Abstract Clustering is a fundamental task in data science, with the $K$-medoids problem serving as a robust alternative to $K$-means due to its resilience to outliers and flexibility with distance metrics. However, finding the global optimum for $K$-medoids is a known combinatorial challenge. Traditionally, practitioners have chosen between fast but non-optimal heuristics or exact solvers with exponential worst-case runtimes. This paper introduces EKM, the first rigorously proven polynomial-time algorithm for the $K$-medoids problem. By employing functional programming techniques such as shortcut fusion, EKM achieves a worst-case time complexity of $O(N^{K+1})$, providing a predictable and scalable path to global optimality.

Introduction

In the landscape of unsupervised learning, $K$-medoids clustering stands out by requiring cluster centers (medoids) to be actual data points from the input set. This constraint ensures that the centers are interpretable and allows the algorithm to operate on any dissimilarity measure. Despite these advantages, the search space for $K$ medoids among $N$ points is $\binom{N}{K}$, leading to an explosion of possibilities as datasets grow.

Historically, the field has relied on heuristics like Partitioning Around Medoids (PAM) or CLARANS. While efficient, these methods offer no guarantee of reaching the global minimum. Conversely, exact solvers based on Branch-and-Bound techniques guarantee optimality but suffer from exponential time complexity, making them impractical for datasets beyond a few hundred points. EKM bridges this gap by offering an exact solution within a polynomial time framework.

Methodology: Correctness by Construction

Unlike traditional algorithms derived through iterative refinement, EKM was developed using transformational programming and the Bird-Meertens formalism. The authors started with a high-level "generate-evaluate-select" specification:

  1. Generate all possible combinations of $K$ medoids.
  2. Evaluate the total cost (sum of distances to the nearest medoid) for each combination.
  3. Select the combination with the minimum total cost.

To make this specification efficient, the researchers applied shortcut fusion (or semiring fusion). This technique mathematically collapses the three stages into a single recursive function. By fusing the selection and evaluation logic directly into the generation process, the algorithm can discard sub-optimal partial solutions early. This transformation results in a space complexity of $O(N^{K-1})$ and a time complexity of $O(N^{K+1})$. Because the algorithm is derived through formal logical steps, it is provably correct by construction.

Empirical Results

The researchers evaluated EKM against 18 real-world datasets from the UCI Machine Learning Repository and various synthetic datasets. The scale of testing reached $N=5,000$, significantly exceeding the $N \approx 150$ limit typical of previous exact solver literature.

Performance of EKM vs. heuristic methods on UCI datasets.

As shown in the table above, EKM consistently matched or improved upon the objective values found by approximate algorithms. While heuristics like PAM often find the global optimum on standard datasets, EKM provides the necessary mathematical proof of that optimality. In several instances, EKM identified lower-cost solutions that heuristics missed, particularly on more complex data distributions.

Performance Scaling

A key contribution of this work is the empirical verification of EKM's polynomial complexity. In comparative tests against a standard Mixed-Integer Programming (MIP) solver (GLPK), EKM demonstrated superior scalability.

Comparison of wall-clock time between EKM and the GLPK MIP solver.

On a log-linear scale, the GLPK solver's runtime appears as a straight line, indicating exponential growth. In contrast, EKM's runtime follows a logarithmic curve, confirming its polynomial nature. This predictability is vital for industrial applications where "timing out" is not an option. Furthermore, EKM's structure is "embarrassingly parallel," allowing it to be distributed across modern multi-core architectures with minimal communication overhead.

Discussion and Future Work

While EKM represents a breakthrough in exact clustering, it is subject to the "Curse of $K$." Because $K$ resides in the exponent of the complexity $O(N^{K+1})$, the algorithm remains computationally expensive for very large numbers of clusters (e.g., $K > 20$).

Future research directions include:

  • GPU Acceleration: Implementing EKM on highly parallel GPU architectures to push the boundaries of $N$ and $K$.
  • Pruning Strategies: Integrating global upper bounds from fast heuristics to further prune the recursive search tree.
  • Memory Efficiency: Utilizing ranking and unranking functions to represent medoid combinations more compactly.

In conclusion, EKM provides a robust, provably correct, and predictable tool for researchers and practitioners who require guaranteed global optimality in $K$-medoids clustering.

Summary updated

BibTeX
@misc{he2024ekm,
  author = {Xi He and Max A. Little},
  title = {{EKM: An exact, polynomial-time algorithm for the k-medoids problem}},
  year = {2024},
  eprint = {2405.12237},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.12237},
}
Figure