[Paper Review] An implementation of the relational k-means algorithm
This paper presents a C# implementation of relational k-means, a clustering algorithm that generalizes k-means to work with arbitrary distance matrices rather than vector-based data. By reformulating centroid distances using quadratic forms on a squared distance matrix, the method enables clustering in non-Euclidean spaces, achieving practical performance on real-world datasets like protein sequences in under a minute on a dual-core laptop.
A C# implementation of a generalized k-means variant called relational k-means is described here. Relational k-means is a generalization of the well-known k-means clustering method which works for non-Euclidean scenarios as well. The input is an arbitrary distance matrix, as opposed to the traditional k-means method, where the clustered objects need to be identified with vectors.
Motivation & Objective
- To enable k-means clustering in non-Euclidean spaces where data points are not representable as vectors.
- To generalize the classical k-means objective function to work with arbitrary symmetric distance functions that need not satisfy the triangle inequality.
- To implement an efficient, parallelized version of relational k-means capable of handling real-world datasets.
- To demonstrate the feasibility and performance of the algorithm on large-scale biological data using a Levenshtein-like distance function.
Proposed method
- The algorithm uses a squared distance matrix $ A_{ij} = f(p_i, p_j)^2 $ as input, where $ f $ is an arbitrary symmetric distance function with $ f(p_i, p_i) = 0 $.
- It defines a generalized squared centroid distance $ q_{ij} = -rac{1}{2} v_{ij}^ op A v_{ij} $, where $ v_{ij} = rac{1}{|S_j|} extstyleigsum_{k otin S_j} e_k - e_i $, extending the classical Euclidean notion.
- The clustering value is defined as $ extstyleigsum_{i=1}^n q_{i au(i)} $, with $ au(i) $ being the cluster assignment of point $ p_i $, and the algorithm minimizes this value.
- Each iteration reassigns each point to the cluster minimizing its $ q_{ij} $, and stops if no improvement is made.
- To ensure convergence in non-Euclidean cases, a $ eta $-spread transformation $ A + eta(J - I) $ is applied to make the matrix Euclidean.
- The algorithm is optimized to $ O(n^2) $ per iteration by precomputing cluster-specific sums and reusing them across points.
Experimental results
Research questions
- RQ1Can k-means be effectively generalized to work with arbitrary distance matrices without requiring vector representations of data points?
- RQ2How can the classical k-means objective function be reformulated to operate on a distance matrix alone, preserving the geometric intuition of centroid distances?
- RQ3What computational optimizations are necessary to make relational k-means practical for real-world datasets with non-Euclidean distances?
- RQ4Can parallelization significantly improve runtime performance for relational k-means on large-scale data?
Key findings
- The relational k-means algorithm successfully generalizes k-means to non-Euclidean spaces by using a quadratic form on a distance matrix to compute generalized centroid distances.
- The algorithm achieves $ O(n^2) $ time complexity per iteration through optimization of the $ q_{ij} $ computation using precomputed cluster sums.
- On a dataset of over 1,000 proteins with a Levenshtein-like distance function, the implementation completed clustering in 30–60 seconds on a dual-core laptop.
- With 20 consecutive failed attempts (no improvement) as a stopping criterion, the algorithm reliably converged to a high-quality clustering without further improvement.
- The implementation is highly parallelizable, with near 100% CPU utilization using multiple threads, and could be expected to run in under 8 seconds on a 16-core machine.
- A C++ port could potentially reduce execution time by approximately 50%, indicating further performance gains are possible with lower-level optimization.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.