Given the distance matrices of metric spaces
where
is the distortion of a relation
The distance is estimated from above by solving its parametric relaxation whose minima are guaranteed to deliver
A detailed description of the relaxation (including its optimality guarantees, optimization landscape, and the minimization algorithm), along with guidance for selecting the relaxation parameter
To install the package from Python Package Index:
$ pip install dgh
Consider
To create their distance matrices, whose
>>> import numpy as np
>>> X = np.array([[0, 1, 10, 10],
... [0, 0, 10, 10],
... [0, 0, 0, 1],
... [0, 0, 0, 0]])
>>> X += X.T
>>> Y = np.array([[0, 1, 1, 10],
... [0, 0, 1, 10],
... [0, 0, 0, 10],
... [0, 0, 0, 0]])
>>> Y += Y.T
To compute (an upper bound of) their Gromov–Hausdorff distance
>>> import dgh
>>> dGH = dgh.upper(X, Y)
>>> dGH
0.5
In this case, the distance
By default, the algorithm is allocated 100 iterations of conditional gradient descent. The algorithm restarts from a random point every time after converging to an approximate solution (i.e. a stationary point) until the iteration budget is depleted. Bigger budget generally means longer run time and better accuracy.
To set the iteration budget:
>>> dGH = dgh.upper(X, Y, iter_budget=20)
>>> dGH
0.5
Every solution is a mapping pair
>>> dGH, f, g = dgh.upper(X, Y, return_fg=True)
>>> f
[2, 2, 3, 3]
>>> g
[1, 1, 1, 2]
The
Explicitly specifying the relaxation parameter
By default, the method allocates half of the iteration budget to select the best value of
To see the value of
>>> dgh.upper(X, Y, verbose=1)
iteration budget 100 | c=auto | dGH≥0
spent 49 iterations to choose c=1.0001
proved dGH≤0.5 after 40 restarts
To specify
>>> dGH = dgh.upper(X, Y, c=1000)
>>> dGH
0.5
If you found a bug or want to suggest an enhancement, you can create a GitHub Issue. Alternatively, you can email vlad.oles (at) proton (dot) me.
dGH is released under the MIT license.
To cite dGH, you can use the following:
Oles, V. (2023). Computing the Gromov–Hausdorff distance using gradient methods. arXiv preprint arXiv:2307.13660.
@article{oles2023computing,
title={Computing the Gromov--Hausdorff distance using gradient methods},
author={Oles, Vladyslav},
journal={arXiv preprint arXiv:2307.13660},
year={2023}
}