Fréchet distance

In mathematics, the Fréchet distance is a measure of similarity between curves that takes into account the location and ordering of the points along the curves. It is named after Maurice Fréchet.

Intuitive definition
Imagine a person traversing a finite curved path while walking their dog on a leash, with the dog traversing a separate finite curved path. Each can vary their speed to keep slack in the leash, but neither can move backwards. The Fréchet distance between the two curves is the length of the shortest leash sufficient for both to traverse their separate paths from start to finish. Note that the definition is symmetric with respect to the two curves—the Fréchet distance would be the same if the dog were walking its owner.

Formal definition
Let $$S$$ be a metric space. A curve $$A$$ in $$S$$ is a continuous map from the unit interval into $$S$$, i.e., $$A : [0,1] \rightarrow S$$. A reparameterization $$\alpha$$ of $$[0,1]$$ is a continuous, non-decreasing, surjection $$\alpha: [0,1] \rightarrow [0,1]$$.

Let $$A$$ and $$B$$ be two given curves in $$S$$. Then, the Fréchet distance between $$A$$ and $$B$$ is defined as the infimum over all reparameterizations $$\alpha$$ and $$\beta$$ of $$[0,1]$$ of the maximum over all $$t \in [0,1]$$ of the distance in $$S$$ between $$A(\alpha(t))$$ and $$B(\beta(t))$$. In mathematical notation, the Fréchet distance $$F(A,B)$$ is

$$F(A,B) = \inf_{\alpha, \beta}\,\,\max_{t \in [0,1]} \,\, \biggl\{d \Bigl( A\bigl(\alpha(t)\bigr), \, B\bigl(\beta(t)\bigr) \Bigr) \biggr\}$$

where $$d$$ is the distance function of $$S$$.

Informally, we can think of the parameter $$t$$ as "time". Then, $$A(\alpha(t))$$ is the position of the dog and $$B(\beta(t))$$ is the position of the dog's owner at time $$t$$ (or vice versa). The length of the leash between them at time $$t$$ is the distance between $$A(\alpha(t))$$ and $$B(\beta(t))$$. Taking the infimum over all possible reparametrizations of $$[0,1]$$ corresponds to choosing the walk along the given paths where the maximum leash length is minimized. The restriction that $$\alpha$$ and $$\beta$$ be non-decreasing means that neither the dog nor its owner can backtrack.

The Fréchet metric takes into account the flow of the two curves because the pairs of points whose distance contributes to the Fréchet distance sweep continuously along their respective curves. This makes the Fréchet distance a better measure of similarity for curves than alternatives, such as the Hausdorff distance, for arbitrary point sets. It is possible for two curves to have small Hausdorff distance but large Fréchet distance.

The Fréchet distance and its variants find application in several problems, from morphing and handwriting recognition to protein structure alignment. Alt and Godau were the first to describe a polynomial-time algorithm to compute the Fréchet distance between two polygonal curves in Euclidean space, based on the principle of parametric search. The running time of their algorithm is $$O(mn \cdot \log(mn))$$ for two polygonal curves with m and n segments.

The free-space diagram
An important tool for calculating the Fréchet distance of two curves is the free-space diagram, which was introduced by Alt and Godau. The free-space diagram between two curves for a given distance threshold ε is a two-dimensional region in the parameter space that consists of all point pairs on the two curves at distance at most ε:

$$D_\varepsilon(A,B) := \bigl\{ (\alpha,\beta)\in[0,1]^2 \mathbin{\big|} d( A(\alpha), B(\beta))\le\varepsilon \bigr\} $$

The Fréchet distance $$F(A,B)$$ is at most ε if and only if the free-space diagram $$D_\varepsilon(A,B)$$ contains a path from the lower left corner to the upper right corner, which is monotone both in the horizontal and in the vertical direction.

As a distance between probability distributions (the FID score)
In addition to measuring the distances between curves, the Fréchet distance can also be used to measure the difference between probability distributions.

For two multivariate Gaussian distributions with means $$\mu_X$$ and $$\mu_Y$$ and covariance matrices $$\Sigma_X$$ and $$\Sigma_Y$$, the Fréchet distance between these distributions is $$d$$ given by

$$d^2 =|\mu_X-\mu_Y|^2+\operatorname{tr}(\Sigma_X+\Sigma_Y-2(\Sigma_X\Sigma_Y)^{1/2})$$.

This distance is the basis for the Fréchet inception distance (FID) that is used to compare images produced by a generative adversarial network with the real images that were used for training.

Variants
The weak Fréchet distance is a variant of the classical Fréchet distance without the requirement that the endpoints move monotonically along their respective curves &mdash; the dog and its owner are allowed to backtrack to keep the leash between them short. Alt and Godau describe a simpler algorithm to compute the weak Fréchet distance between polygonal curves, based on computing minimax paths in an associated grid graph.

The discrete Fréchet distance, also called the coupling distance, is an approximation of the Fréchet metric for polygonal curves, defined by Eiter and Mannila. The discrete Fréchet distance considers only positions of the leash where its endpoints are located at vertices of the two polygonal curves and never in the interior of an edge. This approximation unconditionally yields larger values than the corresponding (continuous) Fréchet distance. However, the approximation error is bounded by the largest distance between two adjacent vertices of the polygonal curves. Contrary to common algorithms of the (continuous) Fréchet distance, this algorithm is agnostic of the distance measures induced by the metric space. Its formulation as a dynamic programming problem can be implemented efficiently with a quadratic runtime and a linear memory overhead using only few lines of code.

When the two curves are embedded in a metric space other than Euclidean space, such as a polyhedral terrain or some Euclidean space with obstacles, the distance between two points on the curves is most naturally defined as the length of the shortest path between them. The leash is required to be a geodesic joining its endpoints. The resulting metric between curves is called the geodesic Fréchet distance. Cook and Wenk describe a polynomial-time algorithm to compute the geodesic Fréchet distance between two polygonal curves in a simple polygon.

If we further require that the leash must move continuously in the ambient metric space, then we obtain the notion of the homotopic Fréchet distance between two curves. The leash cannot switch discontinuously from one position to another &mdash; in particular, the leash cannot jump over obstacles, and can sweep over a mountain on a terrain only if it is long enough. The motion of the leash describes a homotopy between the two curves. Chambers et al. describe a polynomial-time algorithm to compute the homotopic Fréchet distance between polygonal curves in the Euclidean plane with obstacles.

Examples
The Fréchet distance between two concentric circles of radius $$r_1$$ and $$r_2$$ respectively is $$|r_1 - r_2|.$$ The longest leash is required when the owner stands still and the dog travels to the opposite side of the circle ($$r_1 + r_2$$), and the shortest leash when both owner and dog walk at a constant angular velocity around the circle ($$|r_1 - r_2|$$).

Applications
Fréchet distance has been used to study visual hierarchy, a graphic design principle.