Abstract
The Metric Nearness problem seeks the closest valid distance metric to a given dissimilarity matrix that may violate the triangle inequality. While critical for robust data processing, the $O(n^3)$ constraints make it computationally prohibitive for large datasets. This paper proposes a two-stage algorithm: first, finding a high-quality approximation in the subspace of isometrically embeddable metrics, followed by refinement using the Halpern-Lions-Wittmann-Bauschke (HLWB) projection. This approach achieves 100% constraint satisfaction and significantly outperforms state-of-the-art methods in speed and memory efficiency, scaling to datasets with over 10,000 samples.
Introduction
In machine learning and data processing, data is often assumed to reside in a metric space where distances are symmetric, non-negative, and satisfy the triangle inequality. However, real-world dissimilarity matrices frequently violate these rules due to sensor noise or inconsistent human annotations. The Metric Nearness problem addresses this by finding the mathematically "closest" valid distance metric to noisy data.
The primary challenge lies in the $O(n^3)$ triangle inequality constraints. For a dataset of 1,000 samples, this translates to approximately one billion constraints, causing standard solvers to exceed memory limits. Existing dedicated algorithms like Triangle Fixing (TRF) and Project and Forget (PAF) also struggle with memory overhead and slow convergence as $n$ increases. This work introduces a practical two-stage approach to overcome these scalability barriers.
Methodology
The proposed approach addresses these limitations through a two-stage process:
- Embedding Calibration (Warm Start): The algorithm first searches for a high-quality approximation within the subspace of isometrically embeddable metrics—those representable as points in Euclidean space. By leveraging Schoenberg’s theorem, this is transformed into a Positive Semi-Definite (PSD) matrix projection problem, solved efficiently via Dykstra’s projection algorithm. A fast heuristic then further refines this starting point.
- HLWB Projection (Polishing): To reach the optimal solution, the algorithm employs the Halpern-Lions-Wittmann-Bauschke (HLWB) method. This alternating projection technique sequentially projects the matrix onto the half-spaces defined by triangle inequalities.
By initializing with a high-quality approximation from Stage 1, the HLWB stage converges rapidly. Crucially, the implementation requires only $O(n^2)$ memory, as it avoids explicitly storing the full active constraint set, a major bottleneck in previous methods.
Results and Discussion
The algorithm was evaluated on synthetic graphs (Graph-t1, Graph-t2) and the MNIST dataset, with $n$ ranging up to 10,000.
Convergence and Constraint Satisfaction
A standout feature of the HLWB approach is its immediate conformity to metric constraints. As shown in Figure 1, the Constraint Satisfaction Ratio (CSR) reaches 1.0 (100% valid) almost instantly across different datasets and problem sizes, while the Normalized Mean Square Error (NMSE) stabilizes quickly.
Scalability and Memory Efficiency
The proposed method demonstrates superior scalability. On the MNIST dataset ($n=1,500$), HLWB converged in approximately 50 seconds, representing a ~34x speedup over TRF and PAF. Furthermore, Figure 2 highlights the dramatic difference in memory consumption. While PAF's memory usage grows rapidly, reaching 30 GB at $n=10,000$, HLWB maintains a manageable footprint of approximately 3 GB. This efficiency allows the algorithm to run on standard workstations for problems where previous state-of-the-art methods failed.
Conclusion
By decomposing the metric nearness problem into a subspace approximation followed by an efficient projection refinement, this work makes large-scale distance matrix repair practical. The $O(n^2)$ memory complexity and rapid convergence enable the processing of datasets an order of magnitude larger than previously possible, moving metric nearness from theoretical interest to practical utility in data science workflows.
Summary updated