diff options
author | RĂ©mi Flamary <remi.flamary@gmail.com> | 2017-09-14 16:22:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-14 16:22:41 +0200 |
commit | e70d5420204db78691af2d0fbe04cc3d4416a8f4 (patch) | |
tree | f11601b6b1d7ef821a0ae3233960f6f29a1ac0f7 /test | |
parent | a53ede95f916a11e2150ab7917820d813c0034bc (diff) | |
parent | c7eef9dd32212ddeebf716cd5dd54df8974c166d (diff) |
Merge pull request #23 from rflamary/gromov
Gromov-Wasserstein distance
Diffstat (limited to 'test')
-rw-r--r-- | test/test_gromov.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/test_gromov.py b/test/test_gromov.py new file mode 100644 index 0000000..e808292 --- /dev/null +++ b/test/test_gromov.py @@ -0,0 +1,37 @@ +"""Tests for module gromov """
+
+# Author: Erwan Vautier <erwan.vautier@gmail.com>
+# Nicolas Courty <ncourty@irisa.fr>
+#
+# License: MIT License
+
+import numpy as np
+import ot
+
+
+def test_gromov():
+ n_samples = 50 # nb samples
+
+ mu_s = np.array([0, 0])
+ cov_s = np.array([[1, 0], [0, 1]])
+
+ xs = ot.datasets.get_2D_samples_gauss(n_samples, mu_s, cov_s)
+
+ xt = xs[::-1].copy()
+
+ p = ot.unif(n_samples)
+ q = ot.unif(n_samples)
+
+ C1 = ot.dist(xs, xs)
+ C2 = ot.dist(xt, xt)
+
+ C1 /= C1.max()
+ C2 /= C2.max()
+
+ G = ot.gromov_wasserstein(C1, C2, p, q, 'square_loss', epsilon=5e-4)
+
+ # check constratints
+ np.testing.assert_allclose(
+ p, G.sum(1), atol=1e-04) # cf convergence gromov
+ np.testing.assert_allclose(
+ q, G.sum(0), atol=1e-04) # cf convergence gromov
|