---
title: Condensed Nearest Neighbour (CNN)
url: https://www.emergentmind.com/topics/condensed-nearest-neighbour-cnn
type: topic
---

# Condensed Nearest Neighbour (CNN)

Condensed Nearest Neighbour (CNN) is a class of prototype selection techniques designed to reduce the size of training sets for nearest-neighbour (NN) classification. The canonical CNN algorithm operates by iteratively collecting a subset of the original data such that the reduced set (the condensed set) yields perfect classification of all training points under the 1-NN rule. This process is foundational in prototype reduction, memory-constrained learning, and provides a well-defined testbed for theory at the intersection of learning geometry, combinatorial optimization, and computational efficiency.

## 1. Formal Description and Algorithmic Workflow

Let $T=\{(x_1,c_1),\ldots,(x_n,c_n)\}\subset\mathbb{R}^d\times C$, where $C$ is a finite label set. The CNN algorithm constructs a prototype set $P\subseteq T$ such that the 1-NN classifier induced by $P$ is consistent with the original training set: for every $(x,c)\in T$, the label assigned by the prototype set’s nearest neighbour operator $C_P(x)$ equals $c$. The standard algorithm ([1309.7676], [1007.0085]) proceeds as follows:

```text
P ← ∅
flag ← True
while flag do
  flag ← False
  for each (x,c) ∈ T do
    if C_P(x) ≠ c then
      P ← P ∪ {(x,c)}
      flag ← True
    end if
  end for
end while
```

CNN iterates through $T$ in fixed order: each misclassified training point under current $P$ is added to $P$. The process terminates within $|T|$ steps, and at convergence $P$ is consistent with respect to $T$.

## 2. Theoretical Properties and Upper Bounds

CNN guarantees termination, but its storage complexity is nontrivial to analyze. Christiansen [1309.7676] establishes a margin-based upper bound via a connection to the multiclass perceptron mistake bound. For each “neighborly” feature map $\varphi$ (satisfying that the 1-NN rule is reproduced via a restricted class of linear multiclass perceptron decision functions), define:

- Separability margin $\delta_\varphi > 0$: the minimal margin such that for all $(x,c)\in T$ and all $y\neq c$,
  $$
  w^*\cdot\varphi(x,c) - w^*\cdot\varphi(x,y) \geq \delta_\varphi
  $$
- Radius $R_\varphi$: maximal separation,
  $$
  \forall(x,c)\in T, \forall y\neq c,\quad \|\varphi(x,c)-\varphi(x,y)\|\leq R_\varphi
  $$

The main result is that CNN accumulates at most
$$
\inf_{\varphi}\;\frac{R_\varphi^2}{\delta_\varphi^2}
$$
prototypes, where the infimum is over all neighborly feature maps $\varphi$. This bound is independent of the training set size and depends only on geometric characteristics of the data embedding [1309.7676].

## 3. Algorithmic Complexity and Practical Implementation

Let $m=|P|$ denote the final size of the condensed set. Each pass through $T$ examines $n$ points, with a nearest-neighbour search in $P$ (cost $O(m)$ for linear scan, $O(\log m)$ for spatial structures). Typically, $m\ll n$, so total complexity is subquadratic. Major implementation specifics include:

- Prototype storage in spatial indices (e.g., kd-trees) for efficient NN queries.
- Initialization heuristics: seeding $P$ with one point per class improves boundary coverage.
- Order randomization: different scan orders can yield different $P$, reflecting recognized order-sensitivity.
- Early stopping: practical variants terminate if a pass yields too few additions.

Empirically, CNN can reduce storage by an order-of-magnitude while maintaining high fidelity to the original classifier ([1007.0085], [2310.15951]).

## 4. Extensions, Variants, and Related Condensation Schemes

The nearest-neighbor condensation problem is NP-hard; seeking a minimum consistent subset is computationally intractable [2002.06650]. Notable variants and connections include:

- Fast CNN (FCNN) [2006.15650]: Adds batches of misclassified representatives per iteration. It can fail to guarantee polynomial-size upper bounds due to geometrically adversarial configurations.
- Social-distanced FCNN (SFCNN) [2006.15650]: Adds only a single new point per iteration, yielding a tight upper bound $O(\log(1/\gamma)\,4^{\mathsf{ddim}+1})$, where $\gamma$ is the margin and $\mathsf{ddim}$ is the doubling dimension.
- Weighted Distance Nearest-Neighbor Condensing (WNN) [2310.15951]: Each prototype is assigned an individual positive weight, and classification is by weighted distance. WNN can, in some cases, reduce the prototype set to size $O(1)$—substantially less than possible with standard (unweighted) condensation—while retaining generalization guarantees equivalent to the unweighted case.
- Reduced Nearest Neighbour (RNN): Post-processes CNN’s output by greedily removing redundant prototypes, further shrinking the set at extra computational expense ([1007.0085]).
- Coreset approaches: $\alpha$-selective/consistent subsets can yield theoretical coresets for the NN rule, offering refined guarantees on approximation and subquadratic construction in fixed dimension ([2002.06650]).

## 5. Statistical and Geometric Insights

CNN’s upper bound and empirical efficacy are tightly linked to geometric data properties. A large separation margin leads directly to small prototype sets. The number of classes and feature dimension impact the bound only indirectly, through their influence on available feature maps and achievable margins. Conversely, densely packed, low-margin, or high-noise datasets force CNN to retain larger subsets. Order-sensitivity can cause relevant boundary points to be missed in a single pass, motivating multiple passes or ensemble practices (e.g., combining outputs from several random seeds) ([1007.0085]).

The extension to weighted distances (WNN) introduces an extra axis of flexibility that, in pathological constructions, can yield exponentially better compression [2310.15951]. Moreover, for general metric-space training data where the Bayes classifier has margin and the feature space is separable, WNN and its greedy heuristics can achieve Bayes consistency.

## 6. Practical Performance, Empirical Evidence, and Limitations

Experimental results demonstrate dramatic data reduction: on standard UCI datasets, CNN typically retains only 5–20% of the original set while preserving >95% of the 1-NN test accuracy; WNN and SFCNN can approach the theoretical optimum much more closely ([1007.0085], [2310.15951], [2006.15650]). For high-dimensional or complex data, performance remains dependent on the choice of distance metric and implementation of the base NN search.

The NP-hardness of optimal condensation means all practical methods are heuristic. For many real-world settings, boundary coverage is the principal challenge: CNN may miss necessary prototypes in poorly separated regions or under adversarial scan orders. This issue can be partly remedied by ensemble condensation schemes or by switching to weighted and relaxed variants.

## 7. Connections to Broader Literature and Applications

CNN is a central structureless approach to instance selection, distinct from structure-based NN acceleration methods such as kd-trees or cover-trees, which target query-time complexity rather than storage reduction ([1007.0085]). Prototype selection via CNN serves as a precursor to model compression, memory-efficient inference, and as an ingredient in coreset construction for scalable machine learning ([2002.06650]). Its theoretical underpinnings, particularly the perceptron connection, clarify conditions for effective sample compression and inform methods in active learning and statistical geometry. The adaptability of condensation to weighted distances, as in WNN, opens further potential for tailored memory-reduction in complex metric spaces ([2310.15951]).

Source: https://www.emergentmind.com/topics/condensed-nearest-neighbour-cnn