Advanced maths

Gromov Hausdorff distance calculator between finite metric spaces

Compute the exact Gromov–Hausdorff distance of two small finite metric spaces by covering correspondences.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Compute the exact Gromov–Hausdorff distance of two small finite metric spaces by covering correspondences.

THE FORMULAdGH(X,Y) = (1/2) min_R max |dX(x,x′)−dY(y,y′)|, where R projects onto both spaces

A worked example

Two two-point metric spaces whose nonzero distances are two and four have Gromov–Hausdorff distance one: every covering correspondence has distortion at least two, and a bijection attains two.

Good to know

Two rational distance matrices with2–4 points each, exact metric axioms. Enumerate all covering correspondences and minimize half the maximum pairwise distance distortion; return an optimal relation and distortion witness. Cap relation enumeration; no bijection-only shortcut or graph approximation claimed exact.

Comparing spaces without a common frame

Ordinary Hausdorff distance compares subsets already placed in one ambient metric space. Gromov–Hausdorff distance compares metric spaces themselves, allowing their realizations to change. The input is therefore a distance matrix for each space, rather than coordinates that are assumed to share a meaningful origin, orientation or embedding.

A relabeling of points cannot change the answer. Neither can an isometric representation in another ambient space. This makes the quantity appropriate for an intrinsic finite metric comparison, but it also means it answers a different question from the distance between two polylines in their supplied planar coordinates.

Gromov Hausdorff distance between finite metric spacesdX = 2dY = 4distortion 2Gromov–Hausdorff distance = 1
Scroll across to see the full diagram.
Two two-point metric spaces whose nonzero distances are two and four have Gromov–Hausdorff distance one: every covering correspondence has distortion at least two, and a bijection attains two.

Compare this with the Symmetric Hausdorff distance calculator between planar polylines. Compare abstract finite metrics through correspondences, without assuming both objects already share an ambient coordinate frame. Ordinary Hausdorff compares subsets of one metric space.

Validating the metric matrices

Each matrix must have a zero diagonal, positive distances between distinct points, symmetry and the triangle inequality. These conditions define the supported finite metric spaces. A matrix with a zero off-diagonal entry is a pseudometric unless equivalent points are deliberately identified, which this initial input convention does not do automatically.

Rational entries permit exact comparisons of the metric axioms and correspondence distortions. Invalid data should be rejected rather than repaired through an unstated nearest-metric projection. Replacing entries to make the triangle inequality hold would change the object being compared and could produce a plausible distance for a different pair of spaces.

Correspondences can be many to many

A correspondence is a relation between the two point sets that covers every point on both sides. It need not be a bijection, and the spaces may have different cardinalities. Allowing relations rather than only permutations is essential to the general finite-space definition and to handling points that correspond to groups of nearby points in the other space.

The distortion of a relation is the largest absolute difference between paired within-space distances. Examine every pair of relation edges to compute it. A correspondence with small distortion matches relational geometry, not necessarily coordinates. Restricting the search to one-to-one assignments would solve a smaller problem and can overestimate the actual Gromov–Hausdorff distance.

Why the answer is half the distortion

For compact metric spaces, the correspondence formulation expresses Gromov–Hausdorff distance as one half the least possible distortion. In the finite supported setting, the minimum is attained among finitely many covering relations. The factor one half is part of the definition-equivalence and should not be omitted when converting the optimal distortion to the reported distance.

The winning relation gives an upper-bound witness. Exhaustive enumeration or an equivalent complete exact search establishes that no relation has smaller distortion. Retain a pair of matched point pairs realizing the maximum discrepancy, so a reader can check both the reported distortion and its conversion to the distance without relying on the plot.

The two-point calculation

Let the first space have distance two between its two points and the second have distance four. A bijection pairs distinct points with distinct points, producing discrepancy two. It therefore gives distortion two and a Gromov–Hausdorff upper bound of one. The other bijection has the same value because labels do not matter.

Any covering relation must represent the two points separated by four in the second space. Their partners in the first space are either the same point, producing discrepancy four, or distinct points, producing discrepancy two. Thus every relation has distortion at least two, and the upper bound is sharp. The exact distance is one.

Exact enumeration and its limits

For spaces with a few points, enumerate relation subsets and reject those failing either coverage condition. Compute the remaining distortions exactly and retain an optimum. The number of potential relations grows exponentially in the product of the cardinalities, which is why the supported point counts are intentionally very small.

A relation cap or rational-arithmetic cap must return an unresolved result if completeness has not been established. A good greedy matching is only an upper bound until a matching lower bound or complete search is available. It should not be displayed as an exact distance simply because the relation covers all points and looks intuitively sensible.

Interpreting a small or zero distance

A zero answer for finite metric spaces means they are isometric after the appropriate point correspondence. A positive answer measures the least intrinsic discrepancy under the definition, not a physical registration error in a preselected coordinate frame. The units are the same distance units used in the input matrices.

Keep graph approximations and sampled manifolds separate from the finite objects entered here. Computing this finite distance does not by itself certify the Gromov–Hausdorff distance of an unsampled continuous surface. Additional approximation bounds would be needed to transfer the finite result to that larger object. The bounded calculator provides exact evidence for the supplied finite metrics.

A few questions, answered

Must the two spaces have the same number of points?

No. Covering correspondences may relate several points to one point.

Can I search only permutations?

Not in general. Bijection-only search can miss a lower-distortion covering relation.

Why divide the distortion by two?

The correspondence characterization of Gromov–Hausdorff distance includes that factor.

Does this compare the given coordinate placement?

No. It compares intrinsic metrics, unlike ordinary Hausdorff distance in a shared coordinate frame.

Find your calculator

Start typing to explore the library.