---
title: Weighted Distance NN Condensing
url: https://www.emergentmind.com/topics/weighted-distance-nearest-neighbor-condensing-wnn
type: topic
---

# Weighted Distance NN Condensing

Weighted Distance Nearest-Neighbor Condensing (WNN) is a framework for data reduction in nearest-neighbor classification, generalizing traditional condensing by introducing learned, positive weights on representatives of the instance space. By leveraging weighted distances in the nearest-neighbor query, WNN enables more compact summarization of labeled datasets while preserving (or even improving) classification accuracy, and it achieves generalization performance guarantees essentially identical to those of standard nearest-neighbor condensing [2310.15951].

## 1. Formal Foundations and Problem Statement

Let $(\mathcal X,d)$ be a separable metric space and $S = \{(x_i, y_i)\}_{i=1}^n \subset \mathcal X \times \{-1,1\}$ a labeled sample. WNN condensing selects a subset $\tilde S \subseteq S$ (the condensed set) and assigns to each $x\in\tilde S$ a positive weight $w(x) \in (0, \infty)$, with the convention $w(x)=1$ for $x\not\in \tilde S$. Classification of a query $q$ employs the **weighted distance**:
\[
\tilde d(q,s) = \frac{d(q,s)}{w(s)}
\]
for $s \in \tilde S$. The WNN classifier is
\[
h_{(\tilde S, w)}(q) = y_{s^*},\qquad s^* = \arg\min_{s \in \tilde S} \tilde d(q,s).
\]
A pair $(\tilde S, w)$ forms a **consistent WNN condensing** if
\[
h_{(\tilde S, w)}(x_i) = y_i \quad \forall\, (x_i, y_i) \in S.
\]
The **weighted condensing problem** seeks such a pair minimizing $|\tilde S|$.

This construction generalizes unweighted nearest-neighbor condensing: setting $w\equiv 1$ recovers the classical framework, while optimized weights may enable dramatically smaller condensed sets.

## 2. Theoretical Analysis and Generalization Properties

### Separation of Representation Power

WNN provides potentially exponential gains in reduction compared to the unweighted regime. For any $n$, there exist datasets $S$ such that:
- The minimal consistent unweighted subset must be of size $\Theta(n)$.
- A consistent WNN condensed set of size $|\tilde S|=2$ suffices, given appropriate weights.

Typical instances include interleaved structures (“banana-shaped” clusters), where unweighted condensing cannot avoid including all points but weighted condensing, by boosting endpoints, can effect a succinct partition [2310.15951].

### Generalization Bounds

For empirically consistent $h_{(\tilde S, w)}$ with $|\tilde S| = m$ and sample size $n$, the probability of error on unseen data satisfies:
\[
\Pr_{(X,Y)}[h_{(\tilde S,w)}(X) \neq Y] \leq \frac{2}{n-m} \left( m\ln(2n) + \ln\frac{n}{\delta} \right)
\]
with probability at least $1-\delta$. A permutation-invariant reconstruction sharpens this to:
\[
\Pr[h_{(\tilde S,w)}(X)\neq Y] \leq \frac{2}{n-m} \left( m \ln \frac{2e n}{m} + \ln \frac{n}{\delta} \right).
\]
These bounds closely track those for unweighted condensing, confirming that the generalization guarantees of WNN are essentially identical to the classical case [2310.15951].

## 3. Greedy Condensing Heuristic and Algorithmic Aspects

The main practical approach is a greedy algorithm analogous to set cover:

- Let $d_{\mathrm{enemy}}(x)$ denote the minimal distance from $x$ to any opposite-label point,
- At each iteration, select $x^*$ maximizing the number of same-label points within $d_{\mathrm{enemy}}(x^*)$ in $S'$, the set of points not yet covered,
- Add $x^*$ to $\tilde S$ with $w(x^*) = d_{\mathrm{enemy}}(x^*)$, remove all points of the same label within this ball from $S'$,
- Iterate until all points are covered.

Formally, each iteration solves:
\[
\max_{x\in S'}\, |\{z \in S':\tilde d(z, x)<1,\, y(z)=y(x)\}|
\]
subject to $w(x) = d_{\mathrm{enemy}}(x)$.

In complexity, a naive implementation needs $O(n^3)$ work for $n$ points, but distance maintenance and spatial indexing can reduce this to $O(n^2)$ or better in practice [2310.15951].

## 4. Bayes Consistency

Let $w_{\mathrm{enemy}}(x)$ denote the minimal distance to an opposite-label point (outside the condensed set, set $w(x)=1$). Consider the (computationally hard) minimal consistent condensed set:
\[
\tilde S^* = \arg\min_{\tilde S \subset S}\{|\tilde S|: h_{(\tilde S, w_{\mathrm{enemy}})} \text{ consistent on } S \}.
\]
Under mild conditions—separable $(\mathcal X, d)$, atomless $X$ distribution, piecewise-continuous Bayes function $\eta(x)$—the classifier $h_{(\tilde S^*, w_{\mathrm{enemy}})}$ achieves risk converging to Bayes risk zero almost surely as $n\to\infty$.

Furthermore, under mild tail assumptions on the metric distribution (e.g., bounded or Gaussian), the greedy WNN condensing heuristic is also Bayes-consistent. The size of its output is at most an $O(\log|\tilde S^*|)$ factor larger than the optimal, so the generalization excess vanishes [2310.15951].

## 5. Empirical Results: Compression and Accuracy

Experiments compare WNN to MSS (modified selected subset), RSS (recent selective subset), and optimal unweighted integer-programming condensing (IP). Condensed set sizes are summarized as follows:

| Dataset     | Points | MSS | RSS | IP (opt. NN) | WNN |
|-------------|--------|-----|-----|--------------|-----|
| Circle      | 200    | 52  | 45  | 7            | 12  |
| Banana      | 200    | 74  | 66  | 32           | 35  |
| Iris        | 100    | 11  | 9   | 2            | 4   |

WNN substantially out-compresses classical heuristics (MSS, RSS) and approaches the performance of optimal unweighted condensing.

On the large-scale notMNIST dataset ($\approx19,000$ points, 10 classes, UMAP-reduced features), WNN approaches the test-set error of uncompressed 1-NN, with a compression ratio of $\sim 20\%$ (retaining only $\sim80\%$ of samples), while MSS and RSS either compress slightly better or worse with greater accuracy degradation [2310.15951].

## 6. Limitations, Open Problems, and Future Directions

The greedy WNN heuristic lacks a constant-factor approximation guarantee and may be improved with more sophisticated approximation strategies or by leveraging advanced geometric data structures. Computational costs remain considerable for very large datasets without specialized acceleration.

Open problems include the computational complexity and hardness of weighted condensing, improved algorithms (e.g., guaranteed $O(\log n)$-approximation), and extension to multi-class problems or broader classes of weight-dependent metric functions.

Future work involves faster nearest-neighbor search structures for weighted distances, alternative or enhanced condensing heuristics with provable properties, and integration with metric learning to adapt or optimize the base distance $d$ in tandem with the condensing process [2310.15951].

Weighted Distance Nearest-Neighbor Condensing thus strictly generalizes classical NN condensing, combines strong theoretical guarantees with dramatic reductions in storage, and presents numerous directions for continued research into scalable, high-fidelity, label-preserving data summarization.

Source: https://www.emergentmind.com/topics/weighted-distance-nearest-neighbor-condensing-wnn