Efficient distance metric learning by adaptive sampling and mini-batch stochastic gradient descent (SGD)

Qi Qian, Rong Jin, Jinfeng Yi, Lijun Zhang, Shenghuo Zhu

Introduction

Distance Metric Learning (DML) aims to learn a distance measure that effectively captures the underlying structure of data, ensuring that "similar" points are close and "dissimilar" points are distant. This is a fundamental task for many machine learning applications, including $k$-nearest neighbor (k-NN) classification, clustering, and information retrieval. However, the computational cost of maintaining a valid metric—specifically the positive semi-definite (PSD) constraint—often limits the scalability of DML to large-scale datasets. This paper presents a novel framework that significantly reduces this overhead through mini-batch stochastic gradient descent (SGD) and adaptive sampling.

The Challenge of the PSD Constraint

The core of DML involves learning a Mahalanobis distance parameterized by a matrix $M$. To ensure $M$ defines a valid metric, it must be positive semi-definite. In standard online or stochastic learning settings, the matrix is updated based on individual constraints (e.g., triplets or pairs) and then projected back onto the PSD cone. This projection typically requires an eigen-decomposition of the matrix, an operation with $O(d^3)$ complexity, where $d$ is the number of features. For high-dimensional data or large numbers of iterations, these repeated projections become the primary computational bottleneck.

Proposed Methodology

The authors propose three strategies to minimize the frequency of these expensive projections without compromising the quality of the learned metric.

1. Mini-batch SGD with Smooth Loss

A straightforward way to reduce projections is to use mini-batches. Instead of projecting after every update, the algorithm aggregates gradients from $b$ constraints and performs a single projection. However, the authors identify that the standard non-smooth hinge loss used in DML (e.g., in the LMNN algorithm) performs poorly with mini-batching.

To address this, they introduce a smooth loss function based on a log-sum-exp approximation. This smoothness is critical; it allows the mini-batch to effectively reduce the variance of the stochastic gradients, leading to better convergence properties and higher classification accuracy compared to non-smooth alternatives.

2. Adaptive Sampling SGD (AS-SGD)

Not all data constraints are equally informative. Many "easy" triplets are already correctly classified with a sufficient margin and contribute little to the learning process. AS-SGD introduces a difficulty measure based on the derivative of the loss function. For each constraint, the algorithm calculates the probability of an update. If a triplet is "easy," the update (and the subsequent projection) is skipped. This adaptive mechanism focuses computational resources on "difficult" constraints that are more likely to improve the model.

3. Hybrid Approaches (HR-SGD and HA-SGD)

To further optimize performance, the authors combine mini-batching and adaptive sampling:

  • HR-SGD (Hybrid Random): Groups constraints into mini-batches and samples a single triplet from the batch to decide whether to update the entire batch.
  • HA-SGD (Hybrid Average): Uses the average gradient norm of the entire mini-batch as the criterion for deciding whether to perform an update and projection.

Experimental Evaluation

The proposed algorithms were tested on ten diverse datasets from the UCI and LIBSVM repositories, including semeion, dna, isolet, letter, protein, connect4, and sensit. Large-scale performance was evaluated using rcv20 (approx. 477,000 samples) and poker (1 million samples). Feature dimensions ranged from 10 to 617.

Performance and Efficiency

The results demonstrate a dramatic reduction in training time. For instance, on the isolet dataset, standard SGD required over 35,000 seconds, while the proposed methods reduced this to under 4,000 seconds—a nearly 10-fold speedup. Crucially, this efficiency did not come at the cost of accuracy. The classification error rates for Mini-SGD, AS-SGD, and the hybrid methods remained competitive with, and in some cases outperformed, state-of-the-art methods like OASIS and LMNN.

Conclusion

The research highlights that many projections in traditional DML are redundant. By utilizing smooth loss functions for effective mini-batching and adaptive sampling to skip non-informative updates, the proposed framework offers a highly efficient path for learning distance metrics on large-scale data. Future work will look toward scaling these techniques to even higher-dimensional spaces where the $O(d^3)$ projection cost becomes even more prohibitive.

Summary updated

BibTeX
@article{qian2015efficient,
  author = {Qi Qian and Rong Jin and Jinfeng Yi and Lijun Zhang and Shenghuo Zhu},
  title = {{Efficient distance metric learning by adaptive sampling and mini-batch stochastic gradient descent (SGD)}},
  journal = {Machine Learning},
  year = {2015},
  doi = {10.1007/s10994-014-5456-x},
}
Figure