Robust Mahalanobis Metric Learning via Geometric Approximation Algorithms
Diego Ihara, Neshat Mohammadi, Francesco Sgherzi, Anastasios, Sidiropoulos

TL;DR
This paper introduces a fast, parallelizable algorithm for robust Mahalanobis metric learning that effectively handles adversarial label noise, with theoretical guarantees and practical improvements demonstrated on various datasets.
Contribution
It presents a fully polynomial-time approximation scheme for robust Mahalanobis metric learning, leveraging linear programming tools and ensuring near-optimal performance despite adversarial label corruption.
Findings
Algorithm is nearly-linear time and fully parallelizable.
Effective in recovering metrics with adversarial label noise.
Experimental results show robustness on real, synthetic, and poisoned data.
Abstract
Learning Mahalanobis metric spaces is an important problem that has found numerous applications. Several algorithms have been designed for this problem, including Information Theoretic Metric Learning (ITML) [Davis et al. 2007] and Large Margin Nearest Neighbor (LMNN) classification [Weinberger and Saul 2009]. We study the problem of learning a Mahalanobis metric space in the presence of adversarial label noise. To that end, we consider a formulation of Mahalanobis metric learning as an optimization problem, where the objective is to minimize the number of violated similarity/dissimilarity constraints. We show that for any fixed ambient dimension, there exists a fully polynomial-time approximation scheme (FPTAS) with nearly-linear running time. This result is obtained using tools from the theory of linear programming in low dimensions. As a consequence, we obtain a fully-parallelizableā¦
| Data set | ITML | LMNN | LPTMLt=2000 |
|---|---|---|---|
| Iris | |||
| Soybean | |||
| Synthetic |
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsFace and Expression Recognition Ā· Machine Learning and Algorithms Ā· Advanced Image and Video Retrieval Techniques
Robust Mahalanobis Metric Learning via Geometric Approximation Algorithms
Diego Ihara Centurion
Department of Computer Science
University of Illinois at Chicago
Chicago, IL 60607
&Neshat Mohammadi 11footnotemark: 1
Department of Computer Science
University of Illinois at Chicago
Chicago, IL 60607
&Francesco Sgherzi 11footnotemark: 1
Department of Computer Science
University of Illinois at Chicago
Chicago, IL 60607
&Anastasios Sidiropoulos 11footnotemark: 1
Department of Computer Science
University of Illinois at Chicago
Chicago, IL 60607
[email protected] Authors sorted in alphabetical order.
Abstract
Learning Mahalanobis metric spaces is an important problem that has found numerous applications. Several algorithms have been designed for this problem, including Information Theoretic Metric Learning () [Davis et al.Ā 2007] and Large Margin Nearest Neighbor () classification [Weinberger and SaulĀ 2009]. We study the problem of learning a Mahalanobis metric space in the presence of adversarial label noise. To that end, we consider a formulation of Mahalanobis metric learning as an optimization problem, where the objective is to minimize the number of violated similarity/dissimilarity constraints. We show that for any fixed ambient dimension, there exists a fully polynomial-time approximation scheme (FPTAS) with nearly-linear running time. This result is obtained using tools from the theory of linear programming in low dimensions. As a consequence, we obtain a fully-parallelizable algorithm that recovers a nearly-optimal metric space, even when a small fraction of the labels is corrupted adversarially. We also discuss improvements of the algorithm in practice, and present experimental results on real-world, synthetic, and poisoned data sets.
1 Introduction
Learning metric spaces is a fundamental computational primitive that has found numerous applications and has received significant attention in the literature. We refer the reader to [Kulis etĀ al.(2013), Li and Tian(2018)] for detailed exposition and discussion of previous work. At the high level, the input to a metric learning problem consists of some universe of objects , together with some similarity information on subsets of these objects. Here, we focus on pairwise similarity and dissimilarity constraints. Specifically, we are given , which are sets of pairs of objects that are labeled as similar and dissimilar respectively. We are also given some , and we seek to find a mapping , into some target metric space , such that for all ,
[TABLE]
and for all ,
[TABLE]
In the case of Mahalanobis metric learning, we have , with , for some , and the mapping is linear. Specifically, we seek to find a matrix , such that for all , we have
[TABLE]
and for all , we have
[TABLE]
1.1 Our Contribution
In general, there might not exist any that satisfies all constraints of type 1 and 2. We are thus interested in finding a solution that minimizes the fraction of violated constraints, which corresponds to maximizing the accuracy of the mapping. We develop a -approximation algorithm for optimization problem of computing a Mahalanobis metric space of maximum accuracy, that runs in near-linear time for any fixed ambient dimension . This algorithm is obtained using tools from geometric approximation algorithms and the theory of linear programming in small dimension. The following summarizes our result.
Theorem 1.1**.**
For any , , there exists a randomized algorithm for learning -dimensional Mahalanobis metric spaces, which given an instance that admits a mapping with accuracy , computes a mapping with accuracy at least , in time , with high probability.
The above algorithm can be extended to handle various forms of regularization. We also propose several modifications of our algorithm that lead to significant performance improvements in practice. The final algorithm is evaluated experimentally on both synthetic and real-world data sets, and in a data poisoning scenario, and is compared against the currently best-known algorithms for the problem.
1.2 Related Work
Several algorithms for learning Mahalanobis metric spaces have been proposed. Notable examples include the SDP based algorithm of Xing et al.Ā [Xing etĀ al.(2003)Xing, Jordan, Russell, and Ng], the algorithm of Globerson and Roweis for the fully supervised setting [Globerson and Roweis(2006)], Information Theoretic Metric Learning () by Davis et al.Ā [Davis etĀ al.(2007)Davis, Kulis, Jain, Sra, and Dhillon], which casts the problem as a particular optimization minimizing LogDet divergence, as well as Large Margin Nearest Neighbor () by Weinberger et al.Ā [Weinberger etĀ al.(2006)Weinberger, Blitzer, and Saul], which attempts to learn a metric geared towards optimizing -NN classification. We refer the reader to the surveys [Kulis etĀ al.(2013), Li and Tian(2018)] for a detailed discussion of previous work. Our algorithm differs from previous approaches in that it seeks to directly minimize the number of violated pairwise distance constraints, which is a highly non-convex objective, without resorting to a convex relaxation of the corresponding optimization problem.
1.3 Organization
The rest of the paper is organized as follows. Section 2 describes the main algorithm and the proof of Theorem 1.1. Section 3 discusses practical improvements used in the implementation of the algorithm. Section 4 presents the experimental evaluation.
2 Mahalanobis Metric Learning as an LP-Type Problem
In this Section we present an approximation scheme for Mahalanobis metric learning in -dimensional Euclidean space, with nearly-linear running time. We begin by recalling some prior results on the class of LP-type problems, which generalizes linear programming. We then show that linear metric learning can be cast as an LP-type problem.
2.1 LP-type Problems
Let us recall the definition of an LP-type problem. Let be a set of constraints, and let , such that for any , is the value of the optimal solution of the instance defined by . We say that defines an LP-type problem if the following axioms hold:
(A1) Monotonicity. For any , we have .
(A2) Locality. For any , with , and any , if , then .
More generally, we say that defines an LP-type problem on some , when conditions (A1) and (A2) hold for all .
A subset is called a basis if and for any proper subset . A basic operation is defined to be one of the following:
(B0) Initial basis computation. Given some , compute any basis for .
(B1) Violation test. For some and some basis , test whether (in other words, whether violates ).
(B2) Basis computation. For some and some basis , compute a basis of .
2.2 An LP-type Formulation
We now show that learning Mahalanobis metric spaces can be expressed as an LP-type problem. We first note that we can rewrite (1) and (2) as
[TABLE]
and
[TABLE]
where is positive semidefinite.
We define , where for each , we have a constraint of type (3), and for every , we have a constraint of type (4). Therefore, for any set of constraints , we may associate the set of feasible solutions for with the set of all positive semidefinite matrices , satisfying (3) and (4) for all constraints in .
Let , such that for all , we have
[TABLE]
where is a vector chosen uniformly at random from the unit sphere from some rotationally-invariant probability measure. Such a vector can be chosen, for example, by first choosing some , where each coordinate is sampled from the normal distribution , and setting .
Lemma 2.1**.**
*When is chosen as above, the pair defines an LP-type problem of combinatorial dimension , with probability 1. Moreover, for any , if each is chosen using bits of precision, then for each , with , the assertion holds with high probability. *
Proof.
Since adding constraints to a feasible instance can only make it infeasible, it follows that satisfies the monotonicity axiom (A1).
We next argue that the locality axion (A2) also holds, with high probability. Let , with , and let , with . Let and be some (not necessarily unique) infimizers of , when ranges in and respectively. The set , viewed as a convex subset of , is the intersection of the SDP cone with half-spaces, and thus has at most facets. There are at least two distinct infimizers for , when , only when the randomly chosen vector is orthogonal to a certain direction, which occurs with probability 0. When each entry of is chosen with bits of precision, the probability that is orthogonal to any single hyperplane is at most ; the assertion follows by a union bound over facets. This establishes that axiom (A2) holds with high probability.
It remains to bound the combinatorial dimension, . Let be a set of constraints. For each , define the ellipsoid
[TABLE]
For any , with , and , , we have that for all , . Therefore in order to specify a linear transformation , up to an isometry, it suffices to specify the ellipsoid .
Each corresponds to the constraint that the point must lie in . Similarly each corresponds to the constraint that the point must lie either on the boundary or the exterior of . Any ellipsoid in is uniquely determined by specifying at most distinct points on its boundary (see [Welzl(1991), Chazelle(2000)]). Therefore, each optimal solution can be uniquely specified as the intersection of at most constraints, and thus the combinatorial dimension is . ā
Lemma 2.2**.**
Any initial basis computation (B0), any violation test (B1), and any basis computation (B2) can be performed in time .
Proof.
The violation test (B1) can be performed by solving one SDP to compute , and another to compute . By Lemma 2.1 the combinatorial dimension is , thus each SDP has constraints, and be solved in time .
The basis computation step (B2) can be performed starting with the set of constraints , and iteratively remove every constraint whose removal does not decrease the optimum cost, until we arrive at a minimal set, which is a basis. In total, we need to solve at most SDPs, each of size , which can be done in total time .
Finally, by the choice of , any set containing a single constraint in is a valid initial basis. ā
2.3 Algorithmic implications
Using the above formulation of Mahalanobis metric learning as an LP-type problem, we can obtain our approximation scheme. Our algorithm uses as a subroutine an exact algorithm for the problem (that is, for the special case where we seek to find a mapping that satisfies all constraints). We first present the exact algorithm and then show how it can be used to derive the approximation scheme.
An exact algorithm.
[Welzl(1991)] obtained a simple randomized linear-time algorithm for the minimum enclosing ball and minimum enclosing ellipsoid problems. This algorithm naturally extends to general LP-type problems (we refer the reader to [Har-Peled(2011), Chazelle(2000)] for further details).
With the interpretation of Mahalanobis metric learning as an LP-type problem given above, we thus obtain a linear time algorithm for in , for any constant . The resulting algorithm on a set of constraints is implemented by the procedure , which is presented in Algorithm 1. The procedure takes as input sets of constraints . It outputs a solution to the problem induced by the set of constraints , such that all constraints in are tight (that is, they hold with equality); if no such solution solution exists, then it returns . The procedure computes . The analysis of [Welzl(1991)] implies that when is called, the cardinality of is at most the combinatorial dimension, which by Lemma 2.1 is . Thus the procedure Ā can be implemented using one initial basis computation (B0) and basis computations (B2), which by Lemma 2.2 takes total time .
An -approximation algorithm.
It is known that the above exact linear-time algorithm leads to an nearly-linear-time approximation scheme for LP-type problems. This is summarized in the following. We refer the reader to [Har-Peled(2011)] for a more detailed treatment.
Lemma 2.3** ([Har-Peled(2011)], Ch.Ā 15).**
Let be some LP-type problem of combinatorial dimension , defined by some pair , and let . There exists a randomized algorithm which given some instance , with , outputs some basis , that violates at most constraints in , such that , for any basis violating at most constraints in , in time , where is the time needed to compute an arbitrary initial basis of , and , , and are upper bounds on the time needed to perform the basic operations (B0), (B1) and (B2) respectively. The algorithm succeeds with high probability.
For the special case of Mahalanobis metric learning, the corresponding algorithm is given in Algorithm 2. The approximation guarantee for this algorithm is summarized in 1.1. We can now give the proof of our main result.
Proof of Theorem 1.1.
Follows immediately by Lemmas 2.2 and 2.3. ā
Regularization.
We now argue that the LP-type algorithm described above can be extended to handle certain types of regularization on the matrix . In methods based on convex optimization, introducing regularizers that are convex functions can often be done easily. In our case, we cannot directly introduce a regularizing term in the objective function that is implicit in Algorithm 2. More specifically, let denote the total number of constraints of type (3) and (4) that violates. Algorithm 2 approximately minimizes the objective function . A natural regularized version of Mahalanobis metric learning is to instead minimize the objective function , for some , and regularizer . One typical choice is , for some matrix ; the case corresponds to the trace norm (see [Kulis etĀ al.(2013)]). We can extend the Algorithm 2 to handle any regularizer that can be expressed as a linear function on the entries of , such as . The following summarizes the result.
Theorem 2.4**.**
Let be a linear function on the entries of , with polynomially bounded coefficients. For any , , there exists a randomized algorithm for learning -dimensional Mahalanobis metric spaces, which given an instance that admits a solution with , computes a solution with , in time , with high probability.
Proof.
If , for sufficiently large constant , since the coefficients in are polynomially bounded, it follows that the largest possible value of is , and can thus be omitted without affecting the result. Similarly, if , for sufficiently large constant , since there are at most constraints, it follows that the term can be omitted form the objective. Therefore, we may assume w.l.o.g.Ā that . We can guess some , such that . We modify the SDP used in the proof of Lemma 2.2 by introducing the constraint . Guessing the correct value of requires executions of Algorithm 2, which implies the running time bound. ā
3 Practical Improvements and Parallelization
We now discuss some modifications of the algorithm described in the previous section that significantly improve its performance in practical scenarios, and have been integrated in our implementation.
Move-to-front and pivoting heuristics.
We use heuristics that have been previously used in algorithms for linear programming [Seidel(1990), Clarkson(1995)], minimum enclosing ball in [Megiddo(1983)], minimum enclosing ball and ellipsoid is , for any fixed [Welzl(1991)], as well as in fast implementations of minimum enclosing ball algorithms [GƤrtner(1999)]. The move-to-front heuristic keeps an ordered list of constraints which gets reorganized as the algorithm runs; when the algorithm finds a violation, it moves the violating constraint to the beginning of the list of the current sub-problem. The pivoting heuristic further improves performance by choosing to add to the basis the constraint that is āviolated the mostā. For instance, for similarity constraints, we pick the one that is mapped to the largest distance greater than ; for dissimilarity constraints, we pick the one that is mapped to the smallest distance less than .
Approximate counting.
The main loop of Algorithm 2 involves counting the number of violated constraints in each iteration. In problems involving a large number of constraints, we use approximate counting by only counting the number of violations within a sample of constraints.
Early termination.
A bottleneck of Algorithm 2 stems from the fact that the inner loop needs to be executed for iterations. In practice, we have observed that a significantly smaller number of iterations is needed to achieve high accuracy. We denote by for the version of the algorithm that performs a total of iterations of the inner loop.
Parallelization.
Algorithm 2 consists of several executions of the algorithm Ā on independently sampled sub-problems. Therefore, Algorithm 2 can trivially be parallelized by distributing a different set of sub-problems to each machine, and returning the best solution found overall.
4 Experimental Evaluation
We have implemented Algorithm 2, incorporating the practical improvements described in Section 3, and performed experiments on synthetic and real-world data sets. Our implementation and documentation can be found in our repository. We now describe the experimental setting and discuss the main findings.
4.1 Experimental Setting
Classification task.
Each data set used in the experiments consists of a set of labeled points in . The label of each point indicates its class, and there is a constant number of classes. The set of similarity constraints (respt.Ā dissimilarity constraints ) is formed by uniformly sampling pairs of points in the same class (resp.Ā from different classes). We use various algorithms to learn a Mahalanobis metric for a labeled input point set in , given these constraints. The values and are chosen as the th and th percentiles of all pairwise distances. We used 2-fold cross-validation: At the training phase we learn a Mahalanobis metric, and in the testing phase we use -NN classification, with , to evaluate the performance.
Data sets.
We have tested our algorithm on the following synthetic and real-world data sets:
1. Real-world: We have tested the performance of our implementation on the Iris, Wine, Ionosphere and Soybean data sets from the UCI Machine Learning Repository111https://archive.ics.uci.edu/ml/datasets.php.
2. Synthetic: Next, we consider a synthetic data set that is constructed by first sampling a set of points from a mixture of two Gaussians in , with identity covariance matrices, and with means and respectively; we then apply a linear transformation that stretches the axis by a factor of . This linear transformation reduces the accuracy of -NN on the underlying Euclidean metric with from 1 to 0.68.
3. Data poisoning: We modify the above synthetic data set by introducing a small fraction of points in an adversarial manner, before applying the linear transformation. Figure 2(b) depicts the noise added as five points labeled as one of the classes, and sampled from a Gaussian with identity covariance matrix and mean (Figure 2(a)).
Algorithms.
We compare the performance of our algorithm against Ā and . We used the implementations provided by the authors of these works, with minor modifications.
4.2 Results
Accuracy.
Algorithm 2 minimizes the number of violated pairwise distance constraints. It is interesting to examine the effect of this objective function on the accuracy of -NN classification. Figure 1 depicts this relationship for the Wine data set. We observe that, in general, as the number of iterations of the main loop of Ā increases, the number of violated pairwise distance constraints decreases, and the accuracy of -NN increases. This phenomenon remains consistent when we first perform PCA to dimensions.
Comparison to Ā and .
We compared the accuracy obtained by , for iterations, against Ā and .
Table 1 summarizes the findings on the real-world and data sets and the synthetic data set without adversarial noise. We observe that Ā achieves accuracy that is comparable to Ā and .
We observe that Ā outperforms Ā and Ā on the poisoned data set. This is due to the fact that the introduction of adversarial noise causes the relaxations used in Ā and Ā to be biased towards contracting the -axis. In contrast, the noise does not āfoolā Ā because it only changes the optimal accuracy by a small amount. The results are summarized in Figure 3.
The effect of dimension.
The running time of Ā grows with the dimension . This is caused mostly by the fact that the combinatorial dimension of the underlying LP-type problem is , and thus performing each basic operation requires solving an SDP with constraints. Figure 4 depicts the effect of dimensionality in the running time, for iterations of the main loop. The data set used is Wine after performing PCA to dimensions, for .
Parallel implementation.
We implemented a massively parallel version of Ā in the MapReduce model. The program maps different sub-problems of the main loop of Ā to different machines. In the reduce step, we keep the result with the minimum number of constraint violations. The implementation uses the mrjob [Yelp and Contributors(2019)] package. For these experiments, we used Amazon cloud computing instances of type m4.xlarge, AMI 5.20.0 and configured with Hadoop. As expected, the training time decreases as the number of available processors increases (Figure 5). All technical details about this implementation can be found in the parallel section of the documentation of our code.
5 Conclusions
We have shown that the problem of learning a Mahalanobis metric space can be cast as an LP-type problem. This formulation allows us to obtain an efficient approximation scheme using tools from the theory of linear programming in low dimensions. Specifically, we present a near-linear time -approximation algorithm that minimizes the number of violated constraints. Experimental evaluation demonstrates that when compared to prior work, our method is significantly more robust against small adversarial modifications of the input labelling. Our approach also leads to a fully parallelizable algorithm.
It is an interesting research direction to extend our approximation algorithm to other classes of metric learning problems. One such case is when the input is specified as a set of ordered triples , and the goal is to find a mapping with , for some margin (see [weinberger2009distance]). Another important direction is to obtain geometric approximation algorithms for non-linear metric learning primitives, such as mappings computed by small depth neural networks.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[Chazelle(2000)] B. Chazelle. The discrepancy method: randomness and complexity . Cambridge University Press, 2000.
- 2[Clarkson(1995)] K. L. Clarkson. Las vegas algorithms for linear and integer programming when the dimension is small. Journal of the ACM (JACM) , 42(2):488ā499, 1995.
- 3[Davis et al.(2007)Davis, Kulis, Jain, Sra, and Dhillon] J. V. Davis, B. Kulis, P. Jain, S. Sra, and I. S. Dhillon. Information-theoretic metric learning. In Proceedings of the 24th international conference on Machine learning , pages 209ā216. ACM, 2007.
- 4[GƤrtner(1999)] B. GƤrtner. Fast and robust smallest enclosing balls. In European Symposium on Algorithms , pages 325ā338. Springer, 1999.
- 5[Globerson and Roweis(2006)] A. Globerson and S. T. Roweis. Metric learning by collapsing classes. In Advances in neural information processing systems , pages 451ā458, 2006.
- 6[Har-Peled(2011)] S. Har-Peled. Geometric approximation algorithms . Number 173. American Mathematical Soc., 2011.
- 7[Kulis et al.(2013)] B. Kulis et al. Metric learning: A survey. Foundations and TrendsĀ® in Machine Learning , 5(4):287ā364, 2013.
- 8[Li and Tian(2018)] D. Li and Y. Tian. Survey and experimental study on metric learning methods. Neural Networks , 105:447ā462, 2018.
