---
title: Nearest-Mean-of-Exemplars Classification
url: https://www.emergentmind.com/topics/nearest-mean-of-exemplars-classification
type: topic
---

# Nearest-Mean-of-Exemplars Classification

The nearest-mean-of-exemplars (NME) classification paradigm designates each class by a single representative prototype, typically the empirical mean of a set of exemplar embeddings or features. Classification proceeds by assigning queries to the class whose prototype is nearest under a chosen metric, most commonly the Euclidean or cosine distance. Originally rooted in classic pattern recognition as the nearest-class-mean (NCM) classifier, NME has become widely adopted in deep learning for incremental learning, continual learning, open-set recognition, zero-shot learning, and efficient data embedding. By summarizing entire classes by low-dimensional means, NME methods achieve significant computational, storage, and practical advantages while imposing strong inductive biases such as intra-class compactness and inter-class separability.

## 1. Formal Definition and Core Principles

Given a collection of labeled feature vectors $\{(x_i, y_i)\}_{i=1}^N$, where $x_i \in \mathbb{R}^d$ and $y_i \in \{1, \dots, K\}$, the prototype (mean) of class $k$ is computed as:
$$
m_k = \frac{1}{N_k} \sum_{i: y_i = k} x_i, \quad N_k = |\{i : y_i = k\}|
$$
At test time, for any query $x$, the decision rule is:
$$
\hat y = \arg\min_{k} \, d(x, m_k)
$$
where $d(\cdot,\cdot)$ is typically the Euclidean distance $\|x - m_k\|_2$ or its squared form for computational efficiency. This "prototype classifier" reduces both data storage (no need to keep all exemplars) and classification time (no need to compute distances to every training example).

To generalize to neural network representations, a feature extractor $f_\phi(\cdot)$ is trained or fixed, and all $x_i$ are mapped to $f_\phi(x_i)$ before forming class means and performing inference [2510.17338, 1801.02328].

Probabilistic variants often use a softmax over negative distances, introducing a temperature $\tau$:
$$
P_{\text{NCM}}(y = k \,|\, x) = \frac{\exp(-d(f_\phi(x), m_k)/\tau)}{\sum_{j=1}^K \exp(-d(f_\phi(x), m_j)/\tau)}
$$

## 2. Incremental and Continual Learning: Exemplar-based and Exemplar-free

NME classifiers are foundational in class-incremental and online continual learning because they simplify the integration of new classes and mitigate catastrophic forgetting. Two primary strategies exist:

- **Exemplar-based NME**: For each class $c$, a memory buffer $E_c$ of up to $K$ exemplars is maintained. The prototype $m_c$ is the mean of feature embeddings from $E_c$. When new classes arrive, exemplars closest to the new class mean are selected (e.g., herding), and, if budget is exceeded, those farthest from the mean are discarded. During continual learning, exemplars for previously seen classes are replayed, and the NME rule is applied at inference [2008.08336].

- **Exemplar-free NME**: Incremental learning is performed without storing any training exemplars. Instead, per-class running means and counts $(v_c, n_c)$ are maintained using an online mean update:
$$
v_y \leftarrow \frac{n_y - 1}{n_y} v_y + \frac{1}{n_y} f(x), \quad n_y \leftarrow n_y + 1
$$
This model is robust and outperforms exemplar-based methods for small memory budgets ($Q \leq 2000$ images), with competitive performance for much larger budgets. Both memory cost and update time scale as $O(Kd)$. No raw input data are stored, addressing privacy and storage concerns [2202.05491].

Hybrid approaches sometimes use a combination of feature means and reduced exemplar sets, with candidate selection to address class-imbalance or bias [2202.05491].

## 3. NME in Deep Embedding and Metric Learning

NME is often used as the classifier on top of deep embedding architectures, facilitating both analytic understanding and training stability.

- **Anchor-based NME** [Editor's term]: Fixed class prototypes ("anchors") $a_c$ are predefined on the unit hypersphere and not updated during training [1804.08087]. The network is optimized to map each sample to its class anchor while maximizing angular separation between anchors. The resulting loss is a softmax over negative distances to the anchors, with variants using Euclidean or cosine metrics:
  - Euclidean: $M_E(f, a) = \|f - a\|_2$
  - Cosine: $M_C(f, a) = 1 - (f \cdot a) / (\|f\|_2 \|a\|_2)$
Strong intra-class compactness and inter-class separability are enforced by the structure of anchor vectors.

- **Exemplar-centered MCML/Metric Collapse**: Instead of prototypes being the class mean, a small set of exemplars per class are designated, and the embedding space is trained to maximize class-wise collapse onto exemplars. The loss function only requires $O(nz)$ computations (with $n$ samples and $z$ exemplars, $z \ll n$), offering a speed-up over $k$-NN and pairwise methods [1702.06602].

## 4. Application Domains

NME underpins multiple learning paradigms:

- **Incremental and continual learning**: Enables rapid class extension and efficient inference without retraining the entire model; critical for edge or privacy-constrained systems [2202.05491, 2008.08336, 1801.02328].
- **Open-set recognition**: Facilitates detecting samples not belonging to any known class by low maximum class probability or divergence between feature- and logit-based distributions [2510.17338].
- **Zero-shot learning**: Predicts prototypes for unseen classes in embedding space by regressing from semantic to visual features, then classifies novel instances by nearest prototype [1605.08151].
- **Dimensionality reduction and visualization**: Results in compact and interpretable representations for classification and exploration [1702.06602].

## 5. Empirical Results and Performance Considerations

The efficacy of NME classifiers is substantiated across domains:

- **Benchmarks**: On MNIST, CIFAR-10, and CIFAR-100, anchor-based NME achieves error rates rivaling softmax- and margin-based losses, often improving by 1–2% on challenging datasets [1804.08087].
- **Incremental Learning**: Exemplar-free NME outperforms all exemplar-based replay baselines for small replay budgets and narrows the gap to the offline upper-bound for large class sets, e.g., Split CIFAR-100 and Food-1k [2202.05491].
- **Open-set Recognition**: Achieves AUROC of 93.41 and 95.35 on wildlife datasets with a post-hoc NME probability that does not require retraining [2510.17338].
- **Zero-shot Learning**: Nearest-mean-of-exemplars approach scales to thousands of unseen classes (e.g., on ImageNet) with practical accuracy and efficiency, using regressed class prototypes [1605.08151].
- **Computational Complexity**: At test time, cost is $O(Kd)$, where $K$ is the number of classes and $d$ is the feature dimension. This offers substantial speedups over kNN and pairwise metric methods, especially when the number of prototypes per class is reduced [1702.06602].

## 6. Theoretical and Practical Limitations

- **Unimodal Assumption**: All NME approaches model classes as single clusters; performance degrades on highly multi-modal class distributions or classes with complex structure [1801.02328].
- **Feature Drift**: Incrementally learned prototypes may become suboptimal as feature extractors are updated, potentially requiring periodic recomputation or advanced rehearsal strategies [2008.08336].
- **Scalability**: For large numbers of classes, the linear growth in prototype storage and distance computations may become a bottleneck, partly alleviated by candidate selection or hierarchical structures [2510.17338].
- **Adaptation and Generalization**: Fixed-feature or anchor-based models may underperform on genuinely novel or outlier classes if the embedding does not provide sufficient class separation [2202.05491, 1804.08087].

## 7. Extensions and Research Directions

Recent and emerging directions include:

- **Margin-based and prototype-separation losses**: Adding explicit inter-class margin terms to further enforce separation between class means in embedding space [1804.08087, 2008.08336].
- **Cosine-based distances**: Empirically, cosine similarity sometimes outperforms Euclidean metrics in high-dimensional spaces, especially for normalized features [1804.08087, 2008.08336].
- **Generative Replay**: To compress prototype memory, generative models may be used to synthesize exemplars for old classes [2008.08336].
- **Agreement-driven open-set detection**: Combining NME-based probabilities with logits-based softmax for robust open-set recognition [2510.17338].
- **Zero-shot extrapolation**: Employing kernel regression to predict unseen class means from semantic embeddings, leading to rapid extension to unseen categories [1605.08151].

The nearest-mean-of-exemplars methodology thus constitutes a unifying principle underpinning efficient, scalable, and incrementally extensible classification systems across deep learning, continual learning, metric learning, and beyond.

Source: https://www.emergentmind.com/topics/nearest-mean-of-exemplars-classification