Tutorials › Statistical Learning (Graduate) › K-Medians and Alternative Quantization Distortions

Clustering Risk and Consistency · Tutorial 659 of 989

K-Medians and Alternative Quantization Distortions

Learn how Euclidean-distance distortion changes optimal cell representatives and which quantizer consistency arguments continue to apply.

Advanced 12 min read

What You'll Learn

  • Define squared and Euclidean-distance quantization risks for a codebook.
  • Derive the necessary and sufficient condition for a cellwise geometric median.
  • Distinguish geometric medians from centroids using explicit calculations.
  • Identify the moment assumptions that make each distortion finite.
  • Determine which uniform-convergence and argmin consistency arguments transfer to K-medians.

Two Distortions, Two Notions of a Representative

A quantizer represents each observation by its nearest center. The rule assigning observations to centers is the same whether distance is squared or left unsquared: squaring is increasing on nonnegative distances. But the representative that minimizes the loss within a fixed cell can change. Squared distance favors the conditional mean; Euclidean distance leads to a geometric median.

Let \(X\) be a random vector in \(\mathbb{R}^d\), and let a codebook be \(c=(c_1,\ldots,c_K)\), with centers in a specified compact set \(C\subset\mathbb{R}^d\). The two population risks considered here are

$$ R_2(c)=E\!\left[\min_{1\leq j\leq K}\|X-c_j\|^2\right], \qquad R_1(c)=E\!\left[\min_{1\leq j\leq K}\|X-c_j\|\right]. $$

The subscripts indicate the power of the distance in the loss. The corresponding empirical risks for independent observations \(X_1,\ldots,X_n\) are obtained by replacing the expectation with the sample average. A measurable tie-breaking rule can assign each observation to one of its nearest centers. Because both losses use the same nearest-center rule, their Voronoi cells agree for a given codebook, including the same possible ties.

Definition: A K-median quantizer minimizes \(R_1(c)\) over its allowed codebooks. For a fixed cell \(A\) with positive probability, a geometric median is any point minimizing \(m\mapsto E[\|X-m\|\mid X\in A]\). It need not be unique. By contrast, a conditional mean minimizes the corresponding expected squared distance when the conditional second moment is finite.

The cellwise definitions require the appropriate moments. If \(P(A)>0\), then \(E[\|X\|\mid X\in A]\leq E[\|X\|]/P(A)\); likewise, \(E[\|X\|^2\mid X\in A]\leq E[\|X\|^2]/P(A)\). Thus a finite global first moment ensures finite conditional Euclidean-distance loss in every positive-probability cell, and a finite global second moment ensures finite conditional squared-distance loss there. A weaker, mismatched assumption need not suffice: a finite first moment alone does not guarantee finite squared-distance risk.

The Cellwise Geometric-Median Condition

For a fixed cell, the geometric-median condition can be stated without assuming that the distribution has a density or that it puts no mass at the candidate median. That qualification matters: the norm is not differentiable when \(X=m\).

Theorem: Let \(X\) have a finite first moment, and define \(g(m)=E[\|X-m\|]\) for \(m\in\mathbb{R}^d\). A point \(m\) minimizes \(g\) if and only if $$ \left\|E\!\left[\frac{m-X}{\|m-X\|}\,\mathbf{1}_{\{X\ne m\}}\right]\right\|\leq P(X=m). $$ Here the fraction is evaluated only on \(\{X\ne m\}\). For a cellwise geometric median, the same condition applies to the conditional distribution given that the observation lies in the cell.

Proof. Fix a direction \(h\in\mathbb{R}^d\). For \(t>0\), consider the directional difference quotient \((g(m+th)-g(m))/t\). For \(X\ne m\), its integrand converges as \(t\downarrow0\) to \((m-X)\cdot h/\|m-X\|\). For \(X=m\), the integrand equals \(\|h\|\). The absolute value of each difference quotient is at most \(\|h\|\), by the reverse triangle inequality. Dominated convergence therefore gives the directional derivative

$$ g'(m;h)=a\cdot h+p\|h\|, \qquad a=E\!\left[\frac{m-X}{\|m-X\|}\mathbf{1}_{\{X\ne m\}}\right], \quad p=P(X=m). $$

The function \(g\) is convex, since it is an expectation of convex functions. A point minimizes a convex function if and only if all its one-sided directional derivatives there are nonnegative: necessity follows from minimality; for sufficiency, convexity makes the slope from \(m\) to \(m+h\) at least the right derivative at zero. Thus \(m\) minimizes \(g\) exactly when \(a\cdot h+p\|h\|\geq0\) for every \(h\). By Cauchy–Schwarz, this holds if \(\|a\|\leq p\). Conversely, if \(\|a\|>p\), taking \(h=-a\) gives \(-\|a\|^2+p\|a\|<0\). This proves the condition. \(\square\)

When \(P(X=m)=0\), the condition reduces to a zero vector expectation of the unit directions from observations toward \(m\). When there is an atom at \(m\), its probability supplies the allowance \(P(X=m)\); simply setting a derivative equal to zero would miss this case.

Worked Example: A Weighted Cell Where the Mean and Median Differ

Suppose a cell has conditional distribution \(P(X=0)=0.8\) and \(P(X=10)=0.2\). Its squared-distance representative is the conditional mean: \(0.8(0)+0.2(10)=2\). The squared loss at 2 is \(0.8(2^2)+0.2(8^2)=3.2+12.8=16\). At 0 it is \(0.8(0^2)+0.2(10^2)=20\), confirming that 2 does better than 0 for squared loss.

For Euclidean distance, the loss at 0 is \(0.8(0)+0.2(10)=2\). At 2 it is \(0.8(2)+0.2(8)=1.6+1.6=3.2\). More generally, on \(0\leq m\leq10\), the expected distance is \(0.8m+0.2(10-m)=2+0.6m\), which is minimized at \(m=0\). Outside this interval the loss is larger still. Thus the geometric median is 0, not the mean 2.

The condition verifies the result at \(m=0\): the non-atom directional expectation is \(-0.2\), while \(P(X=0)=0.8\), so \(0.2\leq0.8\). The atom is not a technical nuisance here; it is exactly why the condition allows a nonzero directional expectation.

Worked Example: A Nonunique Geometric Median

Let \(X\) equal \((-1,0)\) or \((1,0)\), each with probability \(1/2\). For \(m=(t,0)\) with \(-1\leq t\leq1\), the expected Euclidean distance is \(\tfrac12|t+1|+\tfrac12|t-1|=\tfrac12(t+1)+\tfrac12(1-t)=1\). No point can have expected distance below 1, since the triangle inequality gives \(\|X-m\|+\|X'-m\|\geq\|X-X'\|=2\) when \(X,X'\) are the two support points. Hence every point on the segment between them is a geometric median.

The squared-distance objective along that segment is \(\tfrac12(t+1)^2+\tfrac12(t-1)^2=t^2+1\), uniquely minimized at \(t=0\). This example shows that replacing squared distance by distance can change not only the representative but also whether the cellwise minimizer is unique.

What Changes for a Whole Codebook?

For a fixed assignment of observations to cells, the squared-loss objective separates into one term per cell, whose unrestricted minimizer for each positive-probability cell is its conditional mean. Under Euclidean distance, the unrestricted minimizer of each such term is a conditional geometric median. With centers constrained to \(C\), each cellwise loss must instead be minimized over \(C\); an unrestricted minimizer is valid when it belongs to \(C\). The condition above characterizes unrestricted geometric medians.

This is a cellwise statement, not a recipe that independently chooses all centers and thereby guarantees a global optimum. Changing a center can change which observations are nearest to which center. At a global optimum, replacing a center by a better representative in \(C\) for its current cell would reduce the loss for that fixed assignment, and the nearest-center loss after replacement can only be smaller than or equal to the loss under that assignment. Thus a positive-probability cell of a global optimum must have a representative minimizing its conditional loss over \(C\). A zero-probability cell imposes no such condition, and its center may be arbitrary. Ties can be handled by the measurable partition convention; the cellwise argument uses the assigned observations in each cell.

Worked Example: Checking an Atom Condition in Two Dimensions

Consider a cell with \(P(X=(0,0))=0.5\), \(P(X=(2,0))=0.25\), and \(P(X=(0,2))=0.25\). At \(m=(0,0)\), the non-atom directional expectation in the theorem is \(-0.25(1,0)-0.25(0,1)=(-0.25,-0.25)\). Its norm is \(\sqrt{0.25^2+0.25^2}=\sqrt{1/8}\), approximately \(0.354\), which is at most the atom probability \(0.5\). Therefore the origin is a geometric median.

The conditional mean is \((0.5,0.5)\). The Euclidean loss at the origin is \(0.25(2)+0.25(2)=1\). At the mean it is \(0.5\sqrt{0.5}+0.25\sqrt{2.5}+0.25\sqrt{2.5} =0.5\sqrt{0.5}+0.5\sqrt{2.5}\), approximately \(1.144\). By comparison, the squared loss at the origin is \(0.25(4)+0.25(4)=2\), while at the mean it is \(0.5(0.5)+0.25(2.5)+0.25(2.5)=1.5\). The two losses favor different cell representatives.

Which Consistency Arguments Remain Valid?

The empirical K-means consistency arguments based on compact codebooks, uniform convergence of empirical risks, and set-valued argmin consistency transfer to K-medians when their assumptions are adjusted to the loss. The key issue is not the name of the algorithm but whether the chosen loss has finite expectation and whether the empirical risks converge uniformly over the allowed codebooks.

For example, suppose \(C\) is compact, \(X_1,\ldots,X_n\) are independent and identically distributed, and \(E\|X\|<\infty\). On a bounded set of centers, the Euclidean loss is bounded by \(\|X\|+M\) for a suitable finite \(M\); changing a center by distance \(\delta\) changes its distance loss by at most \(\delta\). These bounds give an integrable envelope and a uniform Lipschitz bound in the codebook. A finite-net argument together with the law of large numbers then gives uniform convergence of the empirical Euclidean-distance risks. For squared loss, the corresponding envelope is bounded by a constant times \(1+\|X\|^2\), so a finite second moment is the natural sufficient moment assumption for that argument.

Theorem: Let the codebook space \(C^K\) be compact, let \(R\) be continuous there, and let \(R_n\) converge uniformly in probability to \(R\). Let \(\mathcal{M}=\arg\min_{c\in C^K}R(c)\), and suppose \(\hat c_n\) satisfies \(R_n(\hat c_n)\leq\inf_{c\in C^K}R_n(c)+o_p(1)\). Then the distance from \(\hat c_n\) to \(\mathcal{M}\) converges to zero in probability.

Proof. Continuity and compactness imply that \(\mathcal{M}\) is nonempty and compact. Fix \(\epsilon>0\). The compact set of codebooks at distance at least \(\epsilon\) from \(\mathcal{M}\) contains no minimizer. If that set is nonempty, continuity and compactness imply that its minimum risk exceeds \(\min R\) by some gap \(\Delta_\epsilon>0\). On the event that \(\sup_{c\in C^K}|R_n(c)-R(c)|<\Delta_\epsilon/3\) and the optimization error is less than \(\Delta_\epsilon/3\), an approximate minimizer cannot lie in that set: its empirical risk would exceed the empirical risk of a population minimizer. Uniform convergence in probability and the \(o_p(1)\) optimization error make the probability of the complementary event tend to zero. If the set is empty, the distance is already less than \(\epsilon\). Thus \(P(\operatorname{dist}(\hat c_n,\mathcal{M})\geq\epsilon)\to0\) for every \(\epsilon>0\). \(\square\)

This result does not require a unique population optimum; it gives convergence to the full minimizing set. Consequently, the set-valued consistency argument remains valid for K-medians under the corresponding uniform-convergence conditions. The uniqueness-based conclusion that a codebook converges to one particular codebook requires uniqueness just as before. Nor do rates transfer automatically: squared loss can yield quadratic growth near an optimum under suitable assumptions, whereas Euclidean loss has different local behavior. Conclusions that convert center error into partition error also need their own boundary and margin conditions. Although the nearest-center partitions for a fixed codebook are the same for both losses, risk and center behavior can differ.

Common Mistakes and Practical Consequences

  • Using the mean for every distortion. The mean minimizes squared distance, not generally Euclidean distance. For K-medians, use the cellwise geometric-median condition.
  • Differentiating through an atom as if the norm were smooth. At \(X=m\), the directional derivative contributes \(P(X=m)\|h\|\). The resulting condition is an inequality, not necessarily a zero-gradient equation.
  • Assuming every cell has a unique representative. Geometric medians can form a set, as the symmetric two-point example shows. An unused cell has no conditional representative requirement at all.
  • Using the wrong moment assumption. A finite first moment suffices for Euclidean-distance risk; squared-distance risk generally requires a finite second moment. A finite global moment of the matching order also ensures finite conditional loss in every positive-probability cell.
  • Transferring a rate or partition bound without checking its assumptions. Uniform convergence and compactness support consistency, but curvature and boundary conditions used for sharper conclusions must be checked for the loss and distribution at hand.
Key takeaway: Squared-distance quantization is governed cellwise by conditional means; Euclidean-distance quantization is governed by conditional geometric medians, including an atom-sensitive optimality condition. Compactness and uniform-convergence argmin arguments still support K-median consistency when the moment assumptions match the loss, but sharper rates and error conversions require separate justification.

Check Your Understanding

Answer each question by referring to the loss and its assumptions.

  1. What conditional moment is sufficient to make Euclidean-distance risk finite in a cell of positive probability? What moment is sufficient for squared-distance risk?
  2. State the geometric-median condition when the candidate point has no probability mass.
  3. Why does an atom at the candidate median change the zero-gradient condition into an inequality?
  4. For two equally likely points at \((-1,0)\) and \((1,0)\), identify the full set of geometric medians and the squared-distance minimizer.
  5. Which ingredients of an argmin consistency proof can be reused for empirical K-medians, and why do rates not follow automatically?
Clinical Biostats