At the heart of many machine learning tasks—such as clustering, image retrieval, and person re-identification—is the need to measure the distance between data points. Standard Euclidean distance treats all dimensions equally, which rarely aligns with semantic reality. To fix this, distance metric learning aims to find a transformation matrix $M$ that defines a Mahalanobis distance:
$$d_M(x, y) = \sqrt{(x-y)^T M (x-y)}$$
For $d_M$ to be a valid metric, $M$ must be a Symmetric Positive Semidefinite (PSD) matrix. Traditionally, enforcing this PSD constraint requires Semidefinite Programming (SDP) or iterative gradient descent with costly projections back onto the PSD cone. These iterative approaches scale poorly, often requiring hours or days of computation, and are highly sensitive to hyperparameter tuning.
A powerful alternative paradigm bypasses iterative optimization entirely. By reframing the core objective functions of metric learning, we can derive closed-form analytical solutions. Instead of searching the space of matrices step-by-step, these methods compute the globally optimal metric in a single mathematical operation—reducing training times from hours to seconds.
The Spectral Shortcut: Generalized Eigenvalue Problems
The most intuitive way to eliminate iterative optimization is to reframe metric learning as a generalized eigenvalue problem. The goal is simple: find a projection that minimizes the distance between similar data pairs while maximizing the distance between dissimilar pairs.
When we express this objective as a ratio of quadratic forms (specifically, a ratio of trace functions capturing between-class and within-class variance), it takes the form of a Generalized Rayleigh Quotient:
$$\max_W \frac{\text{Tr}(W^T S_b W)}{\text{Tr}(W^T S_w W)}$$
Setting the derivative of this ratio to zero yields the generalized eigenvalue equation: $S_b w = \lambda S_w w$.
As demonstrated by Alipanahi et al. in Distance Metric Learning Versus Fisher Discriminant Analysis, this formulation unifies modern metric learning with classical Fisher Discriminant Analysis (FDA). Instead of running an iterative solver, the optimal transformation matrix is constructed directly from the top eigenvectors of $S_w^{-1} S_b$.
This spectral shortcut provides massive computational speedups while maintaining or improving classification accuracy. The mechanism has been adapted across several domains:
- Constrained and Local Alignment: Liu et al. extended this to semi-supervised settings in Constrained Metric Learning Via Distance Gap Maximization by maximizing the distance "gap" between constrained pairs via trace ratios. For fine-grained cross-view matching, Pedagadi et al. utilized local Fisher discriminant analysis in Local Fisher Discriminant Analysis for Pedestrian Re-identification to handle complex, non-linear data manifolds without iterative loops.
- Unsupervised and Large-Scale Scaling: In Cross-View Asymmetric Metric Learning for Unsupervised Person Re-Identification, Hong-Xing Yu showed that formulating unsupervised cross-view alignment as a generalized eigen-problem allows the model to scale efficiently to hundreds of thousands of samples, bypassing the prohibitive costs of graph-based or dictionary learning methods.
- Discriminative Nullspaces: Taking this to the extreme, Feroz Ali et al. in Maximum Margin Metric Learning over Discriminative Nullspace for Person Re-identification leveraged closed-form generalized eigenvalue solutions to collapse within-class variance entirely to zero. This creates a "nullspace" where images of the same target map to an identical point, maximizing the margin against other classes without gradient descent.
From Pairwise Constraints to Linear Regression
Traditional metric learning relies on pairwise or triplet constraints ("point $A$ should be closer to $B$ than to $C$"). This introduces an $O(n^2)$ or $O(n^3)$ combinatorial explosion in the number of constraints.
To circumvent this, we can reframe metric learning as a regression task. Instead of optimizing relative distances between all pairs, we map each data point directly to a predefined target in an "ideal" space. This converts a highly constrained optimization problem into an unconstrained least-squares or ridge regression problem, which can be solved globally via direct matrix inversion.
Pairwise Constraints (Iterative, O(n²))
[Point A] <---> [Point B] (Must be close)
[Point A] <---> [Point C] (Must be far)
Virtual/Reference Regression (Closed-Form, O(n))
[Point A] -------> [Predefined Target Vector A]
[Point B] -------> [Predefined Target Vector B]
In Regressive Virtual Metric Learning, Perrot et al. introduced the concept of mapping data points to "virtual points." By minimizing the squared Frobenius norm between the projected data and these targets, the optimal transformation matrix drops out via a single closed-form matrix inversion, completely avoiding projections onto the PSD cone.
Similarly, Zhou et al. proposed a regression framework against learned "reference points" in Easy Identification From Better Constraints: Multi-Shot Person Re-Identification From Reference Constraints, reducing the constraint complexity from $O(n^2)$ to $O(n)$ while guaranteeing global optimality.
This regression perspective yields massive practical advantages across diverse applications:
- Supervised Clustering: Law et al. demonstrated in Closed-Form Training of Mahalanobis Distance for Supervised Clustering that a Mahalanobis metric can be learned in a single step by multiplying the feature matrix's Moore-Penrose pseudoinverse by a ground-truth partition matrix. This reduced training times from days to seconds.
- Identity Mapping: In Person Re-identification in Identity Regression Space, Zhu et al. formulated cross-view matching as a multivariate ridge regression problem, allowing a standard CPU to learn complex identity mappings in minutes rather than hours.
- Crowdsourcing and Tracking: Jinfeng Yi applied regression-based metric learning in Semi-Crowdsourced Clustering: Generalizing Crowd Labeling by Robust Distance Metric Learning to bypass explicit PSD constraints when handling noisy human labels. In real-time computer vision, Zhao et al. utilized closed-form metric regression in Object Tracking With Structured Metric Learning to update a tracker's distance metric on the fly as an object's appearance changes.
Bypassing Sampling with Closed-Form Distributional Metrics
When data objects are complex—such as images containing a "bag of pixels" or words with multiple meanings—it is often more accurate to represent them as probability distributions (like Gaussians or Gaussian Mixture Models) rather than single points. However, calculating the distance or similarity between two continuous distributions typically requires expensive numerical integration or Monte Carlo sampling.
To maintain efficiency, researchers choose specific kernel functions or distance metrics whose overlap integrals evaluate to an exact, closed-form algebraic expression.
The premier tool for this is the Expected Likelihood Kernel (ELK), which defines the similarity between two distributions $p(x)$ and $q(x)$ as the integral of their product:
$$K(p, q) = \int p(x)q(x)dx$$
In A Kernel Between Unordered Sets of Data: The Gaussian Mixture Approach, Siwei Lyu demonstrated that when $p(x)$ and $q(x)$ are Gaussian Mixture Models (GMMs), this integral evaluates to a simple closed-form sum of exponentials involving only the means and covariances of the mixtures. This allows exact similarity computations via basic matrix algebra, completely bypassing stochastic simulations.
This strategy of exploiting analytical integrals spans several domains:
- Representation Learning: Athiwaratkun et al. leveraged the ELK in Multimodal Word Distributions to train Gaussian mixtures representing polysemous words, using the closed-form kernel as an efficient energy function during training.
- Image-Text Matching: In Improved Probabilistic Image-Text Representations, Sanghyuk Chun used a closed-form metric combining mean Euclidean distance and variance sums to scale up probabilistic image-caption retrieval without the overhead of Monte Carlo sampling.
- Statistical Reductions: Sajedi et al. introduced a symmetric, triangle-inequality-compliant probabilistic distance metric in A New Probabilistic Distance Metric with Application in Gaussian Mixture Reduction. Because it offers a closed-form solution for Gaussian mixtures, it enables highly stable and rapid mixture reduction algorithms.
- Exponential Families: Nielsen et al. proved in On the Chi square and higher-order Chi distances for approximating f-divergences that for any distributions belonging to an affine exponential family, the integral of the density ratio can be solved analytically using the log-normalizer function, allowing exact Chi-square distance calculations.
Information Geometry and Manifold Optimization
The principle of closed-form optimization also extends to non-Euclidean spaces, such as information geometries (where kernel matrices are treated as probability distributions) and Riemannian manifolds (such as spaces of Symmetric Positive Definite matrices).
Instead of performing iterative Riemannian gradient descent—which requires expensive matrix decompositions at every step to stay on the curved manifold—the optimization problem can often be reframed so that the global optimum is found analytically.
In An Information Geometry Approach for Distance Metric Learning, Rong Jin minimized the Kullback-Leibler (KL) divergence between a data-driven kernel and an ideal label kernel. By framing the objective within information geometry, the optimal transformation matrix can be calculated via a closed-form solution, keeping training times nearly constant even as the number of samples grows.
For metric learning directly on Riemannian manifolds, Zhu et al. demonstrated in Towards Generalized and Efficient Metric Learning on Riemannian Manifold that the optimal transformation matrix can be derived as the closed-form solution to a algebraic Riccati equation. This geometric mean approach eliminates the need for iterative manifold projections entirely, providing a mathematically exact global optimum with minimal computational overhead.
Key Foundational Work
A Kernel Between Unordered Sets of Data: The Gaussian Mixture Approach (2005) — contributed 2 concept elements to this direction.
Learning Nonstructural Distance Metric by Minimum Cluster Distortion (2004) — contributed 1 concept elements to this direction.