summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2020-04-24 14:18:41 +0200
committerRémi Flamary <remi.flamary@gmail.com>2020-04-24 14:18:41 +0200
commit17d388be57cb5b0b2492c6b0ad8940e58b36016a (patch)
treef7d0cb9d67cf716a043c6bd82b283695048af12c
parent90bd408e86eccb03b02d57a0cd7963e0c848a1fc (diff)
test raise un partial ot
-rw-r--r--ot/datasets.py4
-rwxr-xr-xtest/test_partial.py49
2 files changed, 50 insertions, 3 deletions
diff --git a/ot/datasets.py b/ot/datasets.py
index a1ca7b6..daca1ae 100644
--- a/ot/datasets.py
+++ b/ot/datasets.py
@@ -147,8 +147,8 @@ def make_data_classif(dataset, n, nz=.5, theta=0, p=.5, random_state=None, **kwa
n2 = np.sum(y == 2)
x = np.zeros((n, 2))
- x[y == 1, :] = get_2D_samples_gauss(n1, m1, nz, random_state=generator)
- x[y == 2, :] = get_2D_samples_gauss(n2, m2, nz, random_state=generator)
+ x[y == 1, :] = make_2D_samples_gauss(n1, m1, nz, random_state=generator)
+ x[y == 2, :] = make_2D_samples_gauss(n2, m2, nz, random_state=generator)
x = x.dot(rot)
diff --git a/test/test_partial.py b/test/test_partial.py
index b533a9c..eb3b76e 100755
--- a/test/test_partial.py
+++ b/test/test_partial.py
@@ -8,6 +8,53 @@
import numpy as np
import scipy as sp
import ot
+import pytest
+
+
+def test_raise_errors():
+
+ n_samples = 20 # nb samples (gaussian)
+ n_noise = 20 # nb of samples (noise)
+
+ mu = np.array([0, 0])
+ cov = np.array([[1, 0], [0, 2]])
+
+ xs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)
+ xs = np.append(xs, (np.random.rand(n_noise, 2) + 1) * 4).reshape((-1, 2))
+ xt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov)
+ xt = np.append(xt, (np.random.rand(n_noise, 2) + 1) * -3).reshape((-1, 2))
+
+ M = ot.dist(xs, xt)
+
+ p = ot.unif(n_samples + n_noise)
+ q = ot.unif(n_samples + n_noise)
+
+ with pytest.raises(ValueError):
+ ot.partial.partial_wasserstein_lagrange(p + 1, q, M, 1, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.partial_wasserstein(p, q, M, m=2, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.partial_wasserstein(p, q, M, m=-1, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.entropic_partial_wasserstein(p, q, M, reg=1, m=2, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.entropic_partial_wasserstein(p, q, M, reg=1, m=-1, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.partial_gromov_wasserstein(M, M, p, q, m=2, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.partial_gromov_wasserstein(M, M, p, q, m=-1, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.entropic_partial_gromov_wasserstein(M, M, p, q, reg=1, m=2, log=True)
+
+ with pytest.raises(ValueError):
+ ot.partial.entropic_partial_gromov_wasserstein(M, M, p, q, reg=1, m=-1, log=True)
def test_partial_wasserstein_lagrange():
@@ -115,7 +162,7 @@ def test_partial_gromov_wasserstein():
m = 2 / 3
res0, log0 = ot.partial.partial_gromov_wasserstein(C1, C3, p, q, m=m,
- log=True)
+ log=True, verbose=True)
np.testing.assert_allclose(res0, 0, atol=1e-1, rtol=1e-1)
C1 = sp.spatial.distance.cdist(xs, xs)