  Density-based distances (DBDs) offer an elegant solution to the problem of
metric learning. By defining a Riemannian metric which increases with
decreasing probability density, shortest paths naturally follow the data
manifold and points are clustered according to the modes of the data. We show
that existing methods to estimate Fermat distances, a particular choice of DBD,
suffer from poor convergence in both low and high dimensions due to i)
inaccurate density estimates and ii) reliance on graph-based paths which are
increasingly rough in high dimensions. To address these issues, we propose
learning the densities using a normalizing flow, a generative model with
tractable density estimation, and employing a smooth relaxation method using a
score model initialized from a graph-based proposal. Additionally, we introduce
a dimension-adapted Fermat distance that exhibits more intuitive behavior when
scaled to high dimensions and offers better numerical properties. Our work
paves the way for practical use of density-based distances, especially in
high-dimensional spaces.
