betaFeedback

WorksComputer Science

Two-Point Local Optimality in kk-Means via Boundary-Point Screening

Abstract

Lloyd's algorithm and the discrete local (D-local) optimization method (Li et al., 2025) for kk-means provide only weak local-optimality guarantees, and their solution quality remains sensitive to initialization. In this paper, we introduce rr-point local optimality, under which no reassignment of at most rr samples decreases the objective function, and focus on r=2r=2. The main computational obstacle is the O(n2(k2+d))\mathcal{O}(n^2(k^2+d)) cost of exhaustive two-point certification for nn samples in dd dimensions and kk clusters. To address this challenge, we prove that (i) every improving two-point move of a D-local optimum must involve a cluster shared by both reassignments, and (ii) only certificate-defined boundary points can participate in an improving pair. Exploiting this structure, we propose Boundary-Point-Screened Two-Point Local Search (BPS-2PLS), which terminates at a two-point local optimum. For fixed k,dk,d and nonvanishing cluster occupancy, the number mm of retained candidates satisfies m=OP(log⁡n)m=\mathcal{O}_{\mathbb{P}}(\log n) under i.i.d. sampling from a bounded-support distribution with bounded density or from a Gaussian mixture. Across twelve benchmarks, BPS-2PLS attains the lowest available mean WCSS on ten. In a subsampling study, screening retains 0.10% to 2.81% of samples on average at the largest tested sizes. The code is available at https://github.com/lwl-learning/BPS-2PLS.

Introduction

kk-means [23] is a canonical clustering method because of its simple geometric interpretation, with broad applications including image analysis [16, 21, 1] (Qi et al. 2024), large-scale similarity search [15], single-cell genomics [7], climate science [19], and speech processing (Ambilduke et al., 2025). kk-means seeks a partition that minimizes the within-cluster sum of squares (WCSS). Despite the simplicity of its objective, finding a global minimizer is NP-hard [2]. Practical methods therefore seek a suboptimal solution from a given initialization.

Lloyd’s algorithm alternates between assignment and centroid updates. At termination, the assignments and centroids are each optimal with the other fixed [22]. This partial optimality does not exclude a reassignment that decreases WCSS after centroid recomputation. Hartigan-style methods [14] (Telgarsky and Vattani 2010) address this weakness, and Li et al. [20] formalize D-local optimality, under which no one-sample reassignment decreases WCSS after centroid recomputation.

However, two reassignments that are individually non-improving can yield an improvement when applied simultaneously, because their centroid updates interact through shared clusters. This motivates rr-point local optimality, which excludes improvements from simultaneously reassigning at most rr samples and ranges from D-locality at r=1r = 1 to global optimality at r=nr = n. We focus on r=2r = 2, the first level beyond one-point relocation.

Exact certification of two-point local optimality appears expensive because direct enumeration over sample pairs and their destination clusters yields (n2)(k−1)2\binom{n}{2}(k - 1)^2 candidates. Nevertheless, we establish that, at a D-local optimum, every improving two-point move must involve a cluster shared by both sample reassignments, reducing all potentially improving moves to six directed configurations. To further reduce sample-pair enumeration, we construct, for each sample, an upper bound on the gains of connected two-point moves involving it, following the safe-screening principle El Ghaoui et al. [9]; Fercoq et al. [11]. A sample with a non-positive upper bound cannot participate in any improving pair and can therefore be safely discarded. After initial Lloyd convergence, alternating Min-D-LO one-point descent with exact search over the retained samples yields Boundary-Point-Screened Two-Point Local Search (BPS-2PLS), which terminates at a two-point local optimum. With mm retained candidates and lazily computed pair distances, screening and search cost O(k2d+nklog⁡n+m2(d+k))O(k^2d + nk \log n + m^2(d + k)) after each one-point descent phase, without a full sample-pair cache.

The benefit of screening depends on how mm grows with nn. We localize retained samples near empirical cluster boundaries and prove m=OP(log⁡n)m = O_{\mathrm{P}}(\log n) for fixed kk, dd under bounded-support sampling with bounded density or Gaussian-mixture sampling. The bounds hold uniformly over D-local states with nonvanishing cluster occupancy. Complementing this theoretical analysis, a six-dataset subsampling experiment shows mean pruning rates above 97% at the largest tested sizes. Together, these results show that exact two-point local optimality can be attained efficiently on the evaluated problems.

Overall, our contributions are summarized as follows:

  • We introduce a hierarchy from D-local to global optimality and characterize improving moves through connected cluster-transfer graphs.

  • We develop BPS-2PLS, combining exact two-point search with safe sample screening to certify two-point local optimality.

  • We establish uniform logarithmic candidate-size bounds m=OP(log⁡n)m = O_{\mathrm{P}}(\log n) for two common distribution classes and a nonvanishing cluster-occupancy condition.

Related Work

Sample-reassignment methods include Hartigan-type one-sample relocations (Hartigan and Wong [14]; Telgarsky and Vattani (2010)) and D-LO/Min-D-LO, which exclude improving one-point moves at termination (Li et al. [20]). Beyond single-sample relocations, Tarsitano (2003) studied general two-sample reassignments under the Friedman–Rubin determinant criterion by scanning sample pairs and their destination clusters. In contrast to Tarsitano (2003), we study the standard WCSS objective through a point-cardinality local-optimality hierarchy, with exact search and safe screening for its complete two-point neighborhood.

Center- or cluster-based neighborhoods include J-Means centroid relocation (Hansen and Mladenović [13]), merge-and-split repartitioning (Nielsen and Nock (2014)), and center swaps with approximation guarantees (Arya et al. [4]; Kanungo et al. [17]). These operations may change many labels, whereas our neighborhoods are defined by the number of reassigned samples.

A complementary line of work reduces computation without changing the output of a prescribed algorithm. For example, exact Lloyd accelerations use triangle inequalities and distance bounds to reduce evaluations (Elkan [10]; Hamerly [12]; Newling and Fleuret (2016)). Safe screening in sparse optimization uses certificates to discard inactive variables without changing the target solution (El Ghaoui et al. [9]; Fercoq et al. [11]). BPS-2PLS combines these two goals: it goes beyond single-sample moves, uses safe screening to preserve every improving two-point move, and certifies two-point local optimality at termination.

Problem Setup and Preliminaries

Throughout this paper, deterministic vectors and matrices are bold italic, sets are blackboard bold, and scalars are upright letters. All unqualified vector norms are Euclidean. Let X=(xi)i=1n\mathcal{X} = (x_i)_{i=1}^{n} be an indexed collection of samples in Rd\mathbb{R}^{d}, and write [n]={1,…,n}[n] = \{1,\ldots,n\} and [k]={1,…,k}[k] = \{1,\ldots,k\}. A clustering is represented by a label vector z∈[k]nz \in[k]^n, with cluster index sets Iℓ(z)={i∈[n]:zi=ℓ}I_{\ell}(z) = \{i \in[n] : z_i = \ell\}, ℓ∈[k]\ell\in[k]. We restrict attention to partitions with nonempty clusters and to reassignments whose resulting partitions also satisfy this condition. For a fixed state zz, we suppress the dependence on zz in the cluster statistics and write nℓ=∣Iℓ∣n_\ell= |I_\ell|, sℓ=∑i∈Iℓxis_\ell= \sum_{i\in I_\ell} x_i, μℓ=sℓ/nℓ\mu_\ell= s_\ell/n_\ell. The kk-means objective, also known as the within-cluster sum of squares (WCSS), is

F(z)=∑ℓ=1k∑i∈Iℓ∥xi−μℓ∥2=∑i=1n∥xi∥2−∑ℓ=1k∥sℓ∥2nℓ.(1)F(z) = \sum_{\ell=1}^{k}\sum_{i\in I_\ell}\lVert x_i-\mu_\ell\rVert^2 = \sum_{i=1}^{n}\lVert x_i\rVert^2-\sum_{\ell=1}^{k}\frac{\lVert s_\ell\rVert^2}{n_\ell}. \tag*{(1)}

A reassignment from zz to z′z' is improving precisely when F(z)−F(z′)>0F(z)-F(z')>0. For later use, define the squared sample–centroid and sample–sample distances

Diℓ=∥xi−μℓ∥2,pij=∥xi−xj∥2.(2)D_{i\ell}=\lVert x_i-\mu_\ell\rVert^2,\qquad p_{ij}=\lVert x_i-x_j\rVert^2. \tag*{(2)}

Lloyd’s algorithm alternates between assigning each sample to a nearest centroid and recomputing each centroid as the mean of its assigned samples (Lloyd [22]). At convergence, the resulting clustering satisfies

Di,zi≤Dib,∀i∈[n],∀b∈[k].(3)D_{i,z_i}\le D_{ib},\qquad\forall i\in[n],\quad\forall b\in[k]. \tag*{(3)}

This gives partial optimality: assignments and centroids are each optimal with the other fixed (Li et al. [20]). However, partial optimality does not account for the centroid changes caused by reassigning a sample and therefore need not imply local optimality of the partition.

To account for these centroid changes, consider a one-point move u=(i:s→a)u=(i:s\to a), with s=zis=z_i, a≠sa\ne s, and ns>1n_s>1. Its exact gain after recomputing the two affected centroids is

gi(a)=nsns−1Dis−nana+1Dia.(4)g_i(a)=\frac{n_s}{n_s-1}D_{is}-\frac{n_a}{n_a+1}D_{ia}. \tag*{(4)}

The first term is the reduction in WCSS obtained by removing xix_i from cluster ss, whereas the second term is the increase caused by inserting it into cluster aa. Following Li et al. [20], this gives the following notion of local optimality.

Definition 3.1 (D-local optimality). A clustering zz is DD-locally optimal if gi(a)≤0g_i(a)\le0 for every feasible one-point move (i:zi→a)(i:z_i\to a), with the affected centroids recomputed.

Every D-locally optimal clustering satisfies the Lloyd fixed-point condition, whereas the converse need not hold. However, jointly reassigning multiple samples may still improve WCSS, motivating the point-cardinality hierarchy in the next section.

r-Point Local Optimality

We extend D-local optimality to joint label changes and identify the cluster interactions that can produce improvements. Let Zk={z∈[k]n:Ia(z)≠∅, ∀a∈[k]}Z_k=\{z\in[k]^n:I_a(z)\ne\varnothing,\ \forall a\in[k]\} be the feasible label space. For z∈Zkz\in Z_k, a simultaneous qq-point reassignment is an unordered collection of qq sample reassignments

M={(it:at→bt)}t=1q,at=zit,bt∈[k]∖{at},(5)M=\{(i_t:a_t\to b_t)\}_{t=1}^{q},\qquad a_t=z_{i_t},\quad b_t\in[k]\setminus\{a_t\}, \tag*{(5)}

where i1,…,iqi_1,\ldots,i_q are distinct. The resulting vector zMz^M changes each zitz_{i_t} to btb_t and leaves all other entries unchanged. Feasibility requires the final simultaneous reassignment to satisfy zM∈Zkz^M\in Z_k; all affected centroids are then recomputed.

For z,z′∈Zkz,z'\in Z_k, let dH(z,z′)=∣{i∈[n]:zi′≠zi}∣d_H(z,z')=|\{i\in[n]:z'_i\ne z_i\}| denote the differing labels, and define the exact-qq shell and radius-rr neighborhood by

N=q(z)={z′∈Zk:dH(z,z′)=q},N≤r(z)=⋃q=1rN=q(z).(6)N_{=q}(z)=\{z'\in Z_k:d_H(z,z')=q\},\qquad N_{\le r}(z)=\bigcup_{q=1}^{r}N_{=q}(z). \tag*{(6)}

For a feasible move MM, define its gain by G(M;z)=F(z)−F(zM)G(M;z)=F(z)-F(z^M).

Definition 4.1 (r-point local optimality). A clustering z∈Zkz\in Z_k is rr-point locally optimal if

F(z)≤F(z′),for every z′∈N≤r(z).(7)F(z)\le F(z'),\qquad\text{for every }z'\in N_{\le r}(z). \tag*{(7)}

Proposition 4.2 (Hierarchy). Let Lr\mathcal{L}_r denote the set of all rr-point local optima. For 1≤s<r≤n1\le s<r\le n,

N≤s(z)⊆N≤r(z),Lr⊆Ls.(8)N_{\le s}(z)\subseteq N_{\le r}(z),\qquad\mathcal{L}_r\subseteq\mathcal{L}_s. \tag*{(8)}

Moreover, 1-point local optimality coincides with D-local optimality, whereas nn-point local optimality coincides with global optimality over ZkZ_k.

The objective is a sum of cluster contributions, so reassignments can interact only through shared clusters. This motivates the following graph representation.

Definition 4.3 (Cluster-transfer graph). For a simultaneous move MM, its cluster-transfer graph G(M)\mathcal{G}(M) is the directed multigraph whose vertex set V(M)V(M) consists of the affected clusters. For each reassignment, the graph contains one edge at→bta_t \to b_t, labeled by iti_t.

Distinct components affect disjoint cluster statistics, so their gains are additive, yielding the following characterization.

Theorem 4.4 (Connected-move characterization). A clustering zz is rr-point locally optimal if and only if every feasible simultaneous move MM with 1≤∣M∣≤r1 \leq|M| \leq r whose transfer graph G(M)\mathcal{G}(M) is weakly connected is non-improving. Consequently, if zz is already (r−1)(r-1)-point locally optimal, then every improving exact-rr move must have a weakly connected transfer graph.

The gain decomposition and proofs are given in Appendix § 13. A connected graph with qq edges has at most q+1q+1 vertices, so every connected qq-point move affects at most q+1q+1 clusters.

Connectedness alone need not reduce the worst-case order for general rr (Appendix § 14). For r=2r=2, every improving move at a D-local state affects at most three clusters, yielding six configurations whose destination choices admit exact optimization. Given DD and the required pijp_{ij}, destination search costs O(n2k)O(n^2k) per pass, without requiring cluster balance.

Exact Two-Point Local Search

References

  1. [1]Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk. Slic superpixels compared to state-of-the-art superpixel methods. IEEE transactions on pattern analysis and machine intelligence, 34(11):2274–2282, 2012. doi: 10.1109/TPAMI.2012.120.DOI
  2. [2]Daniel Aloise, Amit Deshpande, Pierre Hansen, and Preyas Popat. Np-hardness of euclidean sum-of-squares clustering. Machine learning, 75(2):245–248, 2009. doi: 10.1007/s10994-009-5103-0.DOI
  3. [4]Vijay Arya, Naveen Garg, Rohit Khandekar, Adam Meyerson, Kamesh Munagala, and Vinayaka Pandit. Local search heuristics for k-median and facility location problems. SIAM Journal on Computing, 33(3):544–562, 2004. doi: 10.1137/S0097539702416402.DOI
  4. [5]Lorenzo Beretta, Vincent Cohen-Addad, Silvio Lattanzi, and Nikos Parotsidis. Multi-Swap k-means++. In Advances in Neural Information Processing Systems, volume 36, 2023. URL https://papers.nips.cc/paper_files/paper/2023/hash/52d6319e4b81f866bf69fb3c834aad47-Abstract-Conference.html.arxiv.org/abs/2309.16384
  5. [6]Deng Cai. Litekmeans: The fastest MATLAB implementation of kmeans, 2011. URL http://www.zjucadcg.cn/dengcai/Data/Clustering.html. Software.
  6. [7]Tara Chari, Gennady Gorin, and Lior Pachter. Biophysically interpretable inference of cell types from multimodal sequencing data. Nature Computational Science, 4(9):677–689, 2024. doi: 10.1038/s43588-024-00689-2.DOI
  7. [8]Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. Computational Geometry: Algorithms and Applications. Springer, 3 edition, 2008. doi: 10.1007/978-3-540-77974-2.DOI
  8. [9]Laurent El Ghaoui, Vivian Viallon, and Tarek Rabbani. Safe feature elimination for the lasso and sparse supervised learning problems. Pacific Journal of Optimization, 8(4):667–698, 2012.
  9. [10]Charles Elkan. Using the triangle inequality to accelerate k-means. In Proceedings of the Twenty-th International Conference on Machine Learning, pages 147–153, 2003. URL https://cseweb.ucsd.edu/~elkan/kmeansicml03.pdf.
  10. [11]Olivier Fercoq, Alexandre Gramfort, and Joseph Salmon. Mind the duality gap: Safer rules for the lasso. In Proceedings of the 32nd International Conference on Machine Learning, volume 37 of Proceedings of Machine Learning Research, pages 333–342, 2015.arxiv.org/abs/1505.03410
  11. [12]Greg Hamerly. Making k-means even faster. In Proceedings of the 2010 SIAM International Conference on Data Mining, pages 130–140. SIAM, 2010. doi: 10.1137/1.9781611972801.12.DOI
  12. [13]Pierre Hansen and Nenad Mladenović. J-Means: A new local search heuristic for minimum sum of squares clustering. Pattern Recognition, 34(2):405–413, 2001. doi: 10.1016/S0031-3203(99)00216-2.
  13. [14]J. A. Hartigan and M. A. Wong. Algorithm AS 136: A K-means clustering algorithm. Applied Statistics, 28(1):100–108, 1979. doi: 10.2307/2346830.
  14. [15]Hervé Jégou, Matthijs Douze, and Cordelia Schmid. Product quantization for nearest neighbor search. IEEE Transactions on Pattern Analysis and Machine Intelligence, 33(1):117–128, 2011. doi: 10.1109/TPAMI.2010.57.DOI
  15. [16]Yuheng Jia, Jianhong Cheng, Hui Liu, and Junhui Hou. Towards calibrated deep clustering network. In The Thirteenth International Conference on Learning Representations, 2025. URL https://openreview.net/forum?id=JvH4jDDcG3.arxiv.org/abs/2403.02998
  16. [17]Tapas Kanungo, David M. Mount, Nathan S. Netanyahu, Christine D. Piatko, Ruth Silverman, and Angela Y. Wu. A local search approximation algorithm for k-means clustering. Computational Geometry, 28(2–3):89–112, 2004. doi: 10.1016/j.comgeo.2004.03.003.
  17. [18]Silvio Lattanzi and Christian Sohler. A better k-means++ algorithm via local search. In Proceedings of the 36th International Conference on Machine Learning, volume 97 of Proceedings of Machine Learning Research, pages 3662–3671. PMLR, 2019. URL https://proceedings.mlr.press/v97/lattanzi19a.html.
  18. [19]Simon H. Lee and Gabriele Messori. The dynamical footprint of year-round north american weather regimes. Geophysical Research Letters, 51(2):e2023GL107161, 2024. doi: 10.1029/2023GL107161.
  19. [20]Mingy Li, Michael R. Metel, and Akiko Takeda. Modified K-means algorithm with local optimality guarantees. In Proceedings of the 42nd International Conference on Machine Learning, volume 267 of Proceedings of Machine Learning Research, pages 35656–35684. PMLR, 2025a. URL https://proceedings.mlr.press/v267/li25bt.html.arxiv.org/abs/2506.06990
  20. [21]Zhixin Li, Yuheng Jia, Hui Liu, and Junhui Hou. Learning from sample stability for deep clustering. In Proceedings of the 42nd International Conference on Machine Learning, volume 267 of Proceedings of Machine Learning Research, pages 34904–34919. PMLR, 2025b. URL https://proceedings.mlr.press/v267/li25am.html.
  21. [22]Stuart Lloyd. Least squares quantization in pcm. IEEE transactions on information theory, 28(2):129–137, 1982. doi: 10.1109/TIT.1982.1056489.DOI
  22. [23]James B. MacQueen. Some methods for classification and analysis of multivariate observations. In Proceedings of the Fifth Berkeley Symposium on Mathematical Statistics and Probability, volume 1, pages 281–297, Berkeley, CA, 1967. University of California Press. URL https://digicoll.lib.berkeley.edu/record/113015.

Paper details

vlnc:W_6wz76cyh
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

generative AI tools

View statement
Looking for related papers…
Contents