A bi-criteria approximation algorithm for $k$ Means
Konstantin Makarychev, Yury Makarychev, Maxim Sviridenko, Justin Ward
Introduction
The -means clustering problem is one of the most popular models for unsupervised Machine Learning. The problem is formally defined as follows.
The most common heuristic for -means is Lloyd’s algorithm introduced in 1957 . Llloyd’s algorithm starts with some initial solution and then iteratively improves it by alternating two steps: at the first step, the algorithm picks the optimal clustering for the current set of centers; at the second step, the algorithm picks the optimal set of centers for the current clustering. While we know that the algorithm performs well on well-clusterable data it performs arbitrarily badly on general instances. There exist many variants of this algorithm and many heuristics for picking the initial solution. Unfortunately, none of them give a constant (not depending on ) factor approximation. One of the most popular ones is the -means++ algorithm that has an -approximation factor .
The general -means clustering problem has recently been shown to be APX-hard, ruling out a PTAS in the general case . However, a variety of PTASes exist for special cases of the problem. Inaba, Katoh, and Imai gave a -approximation algorithm for the case in which the number of clusters, , and the dimension of the space, , are fixed. Since then many more PTASes were proposed for other special cases. Additionally, there are many results showing the NP-hardness for several special cases .
The best constant factor approximation algorithm for the general case of the problem was proposed by a decade ago. Their algorithm gives factor approximation. Using the connection with -median problem designed an alternative constant factor approximation algorithm. showed that running the -means++ algorithm for more steps gives an factor approximation by opening centers, and also showed how to modify the resulting solution to obtain a set of centers attaining an factor guarantee.
In most practical applications the target number of clusters is not fixed in advance, rather we would like to find a number that provides a well-clusterable solution. Here, we show how to substantially improve the approximation factor by slightly violating the constraint on the number of clusters. We present bi-criteria approximation algorithms for the general case of the problem. A bi-criteria approximation algorithm finds a solution with clusters, whose cost is at most times the optimal cost of a solution using clusters. In contrast to the approach of , our algorithms find an approximate solution for every . Our approximation is always at most , and decreases rapidly with . In particular, we obtain a -approximation by opening only centers, improving over previous results by a factor of nearly 10, and obtain improved approximation factors as continues to grow. For example, , ; , and . In general, we argue that in many applications the number of clusters is not important as long as it approximately equals . For these applications we can obtain an approximation factor very close to 1.
We give three bi-criteria algorithms—two based on linear programming and one based on local search. We show the algorithms’ approximation factors as a function of in Figure 1. Note that our linear programming algorithm attains a better approximation for large , while the local search algorithm is better for near 1.
In the -median problem, we are given a set of points , a set of potential center locations and a distance function . The cost of assigning point to center is . Our goal is to open at most centers and assign each point to a center so as to minimize the total cost.
The first approximation algorithms for the -median problem were given by , who gave an LP-rounding algorithm that attains an approximation factor of by opening centers (i.e. a bi-criteria approximation). In further work, showed that if the distance function is a metric, it is possible to obtain a approximation algorithm by opening only centers. The first constant-factor approximation for the metric -median problem using only centers was obtained by , who showed that a simple local search algorithm gives a approximation. This remained the state of the art, until recently, when gave a approximation algorithm based on LP rounding. Subsequently, this has been improved to by .
We give three approximation algorithms. The first algorithm is based on linear programming. It gives
approximation (see also (11) for a slightly tighter bound). The second algorithm is based on local search. It gives
approximation. The third algorithm is also based on linear programming. It gives
approximation. The algorithm is similar to the first algorithm, but it uses pipage rounding (see ) instead of randomized rounding. In the conference version of the paper, we omit the description of the third algorithm. The approximation factors are shown in Figure 1.
In Section 2 we introduce the notation that we shall use throughout the rest of the paper and review standard notions related to both the -means and -median problems. In Section 3, we give the details of our reduction to -median. Finally, in Sections 4 and 5, respectively, we present our main LP-based algorithm and local search algorithm for the resulting -median instances.
Preliminaries
We now fix some notation, and recall some basic properties of -means solutions and the standard linear program for the -median problem. Additionally, we define the notion of an -relaxed 3-hop triangle inequality, which will be crucial to the analysis of our LP-rounding algorithms.
Note that to describe an optimal solution to the -means problem, it is sufficient to specify either all clusters or all centers in the solution. Indeed, given a list of clusters , we can find the optimal assignment of centers for it: the optimal choice of center for is . For this choice of , we have
Given a partition of into clusters, we then denote by the cost of this optimal choice of centers. That is,
Similarly, given a list of centers , we can find the optimal partition of into clusters. For each , let be the set of those points that are closer to than to other centers (if a point is at the same distance from several centers, we break the ties arbitrarily). The optimal partition for then sets . Given a set of centers, we define , where is the partition induced by .
2 k𝑘k-median
We will reduce a given instance of -means problem to an instance of the -median problem, specified by . By analogy with -means problem, we can consider a partition of demand points from , and then consider the best choice of a single center for each partition. We denote the cost of this choice by :
Similarly, given a list of centers , let be the set of those demand points that are closer (according to the distance function ) to than to any other center in (again, if a point is at the same distance from several facilities, we break ties arbitrarily). As in the case of -means, we define where is the partition of induced by .
Although the distance function in our -median instances will not satisfy the standard triangle inequality, we can show that it satisfies a relaxed variant of the following sort:
We say that satisfies an -relaxed -hop triangle inequality on if, for any and , we have
Specifically, we shall show that the distances produced by our reduction satisfy a -relaxed -hop triangle inequality.
Reduction from k𝑘k-means to k𝑘k-median
We now give the details of our reduction from the -means to the -median problem. In the -median problem, a finite set of candidate centers is specified, while in the -means problem, the ideal center for each cluster of points is given by the centroid of . Ideally, we want to ensure that for every possible centroid of the original -means instance, there is some nearby candidate centers in . The following notion of an -approximate centroid set, introduced by , captures this requirement.
Observe that if is an -approximate centroid set for , then for every set of centers (in particular, for the optimal set ), there exists a -point subset such that
Thus, if we restrict our search for center points in -means problem to only those points of , we lose at most a factor of .
Unfortunately, in our setting, the dimension of the space in which points lie may be as large as . Thus, in order to apply Theorem 5, we first embed into a low-dimensional space using the Johnson–Lindenstrauss transform.
We say that the map is a dimension reduction transform for .
1. For every , there exists a polynomial-time reduction from -means to -median with distance function that satisfies the 3-relaxed 3-hop triangle inequality. Specifically, given an instance of -means, the reduction outputs an instance of -median with , , and distance that satisfies the 3-relaxed 3-hop triangle inequality such that
where is a partition of and is the corresponding partition of . The reduction runs in time .
Algorithm for k𝑘k-Median with Relaxed Triangle Inequality
We now turn to the problem of approximating the -median instance from Theorem 7. Our first algorithm is based on the following standard linear programming relaxation for the -median problem:
In the integral solution, each variable indicates whether the center is open; and each variable indicates whether the point is assigned to the center . Constraint (4) asserts that we should open exactly centers; constraint (5) ensures that every point is assigned to exactly one center; finally, constraint (6) says that points can be assigned only to open centers. In a fractional LP solution, all and lie in the interval $z_{xc}=y_{c}z_{xc}>0z_{xc}y_{c}1cy_{c}=z_{xc}x\in Xc_{1}c_{2}z_{xc}y_{c}-z_{xc}z_{x^{\prime}c}z_{x^{\prime}c_{1}}=\min(z_{x^{\prime}c},y_{c_{1}})z_{x^{\prime}c_{2}}=y_{c_{2}}-\min(z_{x^{\prime}c},y_{c_{1}})ky_{c}y{\cal{C}}y(C)=\sum_{c\in C}y_{c}\mu$.
For every point , let . The set contains all centers that serve in the LP solution. Recall that we modify the solution so that if . Hence, if . For every point , we define its LP radius as:
Observe, that the LP value, which we denote by , equals .
Algorithm. We now describe our LP-rounding algorithm for -Medians with relaxed -hop triangle inequality.
There exists a bi-criteria approximation algorithm for -means with
The algorithm first solves the LP problem and modifies the LP solution as described above if necessary. Then, it partitions all centers into groups , each with LP measure . It picks one center at random from each group with probability (note, that ). The algorithm outputs the set of chosen centers, and assigns every point to the closest center.
We now describe the construction of in more detail. We partition centers into groups as follows. For every , we find the unique ball around whose LP weight exactly equals (To do so, we may split some centers, and pick some centers in at the boundary of the ball but not the others). We find a subset of points such that balls with are disjoint, and for every point , we also define a “witness” . To this end, we sort all points by the LP radius in the ascending order, and then consider them one by one. For each , if is disjoint from all previously chosen balls, then we add to the set , we set . Otherwise, if intersects some other ball that is already chosen, we discard and set . If there are several balls intersecting , we pick the first according to our ordering as the witness. Note, that for all . Once, we found a disjoint collection of balls , we add them to the set . We partition centers not covered by into groups of LP weight arbitrarily and add these groups to . Thus, we obtain a partitioning of all centers into groups of LP weight .
Analysis. We show that the algorithm returns a valid solution, and then prove an upper bound on its expected cost. The algorithm picks exactly one vertex from each group, so it always picks vertices. Hence, it always outputs a valid solution.
Fix . Recall, that is the set of all centers that serve in the LP solution. We upper bound by , which is the distance to the closest center in chosen by the algorithm. Note that the solution always contains at least one center in , so . For the proof, we pick a particular (random) center .
We define using the following randomized procedure. Consider the partitioning of all centers into groups of measure used by the algorithm. Let be the induced partitioning of the set . For all we independently flip a coin and with probability make the set active. We let to be the union of all active sets ; we say that centers in are active centers. Let be the center in closest to , if ; let to be the unique center in , otherwise. We set , if ; and , otherwise. Roughly speaking, indicates whether or : Specifically, if , then ; if , then . Note, however, that , and may belong to .
The center may not be the closest to , but since , we have
In Lemma 9, we show that . Thus,
We bound the expected distance from to given in Lemma 10. We show that
Here, we used that is the radius of ; is the radius of . By the Markov inequality, (see Lemma 15). In Lemma 14,we show that there exists two nonnegative numbers and () such that
where is some parameter in $$. Hence,
Combining all bounds above we get the following inequality:
This function can be upper bounded by defined in (8). We conclude that the approximation factor of the algorithm is upper bounded by .
We now bound .
We have .
We define two sets of random variables and , and then show that they are identically distributed. If the algorithm picks a center in , and is active, let . Let , otherwise. The random variables are mutually independent for all ; and
To define , we introduce an auxiliary Poisson arrival process. At every point of time , we pick a center with probability (i.e., with arrival rate ). For every , let be the first center chosen in . If no centers in are chosen, we let . Note that we pick two centers at exactly the same time with probability , hence is well defined. Conditional on , the random variable is uniformly distributed in with respect to LP weights (since at every given time , the probability of arrival equals ). Then, . Hence, . Note that all random variables are mutually independent. Thus, the random variables have the same distribution as random variables .
Note that if , then is the closest center in to . If , then all are equal to . Let . Since and have the same distribution, we have
Let and . Note that , since . We find .
Observe that the set is one of the sets in the partitioning as and . Assume and . Since , we have . Thus, must be inactive (otherwise, would be ). Moreover, for every (), is inactive or (again, otherwise, would be ). Hence, the event can be represented as the intersection of the following three independent events: , , and . The probability of the first event is ; the probability of the second event is ; the probability of the third event is (this probability is computed as in Lemma 9). Thus,
Local Search
Unfortunately the analyses of relies heavily on the triangle inequality, while the instances generated by Theorem 7 satisfy only a 3-relaxed 3-hop triangle inequality. Thus, we proceed as in .
Let be an optimal set of centers, and be the set of centers produced by the local search algorithm. As in , we say that a center captures a center if is the center of that is closest to . Note that each center in can potentially capture several centers in , but each center in is captured by exactly one center of . We now construct a set of local swaps to consider in our analysis. We say that a center in is “good” if it does not capture any center of . Then, because each center of is captured by only one center of , we must have at least good centers in . We fix some such set of good centers; we call them “auxiliary” centers and set them aside for now.
For the remaining centers , we proceed exactly as in : we assign each center in to the bad center of that captures it. This creates a partition of centers in . We similarly partition the centers of into parts with ; for each , let contain the bad center of that captures all of together with unique good centers of . Note that the fact that each center of is captured only once ensures that there are indeed enough good centers in for our construction. Now, we use this partition of and to construct a set of swaps, each assigned some weight. If , we consider the with weight 1. If , we consider a group of singleton swaps , where and is a good center in , each with weight . At this point, note that every center in occurs in swaps of total weight , and every center in occurs in swaps of total weight at most . Now, we add swaps involving auxiliary centers; for each of the auxiliary centers and each , we consider singleton swap , assigned weight . Each center of now occurs in swaps of total weight , while each center of occurs in swaps of total weight .
Summarizing, our set of swaps satisfies the following properties: (1) each center of occurs in swaps of total weight ; (2) each center of occurs in swaps of total weight at most ; (3) for any swap in our set, no center in captures any center not in . We now give a brief sketch of how these properties lead to our desired approximation ratio (we give a full description of the analysis in the appendix). Our analysis closely follows that of .
As in , the total change due to performing a single swap is at most:
If is locally optimal, then we must have that for all swaps considered by the algorithm. In particular, for each swap in our set, we have:
Multiplying each inequality (12) by the weight of its swap and then adding the resulting inequalities we obtain:
due to properties (1) and (2) of our set of swaps. Theorem 7 part 2, which shows that our center set is an approximate -means centroid set, then allows us to simplify the final term above as in , giving:
where is the squared approximation ratio of our algorithm. Rearranging and simplifying (again, we give a detailed analysis in the appendix), we obtain.
Therefore, we have proved the following theorem:
There exists an algorithm that produces a solution for any instance of -median problem satisfying the properties of Theorem 7, where is a fixed constant. For any and any , the algorithm runs in time polynomial in and produces a solution satisfying:
where is the optimal set of centers in .
References
Appendix A Detailed Analysis of the LP Rounding Algorithm
Given and , the random center is distributed uniformly in (with respect to the LP weights ). Hence, for . We have
There exists two nonnegative numbers and satisfying
Denote the expected distance from a random center in to by and distance from a random center in to by :
The following inequality holds: .
Every center is at distance at least from . Hence,
Appendix B Detailed Analysis of the Local Search Algorithm
Here we give a detailed analysis of the local search algorithm from section 5, closely following .
Let and be two sequences of reals such that for some . Then,
We now show how local optimality implies the desired inequality. For a demand point , let and denote the closest facility to in and , respectively. Recall that for for , is precisely the set of all those demand points such that , and, similarly, for , is the set of all demand point such that . Now, we upper bound the change in cost due to some swap in our set of swaps. We do this by constructing a feasible assignment of all points in to centers in . For each , we assign all the points in to . This changes the cost by
Now, fix a point , and consider ’s closest optimal center . We must have . Let be the closest center to in . Then, by property (3) above, , since captures but . We reassign to . The total cost of reassigning all such points is at most:
where the inequality follows from the fact that is the closest center to in , and so for all . Thus, the total change for each swap is at most:
If is locally optimal, then we must have that for all swaps considered by the algorithm. In particular, for each swap in our set, we have:
Set . Then, multiplying each such inequality by the weight of its swap and then adding the resulting inequalities we obtain
where we have exploited properties (1) and (2) of our set of swaps to bound the number of times a given center in or is counted in our sum of inequalities.
It remains to bound the final term in (13). Consider some , and let be the centroid of . As above, we will let denote the closest center in to . Then, note that:
Let be the approximation ratio attained by the algorithm. Summing over all , and recalling that for all we have , we obtain:
Where in the last inequality, we have applied Lemma 17 to the sequences and defined by:
Applying the upper bound (14) to the final term of (13), we obtain:
where we have used the fact that . Rearranging, we have
Appendix C Proof of Theorem 7
We first show that for every solution of the -means problem on there is a corresponding solution of -means problem on in which all centers lie in , and vice versa.
For every partition of , there is a corresponding clustering of given by and some centers such that:
Part 1: Consider a partition of and the corresponding partition of , where . Let for . Because is an -approximate centroid set for , we have, for each cluster ,
Part 2: Consider a partition of and the corresponding partition of , where . Define the centers . Then, for each cluster , we have:
Now we are ready to define instance . Let , be the -approximate centroid we defined above, and for every and . Define by .
We prove that our reduction, which maps instance of -means to instance of -median, satisfies the conditions of the theorem.
Our reduction produces an instance that satisfies the following properties:
The distance function satisfies the 3-relaxed 3-hop triangle inequality on .
For every partition of and the corresponding partition of , we have
For claim 2, consider any partition of . Let be the corresponding partition of , given by . Then, from our definition of , we have . Moreover, by Lemma 18, we have is between and . Thus,