In machine learning, distance is everything. Whether you are clustering data with $k$-means, retrieving similar images, or classifying samples using $k$-nearest neighbors, your results depend entirely on how you measure the space between data points.
By default, we often turn to standard Euclidean distance. However, Euclidean distance treats every feature dimension equally and assumes they are completely independent. In real-world data, this assumption fails. If you are analyzing faces, a millimeter change in eye distance matters far more than a millimeter change in background lighting. To fix this, we must learn a custom distance metric tailored to our specific task.
Historically, learning these transformations was a treacherous optimization problem. Early techniques frequently got trapped in local minima, making the learned metrics highly sensitive to initialization. The breakthrough came when researchers realized that by framing distance metric learning as a convex optimization problem, they could guarantee a single, globally optimal distance metric every single time.
The Non-Convex Trap of Space Warping
To understand why convex metric learning works, we must first look at how it avoids the mathematical traps of non-convex alternatives.
Imagine we want to learn a linear transformation matrix $L$ that projects our data into a new space where distance reflects semantic similarity. The distance between two points $x$ and $y$ in this transformed space would be:
$$d(x, y) = \|Lx - Ly\|_2$$
If we try to optimize the elements of $L$ directly based on user feedback, the optimization landscape becomes non-convex. Because $L$ interacts with itself multiplicatively in the distance formula, the objective function develops multiple local minima. As noted by Xing et al. and Globerson et al., this makes manual parameter tuning or gradient descent highly unpredictable; a model might find a great metric on one run and a terrible one on the next simply due to its random initialization.
The Core Insight: Optimizing the Metric Cone
Convex metric learning bypasses this issue entirely through a clever mathematical reparameterization. Instead of learning the transformation matrix $L$ directly, we square the distance formula and rewrite it using a single matrix $M$:
$$d_M(x, y)^2 = (x - y)^T L^T L (x - y) = (x - y)^T M (x - y)$$
Here, $M = L^T L$ represents a generalized Mahalanobis distance. For $M$ to define a valid, mathematically rigorous metric space, it must satisfy two core properties:
- Symmetry: $M = M^T$
- Positive Semidefiniteness ($M \succeq 0$): This ensures that distances are never negative ($d_M(x, y)^2 \ge 0$).
The secret sauce of this framework lies in the geometry of these properties. The set of all positive semidefinite (PSD) matrices forms a convex cone. If you take two valid PSD metric matrices, $M_1$ and $M_2$, any convex combination of them ($\alpha M_1 + (1-\alpha)M_2$ for $\alpha \in [0,1]$) is also a valid PSD metric matrix.
If we can design an objective function that is also convex with respect to $M$, the entire optimization problem becomes convex. The treacherous landscape of local minima collapses into a single, well-behaved bowl with a guaranteed global optimum.
Non-Convex Landscape (Optimizing L) Convex Landscape (Optimizing M over the PSD Cone)
_ _ \ /
/ \_/ \ \ /
/ \ \ /
Local Local \_________/
Minima Minima Global Optimum
Translating Side Information into Convex Constraints
To guide the optimization of $M$, we provide the algorithm with "side information"—qualitative constraints about how the space should look. Because the underlying space is a convex cone, we can translate various forms of human feedback into linear or convex constraints.
Pairwise Constraints (Must-Link / Cannot-Link)
The most intuitive form of side information consists of pairs of points that should be close together or far apart. Xing et al. formulated this by minimizing the sum of squared distances between all "must-link" pairs while enforcing a constraint that "cannot-link" pairs maintain a minimum distance.
To prevent the trivial solution where the algorithm collapses all distances to zero ($M=0$), Ghodsi demonstrated that adding a trace constraint ($\text{Tr}(M) = c$) keeps the optimization landscape perfectly convex while preventing distance collapse. Similarly, the authors of Semi-Supervised Metric Learning Using Pairwise Constraints solved this tension by framing it as a trace ratio problem that balances local constraints with the global manifold structure.
Relative Comparisons (Triplets)
Often, humans are bad at providing absolute distance thresholds but excellent at making relative comparisons, such as: "Object $A$ is more like $B$ than it is like $C$."
Schultz et al. showed that these triplet constraints can be modeled as a functional margin, directly mimicking the optimization structure of Support Vector Machines (SVMs):
$$d_M(x_A, x_C)^2 - d_M(x_A, x_B)^2 \ge 1$$
Because this constraint is linear with respect to the parameters of $M$, it preserves the convexity of the problem, resulting in a robust quadratic program that can be solved efficiently using standard optimization tools.
Large Margin Nearest Neighbors (LMNN)
Instead of enforcing global constraints across the entire dataset, the authors of Distance Metric Learning for Large Margin Nearest Neighbor Classification tailored the convex optimization specifically for $k$-nearest neighbor classification.
Their framework sets up a perimeter around each data point. It uses semidefinite programming (SDP) to pull target neighbors of the same class closer while penalizing "impostor" points of different classes that invade this local neighborhood. Because the objective combines a linear penalty for distance with a hinge loss for margin violations, it remains entirely convex.
Target Neighbor (Same Class)
\
[•] ← (Pulled closer)
|
(•) Target Point
|
=======|====== Margin Perimeter
|
[X] ← Impostor (Pushed outside)
Algorithmic Frameworks for Global Optimality
While semidefinite programming guarantees a global optimum, standard interior-point SDP solvers can be computationally expensive for high-dimensional data. To scale convex metric learning, researchers have developed specialized optimization paradigms.
Information-Theoretic Metric Learning (ITML)
Kulis et al. revolutionized the speed of convex metric learning by framing the problem information-theoretically. Instead of treating $M$ purely as a geometric operator, they recognized a bijection between the cone of PSD matrices and the multivariate Gaussian distribution.
By minimizing the Burg matrix divergence between the learned metric $M$ and a baseline prior metric $M_0$ (such as the identity matrix), they created a strictly convex objective function. This formulation allows for simple, iterative projection algorithms that satisfy constraints one by one, guaranteeing convergence to the global optimum without ever requiring an expensive full-matrix semidefinite solver.
Maximally Collapsing Metric Learning (MCML)
Globerson et al. took a probabilistic approach by defining a conditional probability distribution where the probability of point $x$ selecting point $y$ as its neighbor decays exponentially with their Mahalanobis distance.
Their ideal target is a space where all points in the same class collapse to the exact same coordinates (distance 0) and points of different classes are infinitely far apart. By minimizing the Kullback-Leibler (KL) divergence between the actual distribution and this ideal target, they arrived at an optimization problem that is strictly convex over the PSD cone, ensuring a unique global solution.
Local Adjustments for Global Consistency
Convexity also allows global constraints to be satisfied through purely local updates. For instance, when given a matrix of messy, non-metric pairwise distances, Dhillon et al. showed that iteratively fixing individual violations of the triangle inequality guarantees convergence to the globally closest valid metric.
Beyond Simple Vector Spaces
The mathematical guarantees of convex metric learning extend far beyond standard vector spaces:
- Structured Graph Data: Yoshida et al. extended convex similarity learning to graph structures. By combining convex optimization with safe screening pruning techniques, their framework identifies a globally optimal, interpretable set of subgraphs for graph distance metrics.
- Temporal Sequence Alignment: Lajugie et al. proved that learning a Mahalanobis metric to optimize sequence alignment (like Dynamic Time Warping) can be framed as a structured prediction problem. By proving their loss function is concave over the convex hull of possible alignments, they unlocked standard convex tools for complex time-series tasks.
- Orthogonality and Feature Selection: When learning metrics, we often want our projection vectors to be orthogonal to avoid redundant features. While strict orthogonality constraints are non-convex, Xie et al. introduced convex relaxations using von Neumann divergences, allowing models to promote feature independence while preserving global convergence guarantees.
By mapping the abstract concept of "similarity" onto the rigid, elegant geometry of the positive semidefinite cone, convex metric learning transforms an unpredictable art into an exact, reproducible science.
Key Foundational Work
Distance Metric Learning with Application to Clustering with Side-Information (2002) — contributed 3 concept elements to this direction.
Learning a Distance Metric from Relative Comparisons (2003) — contributed 2 concept elements to this direction.
Adapting Codes and Embeddings for Polychotomies (2002) — contributed 1 concept elements to this direction.