Analyzing the robustness of nearest-neighbor classifiers to adversarial examplesAnalyzing the Robustness of Nearest Neighbors to Adversarial Examples
The authors propose a robustness theoretical framework analogous to bias-variance, analyze k-NN and give RobustNN; the authors state that for constant k the robustness of k-NN is 0, and when k is sufficiently large it approaches Bayes Optimal.
test-time adversarial example attack: in the white-box setting the attacker fully knows the classifier type, training data, and parameters, but cannot modify the training process; the goal is to perturb the test input within radius r so that the classifier outputs a different label. In the black-box setting the attacker does not know the details of the target classifier, and trains a substitute classifier on seed data from the same distribution and transfers the attack.
- Why adversarial examples arise, and whether they stem from the data itself or from insufficient samples, according to the authors still lacks understanding. The paper aims to distinguish the effects of distribution, finite samples, and algorithm on robustness, and analyzes the nonparametric classifier k-NN.
- The authors propose a robustness framework analogous to bias-variance, define robust radius and astuteness, theoretically analyze k-NN in two regimes, constant k and k=Ω(√(dn log n)), and propose RobustNN (Algorithm 1), which runs on a pruned training set.
- Theoretically, the authors state that with constant k, k-NN has robustness 0 in the region where η(x)∈(0,1), and as k becomes sufficiently large it approaches Bayes Optimal. Experiments compare white-box and black-box attacks on Halfmoon, MNIST 1v7, and Abalone; the authors state that RobustNN outperforms the baselines on Halfmoon and Abalone, and is slightly lower on MNIST at small radii.
- The authors point out: the analytical gap between the two k regimes is not closed; whether a high k growth rate is necessary is an open problem; only binary classification is analyzed, and multiclass is left for future work; the theoretical guarantee holds in the large-sample limit. The experiments cover only three datasets, two types of white-box attacks, and two types of black-box substitute models, and the paper does not report the number of repetitions.
- Evaluated models
- RobustNN
- Benchmarks
- HalfmoonMNIST 1v7Abalone
- Metrics
- classification accuracy on adversarial examplesrobustness radiusastuteness
Yizhen Wang et al. propose a theoretical framework analogous to bias-variance theory for analyzing the robustness of k-nearest-neighbor classifiers to adversarial examples. The analysis shows that their robustness depends critically on the value of k: when k is small, the classifier may be inherently non-robust, whereas when k grows rapidly, robustness approaches that of the Bayes Optimal classifier. The authors propose an improved 1-nearest-neighbor classifier and guarantee its robustness in the large-sample limit; experiments show that at reasonable dataset sizes this classifier may also have good robustness.
Paper analysis
What problem does this paper attempt to solve?
The authors aim to answer why adversarial examples arise, and use a theoretical framework to analyze the robustness of k-NN and give a more robust variant of 1-NN.
Core question: whether adversarial examples stem from inherent properties of the data distribution or from insufficient training samples; according to the authors, understanding is still lacking, and the paper aims to build a theoretical framework to distinguish these two types of factors.
- Setting and motivation: Machine learning is used in safety-critical domains such as automobiles, healthcare, finance, and robotics, and the authors argue that algorithms resistant to adversarial attacks are needed. In test-time adversarial example attacks, the attacker perturbs a legitimate test input by a small distance to make the classifier err, and small perturbations are hard for humans to perceive.
- Shortcomings of existing work: The authors state that prior work is mostly empirical, or focuses on theory-inspired attacks and defenses, and lacks understanding of why adversarial examples arise.
- Core hypothesis: Analogous to bias-variance theory, the authors divide sources of robustness into three categories—distributional robustness (whether the output classifier is robust as samples tend to infinity), finite-sample robustness (fragility caused by insufficient samples), and algorithmic robustness (robustness differences caused by different training algorithms).
- Paper contributions: Under this framework, analyze k-NN, give RobustNN (a modified 1-NN) and provide robustness guarantees in the large-sample limit, then conduct empirical validation on three datasets.
- Threat model:
- Goal: Perturb the test input x within radius r so that the trained classifier f outputs a label different from f(x).
- Knowledge: White-box setting—the attacker fully knows the classifier type, training data, and parameters; black-box setting—the attacker does not know the nature, parameters, or training data of the target classifier, but has a seed dataset from the same distribution.
- Capability: Can only modify the test input, and cannot modify the training process in any way.
- Victim system: The trained classifier; the paper focuses on k-NN and its variants; the perturbation metric is assumed to be Euclidean distance, and the focus is binary classification.
What related research exists?
Related work falls into three groups: theoretical analysis and defenses of adversarial examples, convergence studies of nearest neighbors, and attacks against nearest neighbors and black-box attacks.
Theoretical work on adversarial examples
- Analysis type: Fawzi et al. [9] analyze the robustness of linear and quadratic classifiers under random and semi-random perturbations; Hein and Andriushchenko [13] give robustness guarantees for linear and kernel classifiers trained on a given dataset; Gilmer et al. [11] state that linear classifiers on high-dimensional data may have an inherent robustness-accuracy tradeoff.
- Theory-inspired defense type: Sinha et al. [1], Kolter and Wong [15], and Madry et al. [20] give defenses for neural networks based on relaxed optimization objectives; Katz et al. [14] use program verification to certify the robustness of small neural networks near given inputs.
- Difference from this paper: The authors point out two things—prior work mostly targets a given training set, whereas this paper considers the influence of the data distribution and sample size and analyzes the large-sample limit; prior work mostly focuses on parametric methods such as neural networks, whereas this paper focuses on the nonparametric nearest-neighbor classifier.
Convergence studies of nearest neighbors
- Asymptotic accuracy: Cover and Hart [6] prove that 1-NN accuracy converges in the large-sample limit to 1 − 2R*(1 − R*) (R* is the Bayes Optimal error rate); k-NN accuracy converges to Bayes Optimal when kn→∞ and kn/n→0. These works consider only accuracy, not robustness.
- Finite-sample rates: Chaudhuri and Dasgupta [5] use a natural class-based interior to characterize finite-sample rates of nearest neighbors; this paper builds on their results to define a stricter r-robust (p, ∆)-strict interior and give robustness bounds.
Attacks against nearest neighbors and black-box attacks
- Amsaleg et al. [2]: Propose an adversarial example generation method against nearest neighbors and state that attack effectiveness grows with intrinsic dimension; the Direct Attack in this paper is taken from that work.
- Papernot et al. [24, 25]: Propose black-box attacks based on substitute classifiers, and their experiments show that attacks from substitute classifiers of other types are unsuccessful against nearest neighbors; the authors state that the experiments in this paper corroborate these results.
Baselines and benchmarks: The experimental baselines are StandardNN (standard 1-NN), ATNN, and ATNN-all (two adversarially trained nearest neighbors), and the datasets are Halfmoon, MNIST 1v7, and Abalone (Section 5.1).
The authors position this paper as: the first large-sample analysis that distinguishes three sources of robustness—distributional, finite-sample, and algorithmic—within a unified framework and targets a nonparametric method (according to the paper's wording, this paper is "a first step toward a comprehensive analysis of how training data size affects robustness").
How does the paper address this problem?
Defines robustness using a bias-variance analogy framework, analyzes k-NN in two k intervals, then proposes RobustNN, which prunes the training set, and gives a large-sample guarantee.
Overall approach: first give a formal definition of robustness and three sources, then theoretically analyze k-NN in two regimes, constant k and rapidly growing k, and finally propose RobustNN (Algorithm 1), which runs on a pruned training set, and prove its robustness in the large-sample limit.
Problem setup and core definitions
- Setup: Binary classification, distribution D over instance space X, marginal µ, conditional distribution η(x)=Pr(y=1|x); the perturbation metric is Euclidean distance, and multiclass is left for future work.
- Robust radius: ρ(f, x) = infr {∃ x′ ∈ X ∩ B(x, r) s.t. f(x) ≠ f(x′)}, i.e., the shortest distance from x to the first input to which f assigns a different label.
- Distributional robustness and astuteness: R(f, r, µ) is the proportion of samples under µ with robust radius ≥ r; astuteness AstD(f, r) = Pr(x,y)∼ D(ρ(f, x) ≥ r, f(x) = y), i.e., the proportion of samples that are both accurate and robust. The authors consider astuteness a more appropriate metric when both accuracy and robustness matter, but it cannot be measured directly empirically, and the experiments approximate it with resistance to standard attacks.
The two regimes of k-NN
- Constant k (low-k regime): Theorem 3.1 states that, under the conditions that µ is absolutely continuous with respect to the Lebesgue measure, η(x)∈(0,1), and η is continuous in a neighborhood of x, for fixed k, ρ(Ak(Sn,·), x) converges in probability to 0, i.e., the distributional robustness (and astuteness) in that region is 0; the authors point out that this contrasts with accuracy—1-NN accuracy converges to 1 − 2R*(1 − R*), which may be quite high. Appendix Theorem A.2 gives finite-sample robustness rates for the interior region where η∈{0,1}.
- High-k regime: Theorem 3.3 states that when kn ≥ C1·√((dn log n + n log(1/δn))/∆n) and pn takes the corresponding value, with probability ≥ 1 − 3δ, kn-NN has robust radius r on the r-robust (pn, ∆n)-strict interior; as n→∞ this region approaches the robust region of Bayes Optimal (Theorem 3.2 gives that Bayes Optimal has robust radius r on X⁺_{r,0,0}∪X⁻_{r,0,0}). The authors explain the intuition: k is large enough to guarantee uniform convergence, the empirical mean label of all balls containing k samples is close to the expectation, and therefore k-NN near x outputs the same as Bayes Optimal.
RobustNN algorithm (Algorithm 1 and 2)
- Motivation: The authors observe that 1-NN is robust when points of different classes are far apart and the test point is close to the training data; real training sets often contain nearby points of different classes, so a portion of the training points is removed to enforce this property.
- Confident-Label (Algorithm 2): Take kn = 3 log(2n/δ)/∆², average the labels of the kn nearest neighbors of x to get ȳ; if ȳ falls in [1/2−∆, 1/2+∆], return ⊥, otherwise return the majority label. The choice of kn makes the probability that the empirical majority agrees with the expected majority ≥ 1−δ (when the expected majority is at least ∆ away from 1/2).
- Training set pruning (Algorithm 1): If f(xi)=yi and all xj in B(xi, r) have f(xj)=f(xi)=yi, mark xi as red; then find the largest 2r-separated subset containing all red points (reduced to the constrained matching problem of [16]), use it as the new training set, and still run 1-NN in the end.
- Guarantee (Theorem 4.2): Take kn = 3 log(2n/δ)/∆n² and marginal parameter τ; there exist constants C, C′ such that on the set XR (the intersection of the r+τ-robust strict interior and the density condition µ(B(x,τ)) ≥ (2C′/n)(d log n + log(1/δ))), with probability ≥ 1−2δ, the robust radius of Algorithm 1 is at least r − 2τ. The authors state that when the data distribution has a large high-density region intersecting the interior, this is an improvement over standard nearest neighbors; τ can be taken very small, so that in the large-sample limit r − 2τ approaches r.
Evaluation method
- Approach: Since the paper states that there is no general robustness certification method, the experiments approximate astuteness with resistance to standard attacks.
- Attacks: White-box uses Direct Attack [2] and Kernel Substitute Attack [24] (FGSM against the kernel substitute classifier, with parameter c of 0.1 on Halfmoon and MNIST and 0.01 on Abalone); black-box uses two types of substitute classifiers, kernel and neural network, augmenting seed data for two rounds following the method of [24], with labels from querying the target classifier, and attacks using FGSM.
- Parameter settings: RobustNN fixes ∆=0.45 and δ=0.1, and the defense radius r is tuned on a validation set of the same size as the test set; the defense radii of ATNN and ATNN-all are likewise tuned by validation accuracy against the strongest attacker.
What experiments did the paper conduct?
On three datasets, RobustNN is compared with three baselines using two types of white-box and two types of black-box attacks, and the authors state that RobustNN is no worse than the baselines in most settings.
Experimental Setup
- Algorithms under test: RobustNN (Algorithm 1), StandardNN (standard 1-NN), ATNN (1-NN trained on a training set augmented with adversarial examples generated by that attack method in the experiment), ATNN-all (1-NN augmented with adversarial examples generated by all attack methods in the experiment).
- Datasets: Halfmoon (2-dimensional synthetic data, 2000 training, 1000 test, σ=0.2); MNIST 1v7 (784-dimensional, 1000 training images each of digits 1 and 7, 500 test images each); Abalone (7-dimensional, determining whether age exceeds 12.5 years, 500 training, 100 test). Each experiment additionally generates a validation set of the same size as the test set for hyperparameter tuning.
- Attacks: White-box are Direct Attack and Kernel Substitute Attack; black-box are kernel substitute and neural net substitute (ConvNet from the [23] tutorial for MNIST, 2-hidden-layer MLP for Halfmoon and Abalone), with substitute models trained for two rounds following the [24] method.
- Metrics: Curves of classification accuracy on adversarial examples as a function of attack radius r (Figure 1, 2); astuteness cannot be measured directly and is approximated by resistance to attacks.
- Review method: No LLM or human review; results are classification accuracy; the paper does not report the number of repetitions.
Main Results
The main results are the accuracy–attack radius curves in Figure 1 (white-box) and Figure 2 (black-box); the converted text does not contain curve values, and the following is the paper body's description of the figures:
Attack type Dataset Authors' description of results (per Figure 1, 2) White-box Direct / Kernel Substitute Halfmoon, Abalone RobustNN outperforms all baselines at all attack radii White-box Direct / Kernel Substitute MNIST 1v7 At small radii RobustNN accuracy is slightly lower than other methods, at large radii it outperforms other methods Black-box kernel / neural net substitute Halfmoon, Abalone RobustNN outperforms baselines under both attacks Black-box neural net substitute MNIST 1v7 At small attack radii RobustNN performs worse than baselines - Authors' interpretation: The authors state the results are consistent with theoretical predictions—when training set size is large relative to dimensionality (Halfmoon, Abalone), RobustNN gains more; on sparse MNIST it is slightly worse at small radii and better at large radii.
- Attack strength comparison: The authors state Direct Attack causes a larger accuracy drop than Kernel Substitute Attack; black-box attacks are less effective against all algorithms than white-box, which the authors state corroborates the observation in [24] that black-box attacks are less successful against nearest neighbors.
- Substitute model differences: The authors state the kernel substitute attack is more effective than the neural net substitute, and consider this consistent with the structural similarity between kernel classifiers and nearest neighbors.
Validity Verification of Black-Box Substitute Models
- What was measured: Accuracy of the substitute classifier on its own training set, accuracy on the clean test set, and the proportion of predictions on the test set that agree with the target classifier (Table 1).
- Results: On Halfmoon, substitute models have test accuracy 90.5%–96.8% and agreement 94.1%–97.6%; on MNIST 1v7, test accuracy 94.8%–98.9% and agreement 97.6%–99.3%; on Abalone agreement is lower, e.g., the kernel substitute is 72.6% against StandardNN and 90.9% against RobustNN, and the neural net substitute is as low as 66.6% against ATNN-All (Table 1).
- Authors' interpretation: The authors state that on Halfmoon and MNIST the substitute models simulate the target classifier well; Abalone, due to its high noise level, is simulated less well than the other two datasets, but substitute model test accuracy remains comparable to the target classifier.
Visualization Analysis
- Figure 4 (MNIST attack samples, r=3): The authors state that perturbations from direct attack, white-box and black-box kernel attacks concentrate on key pixels distinguishing digits 1 and 7 (e.g., the horizontal stroke or the shading of digit 7), whereas the neural net substitute attack spreads perturbations across many pixels and is not effective against nearest neighbors; the authors also state that at r=3 the samples generated by effective attacks are already ambiguous in class to humans, and RobustNN still has non-trivial accuracy at that radius.
- Figure 3 (Halfmoon training subset): In the original training set, a noisy region with mixed red and blue points exists between the two moons; RobustNN cleans this region so that a gap appears between the two classes, and the gap width increases with the defense radius r (r=0.1 and r=0.2 in the figure).
Other Ablations and Analyses
- Training set size relative to dimensionality: The authors state that gains on Halfmoon (2000 samples/2 dimensions) and Abalone (500 samples/7 dimensions) are higher than on MNIST (2000 samples/784 dimensions), consistent with the theoretical prediction that nearest neighbors perform well when samples are sufficient relative to dimensionality (Section 5.2.2, 5.3.2).
- Defense radius tuning: The defense radius of all tunable methods is selected on the validation set by accuracy against the strongest attacker (Section 5.1.2); the paper does not report the final selected r value for each method.
- Negative results: On MNIST at small attack radii, RobustNN accuracy is slightly lower than baselines (in both the white-box and black-box neural net substitute settings); the authors' explanation is that on sparse data the training set size is insufficient relative to dimensionality.
What are some points that can be further explored?
The authors list open problems such as the intermediate range of k, whether a higher growth rate is necessary, and extension to multiclass; the experiments cover three datasets and four types of attacks.
Limitations and future directions noted by the authors
- The intermediate range of k is not analyzed (Section 6): The authors state that the first open problem is closing the analytical gap between the two k ranges (constant k and k=Ω(√(dn log n))).
- Whether a high growth rate is necessary is unknown (Section 1.1.2, 3.2.2): The authors state that the k growth rate required for robustness convergence is much higher than that required for accuracy convergence, and whether this high rate is necessary is an open problem.
- Binary classification only (Section 2.1): The paper focuses on binary classification, and the authors state that extension to multiclass is left for future work.
- Large-sample guarantee (Section 4, 5): The guarantee for RobustNN holds in the large-sample limit; the experiments only indicate that it may still have good robustness properties at reasonable data scales.
- Better nearest-neighbor algorithms (Section 6): The authors state that the second direction is developing nearest-neighbor algorithms with better robustness guarantees.
- Extension to other methods (Section 6): The authors consider it important future work to perform similar analysis for other supervised learning methods.
Experimental coverage
- Datasets: The experiments cover three datasets, Halfmoon, MNIST 1v7, and Abalone, with training sizes of 2000, 2000 (1000 per class), and 500, respectively (Section 5.1.1).
- Attacks: White-box evaluation includes two types, Direct Attack and Kernel Substitute Attack; black-box evaluation includes two types of substitute classifiers, kernel and neural network, both using FGSM to generate adversarial examples (Section 5.2.1, 5.3.1).
- Baselines: Compared against three, StandardNN, ATNN, and ATNN-all (Section 5.1.2).
- Metrics and measurement: The paper states that astuteness cannot be measured directly empirically, and the experiments approximate it with classification accuracy under adversarial attack (Section 2.2, 5); the paper does not report the number of repetitions or variance.
- Theoretical conditions: Theorem 3.1 requires µ to be absolutely continuous with respect to the Lebesgue measure and η to be continuous; the authors note that absolute continuity can be relaxed to an embedded manifold but the proof is more complicated (Section 3.1 Remarks).
Summarize the main content of the paper
The theoretical framework distinguishes three sources of robustness, analyzes two k regimes of k-NN, proposes RobustNN, and validates it on three datasets.
A theoretical analysis paper on the robustness of adversarial examples, whose object is the nonparametric k-nearest-neighbor classifier, and which gives a modified 1-NN with a large-sample robustness guarantee.
- Problem: The authors state that why adversarial examples appear, and whether they stem from intrinsic properties of the data or from insufficient samples, remains poorly understood, and that prior work is mostly empirical or targets parametric models.
- Framework: Analogous to bias-variance theory, robustness is divided into distributional robustness, finite-sample robustness, and algorithmic robustness; robust radius ρ(f,x) and astuteness (the proportion of samples that are both accurate and robust) are defined as metrics.
- Theoretical results: The authors state that for constant k, the distributional robustness of k-NN in the region η(x)∈(0,1) is 0 in the large-sample limit (Theorem 3.1), in contrast with the possibly quite high accuracy; when k=Ω(√(dn log n)), the robust region of k-NN approaches the Bayes Optimal classifier (Theorem 3.3), and the required growth rate is much higher than that required for accuracy convergence.
- Method: RobustNN first uses the majority label of the kn nearest neighbors for a confidence judgment, keeps points whose label is confident and whose neighborhood has the same label (red), then finds the largest 2r-separated training subset containing all red points and runs 1-NN; Theorem 4.2 guarantees that on the set XR the robust radius is at least r − 2τ (with probability ≥ 1−2δ).
- Experiments: On Halfmoon, MNIST 1v7, and Abalone, evaluated with two white-box attacks, Direct and Kernel Substitute, and two black-box substitute attacks, kernel and neural net. The authors state that RobustNN outperforms StandardNN, ATNN, and ATNN-all at all attack radii on Halfmoon and Abalone; on MNIST it is slightly lower at small radii and higher at large radii, consistent with the theoretical prediction that "the benefit is greater when samples are relatively sufficient for the dimension."
- Authors' conclusion: The authors state that RobustNN may preserve the robustness properties of the large-sample limit at reasonable data scales, and that this paper is a first step toward analyzing how training data size affects robustness; the intermediate range of k, the necessity of the high rate, and extension to other methods are open problems.