summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2017-07-24 12:11:34 +0200
committerRémi Flamary <remi.flamary@gmail.com>2017-07-24 12:11:34 +0200
commita8a0995edefd437f56b91b95c2628fb031428a08 (patch)
tree85c4f4ac39e8257b63062cce91cf53e622233ca2 /test
parent75492827c89a47cbc6807d4859be178d255c49bc (diff)
pep8 tests
Diffstat (limited to 'test')
-rw-r--r--test/test_bregman.py43
-rw-r--r--test/test_ot.py34
2 files changed, 61 insertions, 16 deletions
diff --git a/test/test_bregman.py b/test/test_bregman.py
new file mode 100644
index 0000000..fd2c972
--- /dev/null
+++ b/test/test_bregman.py
@@ -0,0 +1,43 @@
+
+
+import ot
+import numpy as np
+
+# import pytest
+
+
+def test_sinkhorn():
+ # test sinkhorn
+ n = 100
+ np.random.seed(0)
+
+ x = np.random.randn(n, 2)
+ u = ot.utils.unif(n)
+
+ M = ot.dist(x, x)
+
+ G = ot.sinkhorn(u, u, M, 1, stopThr=1e-10)
+
+ # check constratints
+ assert np.allclose(u, G.sum(1), atol=1e-05) # cf convergence sinkhorn
+ assert np.allclose(u, G.sum(0), atol=1e-05) # cf convergence sinkhorn
+
+
+def test_sinkhorn_variants():
+ # test sinkhorn
+ n = 100
+ np.random.seed(0)
+
+ x = np.random.randn(n, 2)
+ u = ot.utils.unif(n)
+
+ M = ot.dist(x, x)
+
+ G0 = ot.sinkhorn(u, u, M, 1, method='sinkhorn', stopThr=1e-10)
+ Gs = ot.sinkhorn(u, u, M, 1, method='sinkhorn_stabilized', stopThr=1e-10)
+ Ges = ot.sinkhorn(
+ u, u, M, 1, method='sinkhorn_epsilon_scaling', stopThr=1e-10)
+
+ # check constratints
+ assert np.allclose(G0, Gs, atol=1e-05)
+ assert np.allclose(G0, Ges, atol=1e-05)
diff --git a/test/test_ot.py b/test/test_ot.py
index b69d080..9103ac8 100644
--- a/test/test_ot.py
+++ b/test/test_ot.py
@@ -36,7 +36,8 @@ def test_emd_emd2():
# check loss=0
assert np.allclose(w, 0)
-
+
+
def test_emd2_multi():
from ot.datasets import get_1D_gauss as gauss
@@ -72,11 +73,11 @@ def test_emd2_multi():
emdn = ot.emd2(a, b, M)
ot.toc('multi proc : {} s')
- assert np.allclose(emd1, emdn)
-
-
+ assert np.allclose(emd1, emdn)
+
+
def test_sinkhorn():
- # test sinkhorn
+ # test sinkhorn
n = 100
np.random.seed(0)
@@ -85,14 +86,15 @@ def test_sinkhorn():
M = ot.dist(x, x)
- G = ot.sinkhorn(u, u, M,1,stopThr=1e-10)
+ G = ot.sinkhorn(u, u, M, 1, stopThr=1e-10)
# check constratints
- assert np.allclose(u, G.sum(1), atol=1e-05) # cf convergence sinkhorn
- assert np.allclose(u, G.sum(0), atol=1e-05) # cf convergence sinkhorn
-
+ assert np.allclose(u, G.sum(1), atol=1e-05) # cf convergence sinkhorn
+ assert np.allclose(u, G.sum(0), atol=1e-05) # cf convergence sinkhorn
+
+
def test_sinkhorn_variants():
- # test sinkhorn
+ # test sinkhorn
n = 100
np.random.seed(0)
@@ -101,11 +103,11 @@ def test_sinkhorn_variants():
M = ot.dist(x, x)
- G0 = ot.sinkhorn(u, u, M,1, method='sinkhorn',stopThr=1e-10)
- Gs = ot.sinkhorn(u, u, M,1, method='sinkhorn_stabilized',stopThr=1e-10)
- Ges = ot.sinkhorn(u, u, M,1, method='sinkhorn_epsilon_scaling',stopThr=1e-10)
+ G0 = ot.sinkhorn(u, u, M, 1, method='sinkhorn', stopThr=1e-10)
+ Gs = ot.sinkhorn(u, u, M, 1, method='sinkhorn_stabilized', stopThr=1e-10)
+ Ges = ot.sinkhorn(
+ u, u, M, 1, method='sinkhorn_epsilon_scaling', stopThr=1e-10)
# check constratints
- assert np.allclose(G0, Gs, atol=1e-05)
- assert np.allclose(G0, Ges, atol=1e-05) #
-
+ assert np.allclose(G0, Gs, atol=1e-05)
+ assert np.allclose(G0, Ges, atol=1e-05)