WorksComputer Science
Evolutionary Adaptive Metric Learning: A Multi-Objective Framework for Learning Local Distance Functions in Nearest Neighbor Classification
Abstract
Nearest neighbour classifiers inherit the geometry of their distance function. Fixed distances and globally learned metrics apply the same geometry throughout the input space, although relevant feature directions may vary across regions. We propose EAML (Evolutionary Adaptive Metric Learning), a framework that learns instance-dependent positive-definite metrics through a low-dimensional parameterization. Each local metric combines an input-dependent diagonal scaling, generated by softmax interpolation between anchor points, with a global low-rank correlation component. A real-coded elitist genetic algorithm optimizes the parameters using a scalar objective combining leave-one-out prediction error, robustness, metric smoothness, and regularization. We establish positive definiteness, metric equivalence, existence of an optimal solution, and Lipschitz continuity of the metric field. We further investigate prediction stability, generalization bounds, and evolutionary convergence under explicit assumptions. Experiments on synthetic data with region-dependent feature relevance show that EAML can recover local metric variations and outperform global metrics. Evaluation on thirteen public datasets using nested 5-fold cross-validation reveals a more nuanced picture: EAML improves performance on selected datasets but does not significantly outperform global metric baselines overall. Additional experiments show that global diagonal metrics can be preferable under nuisance features and test-time noise. These findings identify the conditions under which evolutionary local metric learning is beneficial and highlight its practical limitations.
Introduction
The -nearest neighbour (-NN) rule [3] classifies a point by looking at its closest training examples, so its behaviour is entirely determined by the notion of closeness. The Euclidean distance treats all features alike. The Mahalanobis distance [19] rescales and decorrelates them using the global covariance. Metric learning goes further and fits a Mahalanobis matrix to the labels: from side information [29], by maximising a stochastic leave-one-out score (NCA, [12], with large-margin constraints (LMNN, [27]) or with an information-theoretic regulariser (ITML, [4]); see Bellet et al. [2], Kulis [17] for surveys.
All these metrics are global. They apply a single linear geometry to the entire input space, yet in real data the relevant features, their correlations and the noise level can depend on the region. A feature that separates two classes in one part of the space may be pure noise elsewhere. Locally adaptive rules address this. DANN [13] and the method of Domeniconi et al. [11] reshape the neighbourhood of each query from local statistics. Multi-metric LMNN [27] learns one metric per class or cluster. Parametric local metric learning (PLML, [26]) combines basis metrics anchored in the input space with manifold regularisation. Adaptive neighbourhood sizes form a related line of work [18, 20].
Question. Can we learn, jointly, a local metric field, its smoothness and its robustness, while keeping the complexity of the learned object under explicit mathematical control? And does local adaptivity actually help on standard benchmarks once every competitor is tuned with the same care? We study these questions with an evolutionary approach. The optimisation problem combines non-convex, non-differentiable-looking terms (margins, minima over training points) with box constraints, and a GA handles it without gradients.
Contributions.
Model. We introduce a family of local metrics generated by parameters, with anchors and rank , independent of the sample size . The family contains the Euclidean metric, global diagonal metrics () and global low-rank corrections (§ 3).
Algorithm. EAML evolves these parameters with an elitist real-coded GA [6, 7]. Its fitness is a continuous scalarisation of four objectives: classification, robustness, smoothness and complexity (§ 3).
Theory. We prove positivity and metric equivalence, existence of an optimal metric, Lipschitz regularity of the metric field, robustness of -NN decisions to perturbations, a uniform generalisation bound and the almost-sure convergence in value of the GA (§ 4).
Evidence. We compare EAML with seven baselines (Euclidean, Manhattan, Mahalanobis, NCA, LMNN, ITML and an evolved global diagonal metric) on a controlled problem and on thirteen datasets, including a Fashion-MNIST subsample [28], with nested -fold cross-validation, noise-robustness tests and ablations (§ 5). We report where the local model helps and where it does not.
Related work
Global metric learning. Most supervised metric learning methods learn a single positive semi-definite matrix such that brings same-class points together. Xing et al. [29] posed it as a convex problem with pairwise constraints. NCA [12] maximises the expected LOO accuracy of a stochastic neighbour rule, which is the classification term we also use. LMNN [27] enforces large margins between target neighbours and impostors. ITML [4] regularises towards a prior with a LogDet divergence. Generalisation guarantees for metric learning have been derived through algorithmic robustness [1].
Local metrics and adaptive neighbourhoods. DANN [13] and ADAMENN [11] estimate a query-specific metric from local class statistics. Multi-metric LMNN [27] assigns one metric per cluster. PLML [26] expresses each local metric as a combination of anchored basis metrics with smooth weights, and our gating construction is close in spirit. Closely related are methods that adapt the neighbourhood size rather than its shape, for instance with neural networks [20] or with curvature estimates of the data manifold [18].
Evolutionary metric and feature weighting. GAs were used early on to learn feature weights for -NN [15], and later for joint feature selection, weighting and extraction [23]. These approaches evolve a global diagonal metric, which corresponds to our GA-GLOBAL baseline (, ). Multi-objective evolutionary algorithms such as NSGA-II [8] return Pareto fronts. We use a scalarisation instead and leave the Pareto analysis for future work. Our GA analysis follows the classical argument for elitist algorithms [24].
The EAML model and algorithm
A parametric family of local metrics
Let , with standardised features. We choose anchors (the -means centres of the training fold) and the gating
where is the median squared distance from a training point to its closest anchor. Each anchor carries a vector of log-scales . The local log-scale field and the local metric are
with . This is the factorisation with . The distance from a query to a reference point uses the metric of the query:
The genome is , of dimension . The case , is a global diagonal metric, and gives the Euclidean metric (up to the factor ).
Objective
Let be the query points used in the fitness: all points, or a random subset of size when . We minimise
with the following four terms.
Classification (stochastic-neighbour LOO error, as in NCA):
Algorithm 1: EAML: Evolutionary Adaptive Metric Learning
Input: standardised training set ; anchors ; rank ; weights ; GA settings Output: metric parameters and number of neighbours
Compute anchors by -means, the temperature and the gating ;
Select the query set and the Euclidean 5-NN graph of ;
Initialise the population with (Euclidean) and small random genomes;
for do
Tournament selection; SBX crossover; annealed Gaussian mutation; reflection into ;
Evaluate for every offspring (two matrix products of size );
Elitist replacement;
if no improvement during 15 generations then break;
best genome; LOO accuracy of -NN under ;
Prediction for : compute , , the distances , and return the majority label of the nearest neighbours.
Robustness (relative margin hinge): with and the distances from to its nearest same-class and other-class training points, and , we set with target . Theorem 4 links these margins to decision stability.
Smoothness of the metric field on the Euclidean 5-NN graph of :
Complexity (shrinkage towards the Euclidean metric): .
We use , and on every dataset. All terms are continuous in , which is what Theorems 2 and 6 require.
Genetic search
Algorithm 1 summarises the method. The GA uses a population of 30 genomes and 40 generations, i.e. at most 1230 objective evaluations. Selection is by tournament of size 3. Simulated binary crossover [6, 7] is applied with probability 0.9 and index 15. Mutation is Gaussian with per-gene probability 0.1 (at least one gene per offspring) and a step that anneals from 0.25 to 0.02 of the box width. Offspring are reflected into the box . The two best parents survive, and the run stops early after 15 generations without improvement. The initial population contains the Euclidean genome and 29 genomes drawn uniformly in times the box. After evolution, the number of neighbours is chosen by LOO accuracy of the -NN rule under the learned metric, exactly as for all baselines.
Theoretical analysis
Throughout this section the training sample, the anchors and the gating temperature are fixed. We assume the following.
Assumption 1. The (standardised) inputs lie in the ball , the anchors satisfy , and the genome lies in the box .
All proofs are given in Section A.
Positivity and existence
Theorem 1 (Positivity and metric equivalence). For every and , is symmetric and
Consequently, for every fixed , is the distance induced by a norm, and .
Theorem 2 (Existence of an optimal metric). The objective of (4) is continuous on . Hence it attains its minimum: there is with .
The continuity of is the reason why we use the stochastic neighbour error instead of the 0–1 error of the -NN rule: the latter is piecewise constant in and need not attain its infimum.
Regularity of the metric field
Theorem 3 (Lipschitz metric field). Under Assumption 1, let . For all and ,
Small temperatures (sharp gating) and large log-scales allow the metric to change quickly; the smoothness penalty controls the same quantity empirically on the training graph.
Robustness to perturbations
Theorem 4 (Robustness of the neighbour structure). Under Assumption 1, let and let range over the training points. Then
Consequently: (i) the 1-NN prediction at is unchanged whenever , where () is the distance to the nearest training point of the predicted class (of any other class); (ii) the set of nearest neighbours of , and hence the -NN prediction, is unchanged whenever .
The theorem explains the role of the robustness term: enlarges the relative hit/miss margins on the training points, while , controlled by , , and the gating, bounds how fast distances can move.
Generalisation
Let with over the training points: this is the probability of error of the stochastic neighbour rule, whose empirical LOO version is . Write and for its average on an i.i.d. sample of size independent of the training sample.
Theorem 5 (Uniform generalisation). Under Assumption 1, let , and . For every and , with probability at least , simultaneously for all ,
With the complexity term is of order . It grows with the number of evolved parameters , not with the number of training points, and it holds for any produced by any search procedure. This is the formal reason for generating the local matrices from a small parametric family instead of learning one free matrix per training point.
Convergence of the evolutionary search
Theorem 6 (Convergence in value). Run the GA of Algorithm 1 without the stagnation stop. Let be the best objective value found up to generation and . Then is non-increasing and, for every , there is with . Hence almost surely.
The result is asymptotic: can be extremely small when is large, so it guarantees that the search cannot stall at a non-optimal value forever, not that a finite budget suffices. We measure the finite-budget behaviour empirically in § 5.
Proposition 7 (Seeded dominance). The genome encodes the Euclidean metric up to the factor . Since it is in the initial population and replacement is elitist, : EAML never does worse than the Euclidean metric on its training objective.
Proposition 8 (Cost). With query rows in the fitness, one evaluation of costs time and memory, dominated by two matrix products. Prediction costs per query.
Experiments
Setup
Datasets. We use thirteen public datasets (Table 1). Iris, Wine, Breast cancer and Digits ship with scikit-learn [22]; eight others come from the UCI repository [16]. Fashion-MNIST [28] is represented by a stratified subsample of 3000 test images. For this dataset the pixels are standardised and reduced to 40 principal components inside each training fold.
| Dataset | Imb. ratio | |||
| Fashion-MNIST | 3000 | 10 | 1.0 | |
| Digits | 1797 | 61 | 10 | 1.1 |
| Iris | 150 | 4 | 3 | 1.0 |
| Wine | 178 | 13 | 3 | 1.5 |
| Breast cancer | 569 | 30 | 2 | 1.7 |
| Sonar | 208 | 60 | 2 | 1.1 |
| Ionosphere | 351 | 33 | 2 | 1.8 |
| Pima | 768 | 8 | 2 | 1.9 |
| Glass | 214 | 9 | 6 | 8.4 |
| Seeds | 210 | 7 | 3 | 1.0 |
| Banknote | 1372 | 4 | 2 | 1.2 |
| Haberman | 306 | 3 | 2 | 2.8 |
| Ecoli | 336 | 7 | 8 | 71.5 |
Table 1. Datasets: instances , features (after removing constant ones; Fashion-MNIST is reduced by PCA inside each fold), classes , and imbalance ratio.
Methods. All methods use the same -NN rule, with chosen by LOO accuracy on the training fold among , so they differ only in the metric. The baselines are: Euclidean; Manhattan; Mahalanobis (regularised inverse covariance); NCA [12] (scikit-learn, 100 iterations); LMNN [27] and ITML [4] (metric-learn, 5, default settings, 3 target neighbours and 200 iterations for LMNN); and GA-global, which is EAML with and , i.e. an evolved global diagonal metric in the spirit of Kelly and Davis [15], Raymer et al. [23]. EAML uses , , , and . These values were fixed before running the benchmark and are identical for all datasets. LMNN could not be run on any Ecoli fold, because metric-learn rejects classes with fewer training points than target neighbours, and ITML failed on one Haberman fold. In these cases the method falls back to its initial (Euclidean) metric, so on Ecoli LMNN coincides with the Euclidean baseline.
Protocol. We use repeated stratified 5-fold cross-validation (25 splits per dataset, 325 in total). All preprocessing, metric learning and the choice of take place inside the training fold [25]. Besides accuracy and macro-F1, we measure robustness by adding Gaussian noise , , to the standardised test points. Across datasets we use the Friedman test, the Nemenyi critical difference and Wilcoxon signed-rank tests with Holm correction [9, 10]. Within a dataset we use the corrected resampled -test of Nadeau and Bengio [21]. Ablations are run on the first repetition (5 splits) of the eleven datasets other than Digits and Fashion-MNIST, for which five additional EAML runs per split were too costly.
Controlled study: a region-dependent relevant feature
We draw uniformly. The coordinate selects a region, and the label is if and otherwise. The other coordinates are nuisance features. A global metric has to keep both and ; a local metric can drop the irrelevant one in each region. We train on 800 points, test on 3000, and repeat 10 times.
Without nuisance features (Table 2, Figure 1), EAML learns what the problem requires. On the left it gives a weight about 2.3 times that of , and on the right the ratio is reversed. It is the most accurate method (93.2% against 91.4% for GA-global, ). With nuisance features the order changes: GA-global stays above 90%, whereas EAML falls to 88.2% and 83.1% (both in favour of GA-global). The learned weights show why. With 4 or 8 nuisance features, the weights of and no longer swap between the regions. The -means anchors are computed in the full noisy space, so they do not align with the region boundary . The genome also grows with the dimension () while the evaluation budget does not. Global metric learners that ignore nuisance features (Euclidean, LMNN) collapse to about 59%, and NCA degrades to 75%.
| Euclidean | NCA | LMNN | GA-global | EAML | left | right | ||
| 0 | 90.95 | 89.91 | 90.90 | 91.40 | 93.22 | 0.002 | 13.95/5.95 | 5.20/14.99 |
| 4 | 64.91 | 86.51 | 66.14 | 91.46 | 88.23 | 0.002 | 11.49/12.42 | 10.14/13.32 |
| 8 | 58.47 | 75.34 | 58.94 | 90.43 | 83.12 | 0.002 | 10.17/10.88 | 9.70/11.04 |
Table 2. Synthetic benchmark: test accuracy (%, mean of 10 replications) for nuisance features. : Wilcoxon signed-rank test between EAML and GA-global (two-sided; the better method is in bold). Last columns: mean local weights , learned by EAML for in the left () and right regions.
Figure 1. Synthetic benchmark. Left: local weights of and learned by EAML on the test points of one replication without nuisance features, plotted against the region coordinate . The weights swap between the regions. Right: accuracy versus number of nuisance features (mean s.d.).
| Dataset | Euclidean | Manhattan | Mahalanobis | NCA | LMNN | ITML | GA-global | EAML |
| Fashion-MNIST | 80.2 ± 1.3 | 80.3 ± 1.3 | 80.2 ± 1.3 | 76.6 ± 1.7 | 80.8 ± 1.0 | 80.5 ± 1.1 | 79.8 ± 1.1 | 79.9 ± 1.4 |
| Digits | 97.6 ± 0.5 | 98.0 ± 0.6 | 95.6 ± 1.2 | 97.8 ± 0.6 | 98.0 ± 0.7 | 98.0 ± 0.8 | 97.7 ± 0.9 | 97.5 ± 0.7 |
| Iris | 96.3 ± 3.5 | 94.5 ± 4.1 | 90.3 ± 4.5 | 95.9 ± 3.9 | 96.3 ± 3.5 | 96.9 ± 2.5 | 94.5 ± 3.6 | 94.5 ± 4.4 |
| Wine | 96.3 ± 2.5 | 97.2 ± 2.3 | 93.5 ± 3.4 | 96.6 ± 2.9 | 96.4 ± 3.3 | 98.3 ± 2.3 | 95.7 ± 2.8 | 97.4 ± 2.9 |
| Breast cancer | 96.6 ± 1.5 | 96.7 ± 1.8 | 84.0 ± 2.7 | 95.3 ± 1.4 | 96.7 ± 1.5 | 95.5 ± 1.7 | 95.1 ± 1.6 | 96.3 ± 1.6 |
| Sonar | 84.9 ± 5.1 | 85.2 ± 5.2 | 76.5 ± 5.6 | 86.7 ± 3.9 | 87.3 ± 4.7 | 78.3 ± 4.8 | 85.0 ± 6.4 | 84.6 ± 6.2 |
| Ionosphere | 85.7 ± 3.7 | 90.6 ± 3.1 | 85.5 ± 3.8 | 89.2 ± 3.1 | 87.3 ± 3.5 | 88.1 ± 2.7 | 90.0 ± 3.1 | 90.3 ± 2.8↑ |
| Pima | 75.0 ± 3.0 | 75.0 ± 2.8 | 73.6 ± 3.5 | 69.0 ± 3.9 | 74.9 ± 3.5 | 75.7 ± 3.7 | 76.1 ± 3.3 | 73.6 ± 3.5 |
| Glass | 69.8 ± 5.6 | 71.6 ± 6.0 | 66.0 ± 5.5 | 71.1 ± 5.3 | 69.2 ± 6.1 | 61.0 ± 5.9 | 77.4 ± 5.3 | 76.8 ± 5.4↑ |
| Seeds | 92.5 ± 3.7 | 92.3 ± 3.2 | 94.3 ± 3.3 | 93.2 ± 3.7 | 92.5 ± 3.8 | 95.8 ± 2.9 | 93.0 ± 2.9 | 91.7 ± 3.5 |
| Banknote | 99.8 ± 0.3 | 99.9 ± 0.2 | 100.0 ± 0.0 | 100.0 ± 0.0 | 99.8 ± 0.3 | 100.0 ± 0.0 | 99.8 ± 0.3 | 99.9 ± 0.3 |
| Haberman | 74.8 ± 3.7 | 74.4 ± 3.6 | 75.0 ± 4.1 | 71.0 ± 6.3 | 74.8 ± 3.5 | 74.4 ± 3.4 | 74.6 ± 4.3 | 73.2 ± 3.8 |
| Ecoli | 86.3 ± 3.6 | 85.2 ± 3.2 | 85.9 ± 3.5 | 74.0 ± 14.4 | 86.3 ± 3.6 | 85.9 ± 3.5 | 84.8 ± 4.2 | 84.6 ± 3.4 |
| Mean acc. | 87.37 | 87.76 | 84.65 | 85.88 | 87.72 | 86.80 | 87.98 | 87.72 |
| Mean rank | 4.65 | 3.65 | 5.69 | 5.00 | 3.54 | 3.46 | 4.77 | 5.23 |
Table 3. Test accuracy (%, mean ± s.d. over 25 nested splits). Bold: best per row. ↑/↓: EAML significantly better/worse than Euclidean (corrected resampled -test, ). Mean rank: average Friedman rank (lower is better).
| Baseline | W/T/L | sig. better/worse | ||
| Euclidean | 4/0/9 | 0.414 | 1.000 | 2/0 |
| Manhattan | 3/1/9 | 0.062 | 0.438 | 0/0 |
| Mahalanobis | 7/0/6 | 0.110 | 0.659 | 4/0 |
| NCA | 8/0/5 | 0.146 | 0.732 | 2/0 |
| LMNN | 4/0/9 | 0.376 | 1.000 | 2/0 |
| ITML | 4/0/9 | 0.635 | 1.000 | 1/1 |
| GA-global | 5/1/7 | 0.395 | 1.000 | 0/0 |
Table 4. Pairwise comparison of EAML with each baseline over the 13 datasets: wins/ties/losses, Wilcoxon -value, Holm-adjusted -value, and number of datasets where EAML is significantly better/worse (corrected resampled -test).
Benchmark results
Tables 3 and 4 summarise the benchmark. Overall, no method stands out: the Friedman test does not reject equal performance (, ). ITML (3.46), LMNN (3.54) and Manhattan (3.65) have the best mean ranks. GA-global has the highest mean accuracy (87.98%) but a middle rank (4.77). EAML ranks 5.23, with a mean accuracy of 87.72%. The differences between EAML and every baseline are not significant across datasets (all Holm-adjusted ).
The local model helps on two datasets. On Glass, EAML improves on the Euclidean metric by 7.0 points (76.8% vs. 69.8%), and on Ionosphere by 4.6 points; both differences are significant. On these datasets the global evolved metric does about as well (77.4% and 90.0%), so the gain mainly comes from evolving feature weights rather than from locality. Elsewhere EAML loses up to 1.7 points to the Euclidean metric (Iris, Ecoli, Haberman, Pima), although no loss is significant.
Robustness. Table 5 and Figure 2 show that the robustness term does not translate into better robustness to test-time noise. At , EAML loses 5.8 points on average, against 3.8 for the Euclidean metric and 4.1 for LMNN. It nevertheless degrades less than GA-GLOBAL (6.4),
Figure 2. Mean accuracy over the 13 datasets as a function of the test-time noise level.
| Euclidean | Manhattan | Mahalanobis | NCA | LMNN | ITML | GA-global | EAML | |
| Mean acc., | 87.37 | 87.76 | 84.65 | 85.88 | 87.72 | 86.80 | 87.98 | 87.72 |
| Mean rank, | 4.65 | 3.65 | 5.69 | 5.00 | 3.54 | 3.46 | 4.77 | 5.23 |
| Mean acc., | 86.08 | 86.54 | 77.71 | 83.46 | 86.22 | 84.24 | 85.80 | 86.02 |
| Mean rank, | 3.77 | 2.69 | 6.54 | 5.96 | 2.92 | 5.04 | 4.54 | 4.54 |
| Mean acc., | 83.57 | 83.49 | 70.31 | 79.39 | 83.62 | 78.44 | 81.57 | 81.93 |
| Mean rank, | 2.19 | 2.69 | 6.77 | 6.00 | 2.42 | 6.27 | 4.88 | 4.77 |
| Mean drop at | 3.80 | 4.27 | 14.34 | 6.49 | 4.10 | 8.36 | 6.41 | 5.79 |
Table 5. Robustness to Gaussian noise added to the standardised test points (13 datasets).
NCA (6.5), ITML (8.4) and Mahalanobis (14.3). The main reason is that the learned metrics are sharp: the stochastic-neighbour term rewards metrics under which the nearest same-class point dominates. As a result, EAML and GA-global select in most folds (median , as for NCA, against 4 to 6 for the other metrics, Table 6), and the 1-NN rule is the most sensitive to noise. This is consistent with Theorem 4: the guarantee depends on the hit/miss margin relative to , a ratio that a mere rescaling of leaves unchanged, so sharper metrics do not buy robustness by themselves.
| Euclidean | Manhattan | Mahalanobis | NCA | LMNN | ITML | GA-global | EAML | |
| Macro-F1 (mean) | 84.04 | 84.25 | 80.86 | 82.41 | 84.40 | 82.86 | 84.91 | 84.28 |
| Macro-F1 (rank) | 4.69 | 3.92 | 6.00 | 5.00 | 3.54 | 3.46 | 4.46 | 4.92 |
| Fit time, median over datasets (s) | 0.00 | 0.00 | 0.00 | 0.09 | 0.51 | 0.25 | 3.62 | 3.93 |
| Fit time, Fashion-MNIST (s) | 0.2 | 0.1 | 0.1 | 22.7 | 9.1 | 29.7 | 162.2 | 171.1 |
| Median selected | 6 | 5 | 4 | 1 | 6 | 6 | 1 | 1 |
Table 6. Macro-F1, wall-clock training time per fold (one CPU core) and median selected .
Cost. The median training time of EAML is 3.9 s per fold, against less than 0.6 s for NCA, LMNN and ITML. On the largest problem (Fashion-MNIST, 2400 training points, 40 dimensions) it takes 171 s, against 9–30 s for the gradient-based learners.
Search behaviour
The GA reduces the training objective to 0.58 times its Euclidean value on average, from 0.08 on Banknote to 0.89 on Haberman. However, every run used all 40 generations without triggering the stagnation stop, and the curves in Figure 3 are still decreasing at the end. The search budget is therefore binding. This is consistent with the asymptotic nature of Theorem 6: almost-sure convergence in value says nothing about the speed at which a 366-dimensional genome (Digits) is optimised with 1230 evaluations.
Figure 3. Best objective value relative to the Euclidean genome, per generation (mean and 10–90% band over 25 folds). The dashed line is the seeded starting point (Theorem 7).
| Variant | Acc. | Rank | Acc. | Time | |||
| EAML | 87.95 | 2.88 | 81.70 | 0.577 | 0.114 | 0.293 | 3.8 |
| EAML (no robustness) | 87.25 | 4.14 | 81.16 | 0.477 | 0.113 | 0.332 | 3.3 |
| EAML (no smoothness) | 88.33 | 2.50 | 81.48 | 0.543 | 0.117 | 0.289 | 2.9 |
| EAML (no low-rank, ) | 87.97 | 3.95 | 80.34 | 0.565 | 0.119 | 0.299 | 3.2 |
| EAML (random search) | 87.31 | 3.23 | 80.69 | 0.684 | 0.138 | 0.331 | 1.9 |
| EAML (NCA term only) | 87.55 | 3.95 | 81.53 | 0.442 | 0.113 | 0.331 | 3.1 |
Table 7. Ablations (first repetition, 11 datasets): mean accuracy (%), mean rank among the six variants, mean accuracy at , objective relative to the Euclidean genome, final and , median fit time (s).
Ablation study
Table 7 isolates the design choices. The numbers in the column are not comparable across rows when the objective itself differs.
Robustness term. Removing it lowers accuracy (87.25% vs. 87.95%) and the noisy accuracy (81.16% vs. 81.70%), and gives the worst rank. This is the only term whose removal clearly hurts.
Smoothness term. Removing it slightly improves accuracy (88.33%, best rank), so with our default weight the smoothness prior is too strong for these datasets.
Low-rank term. With the clean accuracy is unchanged but the noisy accuracy drops by 1.4 points.
Search. Random search with the same budget reaches a worse objective (0.68 vs. 0.58 of the Euclidean value) and a lower accuracy (87.31%). The genetic operators do matter.
NCA term only. Optimising only lowers accuracy by 0.4 points.
Learned geometry. Figure 4 shows the anchor log-scales learned on Glass, the dataset where EAML gains most. The anchors disagree substantially. For example, the refractive index (RI) and potassium (K) are strongly up-weighted near anchor 1 and down-weighted near anchor 4. This confirms that the model does use its local degrees of freedom when the data allow it.
Figure 4. Log-scales learned at the four anchors on Glass (first fold). Positive values increase the weight of a feature near that anchor.
Discussion and limitations
When do local metrics pay off? Locality helps when (i) the relevant directions genuinely change across the space and (ii) the gating can see the regions. The controlled study meets both conditions without nuisance features, and EAML then outperforms every global metric. When nuisance dimensions blur the unsupervised gating, or when the data are close to homogeneous, the additional degrees of freedom cost more search effort and variance than they bring. A global evolved metric is then preferable. On the thirteen benchmarks, no metric learner, global or local, significantly beats the others, which is a useful reminder that careful nested evaluation of metric learning often yields small differences.
Limitations. (i) The search budget is binding (Figure 3). Our convergence theorem is asymptotic and does not bound the number of generations. (ii) The anchors are unsupervised; supervised or evolved anchors, or a gating on the learned metric itself, are natural fixes for the misalignment observed with nuisance features. (iii) The stochastic-neighbour term produces sharp metrics and , which hurts robustness. A temperature or margin constraint on the scale of would counter this. (iv) The generalisation bound concerns the stochastic neighbour risk on an independent sample, not the LOO-selected majority vote. (v) The objective is a fixed scalarisation; a Pareto approach (e.g. NSGA-II, [8]) would expose the accuracy–robustness trade-off directly. (vi) Training is one to two orders of magnitude slower than gradient-based metric learners.
Future work. The results point to three concrete steps: a larger or adaptive evaluation budget with warm starts from GA-GLOBAL; supervised placement of anchors; and multi-objective evolution of local metrics, with the theory above applied to each Pareto-optimal solution.
Conclusion
We introduced EAML, an evolutionary framework that learns a field of local Mahalanobis metrics from a small set of generating parameters, under a continuous multi-objective criterion. The framework comes with guarantees on positivity, existence, regularity, robustness, generalisation and convergence in value of the search. Experiments show that local metrics recover region-dependent geometry when it exists and the regions are identifiable. On standard benchmarks their benefit is confined to a few datasets and does not survive nuisance features or test-time noise, where a global evolved metric is more reliable. These positive and negative findings delimit the regime in which evolutionary local metric learning is worth its cost.
Code and data availability. The Python implementation of EAML, the baselines and the scripts that reproduce every table and figure of this paper are available from the corresponding author upon request. All datasets used in this study are publicly available (Table 1).
Proofs
Proof of Theorem 1. is diagonal with entries , and , so . Since is a convex combination of vectors in , every entry of is at most . Moreover . Hence . For fixed , is a norm of , and the two-sided bound follows from the eigenvalue bounds.
Proof of Theorem 2. For fixed , is a finite sum of products of exponentials and polynomials in , hence continuous. is a finite combination of of these quantities, hence continuous. Each and is the square root of a minimum of finitely many continuous functions, hence continuous. (If a class has a single training point, is set to the constant .) Since the implemented ratio has denominator , is continuous. and are polynomials in (the gating does not depend on ). Thus is continuous on the compact box , and the Weierstrass theorem gives a minimiser.
Proof of Theorem 3. Write and , so that . The softmax gives with , hence . Therefore , and by the mean value theorem on the convex set , . Since , . The terms and do not depend on , and the operator norm of a diagonal matrix is its largest absolute entry, which gives the claim.
Proof of Theorem 4. Let , and . By the triangle inequality,
The second term is at most (Theorem 1). For the first, , so . By Theorem 3, , so the first term is at most , because . This proves the bound with . Every distance from the query to a training point therefore moves by at most . If two such distances differ by more than , their order is preserved. Applied to the nearest hit and miss, this gives (i): applied to the -th and -th neighbours, it shows that the -NN set, and hence the vote, is unchanged, which gives (ii).
Proof of Theorem 5. Lipschitz property in . Fix and let . Writing with , we have , so and . Next, with and , and . Summing absolute values, and . Hence , and for (a convex set), . Combining both steps, for all , so the same holds for and .
Covering and union bound. A grid with points per coordinate covers within -distance , so it has points. Since , Hoeffding’s inequality [14] and a union bound give, with probability at least , for all grid points . For any , choosing the closest grid point changes and by at most each, which yields the bound.
Proof of Theorem 6. Monotonicity. The best parents enter the truncated merged population, so the best value never increases.
Hitting probability. Fix and let . By continuity (Theorem 2), is relatively open in and contains a minimiser, so . Consider any offspring, with pre-mutation genome . All genes are mutated with probability at least : one gene is forced, and the others mutate independently with probability . Conditionally on this, the offspring is the coordinate-wise reflection into of , , where holds the box widths and . Its density at any is at least that of the unreflected Gaussian. Since , this density is at least . Hence each offspring lands in with probability at least , whatever the past. With at least one offspring per generation, .
Almost-sure convergence. By Borel–Cantelli, eventually, almost surely, for each rational . Intersecting over these countably many events and using monotonicity gives almost surely.
Proof of Theorems 7 and 8. For , , and , so . The seed is evaluated at generation 0, and by monotonicity the returned genome satisfies . For the cost, the squared distances are , with . This requires the products and (), the low-rank term (), the gating products () and row-wise reductions ().
Hyper-parameters
| Setting | Value | Setting | Value |
| anchors , rank | , | population, generations | , (patience ) |
| bounds , | , | tournament size | |
| SBX probability, index | , | ||
| , , | mutation probability per gene | ||
| margin target | mutation step | ||
| query rows | elites | ||
| search range | smoothness graph | Euclidean 5-NN |
Table 8. Default settings of EAML (identical for all datasets).
References
- [1]Aurélien Bellet and Amaury Habrard. Robustness and generalization for metric learning. Neurocomputing, 151(1):259–267, 2015. doi: 10.1016/j.neucom.2014.09.044.DOI
- [2]Aurélien Bellet, Amaury Habrard, and Marc Sebban. A survey on metric learning for feature vectors and structured data, 2013. arXiv:1306.6709.arxiv.org/abs/1306.6709
- [3]Thomas M. Cover and Peter E. Hart. Nearest neighbor pattern classification. IEEE Transactions on Information Theory, 13(1):21–27, 1967. doi: 10.1109/TIT.1967.1053964.DOI
- [4]Jason V. Davis, Brian Kulis, Prateek Jain, Suvrit Sra, and Inderjit S. Dhillon. Information-theoretic metric learning. In Proceedings of the 24th International Conference on Machine Learning (ICML), pages 209–216, 2007. doi: 10.1145/1273496.1273523.DOI
- [6]Kalyanmoy Deb and Ram Bhushan Agrawal. Simulated binary crossover for continuous search space. Complex Systems, 9(2):115–148, 1995. URL https://wpmedia.wolfram.com/uploads/sites/13/2018/02/09-2-2.pdf.
- [7]Kalyanmoy Deb and Hans-Georg Beyer. Self-adaptive genetic algorithms with simulated binary crossover. Evolutionary Computation, 9(2):197–221, 2001. doi: 10.1162/106365601750190406.DOI
- [8]Kalyanmoy Deb, Amrit Pratap, Sameer Agarwal, and T. Meyarivan. A fast and elitist multiobjective genetic algorithm: NSGA-II. IEEE Transactions on Evolutionary Computation, 6(2):182–197, 2002. doi: 10.1109/4235.996017.DOI
- [9]Janez Demšar. Statistical comparisons of classifiers over multiple data sets. Journal of Machine Learning Research, 7:1–30, 2006. URL https://www.jmlr.org/papers/v7/demsar06a.html.
- [10]Joaquín Derrac, Salvador García, Daniel Molina, and Francisco Herrera. A practical tutorial on the use of nonparametric statistical tests as a methodology for comparing evolutionary and swarm intelligence algorithms. Swarm and Evolutionary Computation, 1(1):3–18, 2011. doi: 10.1016/j.swevo.2011.02.002.DOI
- [11]Carlotta Domeniconi, Jing Peng, and Dimitrios Gunopulos. Locally adaptive metric nearest-neighbor classification. IEEE Transactions on Pattern Analysis and Machine Intelligence, 24(9):1281–1285, 2002. doi: 10.1109/TPAMI.2002.1033219.DOI
- [12]Jacob Goldberger, Sam T. Roweis, Geoffrey E. Hinton, and Ruslan Salakhutdinov. Neighbourhood components analysis. In Advances in Neural Information Processing Systems 17, pages 513–520, 2004. URL https://proceedings.neurips.cc/paper/2004/hash/42fe880812925e520249e808937738d2-Abstract.html.
- [13]Trevor Hastie and Robert Tibshirani. Discriminant adaptive nearest neighbor classification. IEEE Transactions on Pattern Analysis and Machine Intelligence, 18(6):607–616, 1996. doi: 10.1109/34.506411.DOI
- [14]Wassily Hoeffding. Probability inequalities for sums of bounded random variables. Journal of the American Statistical Association, 58(301):13–30, 1963. doi: 10.1080/01621459.1963.10500830.DOI
- [15]James D. Kelly, Jr. and Lawrence Davis. A hybrid genetic algorithm for classification. In Proceedings of the 12th International Joint Conference on Artificial Intelligence (IJCAI), pages 645–649, 1991. URL https://ijcai.org/proceedings/1991/94.
- [16]Markelle Kelly, Rachel Longjohn, and Kolby Nottingham. The UCI machine learning repository, 2023. URL https://archive.ics.uci.edu.
- [17]Brian Kulis. Metric learning: A survey. Foundations and Trends in Machine Learning, 5(4):287–364, 2013. doi: 10.1561/2200000019.DOI
- [18]Alexandre L. M. Levada, Frank Nielsen, and Michel F. C. Haddad. Adaptive k-nearest neighbor classifier based on the local estimation of the shape operator, 2024. arXiv:2409.05084.arxiv.org/abs/2409.05084
- [19]Prasanta Chandra Mahalanobis. On the generalised distance in statistics. Saṅkhyā A, 80 (Suppl. 1):1–7, 2018. doi: 10.1007/s13171-019-00164-5. Reprint of Proc. National Institute of Sciences of India 2:49–55 (1936).
- [20]Sankha Subhra Mullick, Shounak Datta, and Swagataм Das. Adaptive learning-based k-nearest neighbor classifiers with resilience to class imbalance. IEEE Transactions on Neural Networks and Learning Systems, 29(11):5713–5725, 2018. doi: 10.1109/TNNLS.2018.2812279.DOI
- [21]Claude Nadeau and Yoshua Bengio. Inference for the generalization error. Machine Learning, 52(3):239–281, 2003. doi: 10.1023/A:1024068626366.DOI
- [22]Fabian Pedregosa, Gaël Varoquaux, Alexandre Gramfort, Vincent Michel, Bertrand Thirion, Olivier Grisel, Mathieu Blondel, Peter Prettenhofer, Ron Weiss, Vincent Dubourg, Jake Vanderplas, Alexandre Passos, David Cournapeau, Matthieu Brucher, Matthieu Perrot, and Édouard Duchesnay. Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12:2825–2830, 2011. doi: 10.48550/arXiv.1201.0490. URL https://www.jmlr.org/papers/v12/pedregosa11a.html.DOI
- [23]Michael L. Raymer, William F. Punch, Erik D. Goodman, Leslie A. Kuhn, and Anil K. Jain. Dimensionality reduction using genetic algorithms. IEEE Transactions on Evolutionary Computation, 4(2):164–171, 2000. doi: 10.1109/4235.850566.DOI
- [24]Günter Rudolph. Convergence analysis of canonical genetic algorithms. IEEE Transactions on Neural Networks, 5(1):96–101, 1994. doi: 10.1109/72.265964.DOI
- [25]Sudhir Varma and Richard Simon. Bias in error estimation when using cross-validation for model selection. BMC Bioinformatics, 7:91, 2006. doi: 10.1186/1471-2105-7-91.DOI
- [26]Jun Wang, Alexandros Kalousis, and Adam Woznica. Parametric local metric learning for nearest neighbor classification. In Advances in Neural Information Processing Systems 25, pages 1601–1609, 2012. doi: 10.48550/arXiv.1209.3056.
- [27]Kilian Q. Weinberger and Lawrence K. Saul. Distance metric learning for large margin nearest neighbor classification. Journal of Machine Learning Research, 10:207–244, 2009. URL https://jmlr.org/papers/v10/weinberger09a.html.
- [28]Han Xiao, Kashif Rasul, and Roland Vollgraf. Fashion-MNIST: A novel image dataset for benchmarking machine learning algorithms, 2017. arXiv:1708.07747.arxiv.org/abs/1708.07747
- [29]Eric P. Xing, Andrew Y. Ng, Michael I. Jordan, and Stuart Russell. Distance metric learning with application to clustering with side-information. In Advances in Neural Information Processing Systems 15, 2002. URL https://proceedings.neurips.cc/paper/2002/hash/c3e4035af2a1cde9f21e1ae1951ac80b-Abstract.html.



