diff options
Diffstat (limited to 'test/test_da.py')
-rw-r--r-- | test/test_da.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/test/test_da.py b/test/test_da.py index 50d3aba..a38390f 100644 --- a/test/test_da.py +++ b/test/test_da.py @@ -1,19 +1,17 @@ - -import ot import numpy as np - -# import pytest +import ot -def test_OTDA(): +def test_otda(): - n = 150 # nb bins + n_samples = 150 # nb samples + np.random.seed(0) - xs, ys = ot.datasets.get_data_classif('3gauss', n) - xt, yt = ot.datasets.get_data_classif('3gauss2', n) + xs, ys = ot.datasets.get_data_classif('3gauss', n_samples) + xt, yt = ot.datasets.get_data_classif('3gauss2', n_samples) - a, b = ot.unif(n), ot.unif(n) + a, b = ot.unif(n_samples), ot.unif(n_samples) # LP problem da_emd = ot.da.OTDA() # init class @@ -21,8 +19,8 @@ def test_OTDA(): da_emd.interp() # interpolation of source samples da_emd.predict(xs) # interpolation of source samples - assert np.allclose(a, np.sum(da_emd.G, 1)) - assert np.allclose(b, np.sum(da_emd.G, 0)) + np.testing.assert_allclose(a, np.sum(da_emd.G, 1)) + np.testing.assert_allclose(b, np.sum(da_emd.G, 0)) # sinkhorn regularization lambd = 1e-1 @@ -31,8 +29,8 @@ def test_OTDA(): da_entrop.interp() da_entrop.predict(xs) - assert np.allclose(a, np.sum(da_entrop.G, 1), rtol=1e-3, atol=1e-3) - assert np.allclose(b, np.sum(da_entrop.G, 0), rtol=1e-3, atol=1e-3) + np.testing.assert_allclose(a, np.sum(da_entrop.G, 1), rtol=1e-3, atol=1e-3) + np.testing.assert_allclose(b, np.sum(da_entrop.G, 0), rtol=1e-3, atol=1e-3) # non-convex Group lasso regularization reg = 1e-1 @@ -42,8 +40,8 @@ def test_OTDA(): da_lpl1.interp() da_lpl1.predict(xs) - assert np.allclose(a, np.sum(da_lpl1.G, 1), rtol=1e-3, atol=1e-3) - assert np.allclose(b, np.sum(da_lpl1.G, 0), rtol=1e-3, atol=1e-3) + np.testing.assert_allclose(a, np.sum(da_lpl1.G, 1), rtol=1e-3, atol=1e-3) + np.testing.assert_allclose(b, np.sum(da_lpl1.G, 0), rtol=1e-3, atol=1e-3) # True Group lasso regularization reg = 1e-1 @@ -53,8 +51,8 @@ def test_OTDA(): da_l1l2.interp() da_l1l2.predict(xs) - assert np.allclose(a, np.sum(da_l1l2.G, 1), rtol=1e-3, atol=1e-3) - assert np.allclose(b, np.sum(da_l1l2.G, 0), rtol=1e-3, atol=1e-3) + np.testing.assert_allclose(a, np.sum(da_l1l2.G, 1), rtol=1e-3, atol=1e-3) + np.testing.assert_allclose(b, np.sum(da_l1l2.G, 0), rtol=1e-3, atol=1e-3) # linear mapping da_emd = ot.da.OTDA_mapping_linear() # init class |