From 365adbccc73f7fea28811b16cbbbdbb77761e55c Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Fri, 10 Jan 2020 13:01:42 +0100 Subject: add simple test for screenkhorn --- test/test_bregman.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/test_bregman.py b/test/test_bregman.py index f70df10..eb74a9f 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -337,3 +337,14 @@ def test_implemented_methods(): ot.bregman.sinkhorn(a, b, M, epsilon, method=method) with pytest.raises(ValueError): ot.bregman.sinkhorn2(a, b, M, epsilon, method=method) + +def test_screenkhorn(): + # test screenkhorn + rng = np.random.RandomState(0) + n = 100 + a = ot.unif(n) + b = ot.unif(n) + + x = rng.randn(n, 2) + M = ot.dist(x, x) + G_screen = ot.bregman.screenkhorn(a, b, M, 1e-1) \ No newline at end of file -- cgit v1.2.3 From 18242437e73aba9cf131fafc1571e376b57f25f6 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Mon, 13 Jan 2020 09:50:49 +0100 Subject: fix simple test of screenkhorn in test/ --- test/test_bregman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_bregman.py b/test/test_bregman.py index eb74a9f..bc8f6ae 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -347,4 +347,4 @@ def test_screenkhorn(): x = rng.randn(n, 2) M = ot.dist(x, x) - G_screen = ot.bregman.screenkhorn(a, b, M, 1e-1) \ No newline at end of file + G_screen = ot.bregman.screenkhorn(a, b, M, 1e-2, uniform=True, verbose=True) \ No newline at end of file -- cgit v1.2.3 From 4918d2c619aaa654c524c9c5dc7f4dc82b838f82 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Thu, 16 Jan 2020 16:44:40 +0100 Subject: update readme --- README.md | 2 +- test/test_bregman.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/README.md b/README.md index 987adf1..c115776 100644 --- a/README.md +++ b/README.md @@ -256,4 +256,4 @@ You can also post bug reports and feature requests in Github issues. Make sure t [25] Frogner C., Zhang C., Mobahi H., Araya-Polo M., Poggio T. (2015). [Learning with a Wasserstein Loss](http://cbcl.mit.edu/wasserstein/) Advances in Neural Information Processing Systems (NIPS). -[26] Alaya M. Z., Bérar M., Gasso G., Rakotomamonjy A. (2019). [Screening Sinkhorn Algorithm for Regularized Optimal Transport](https://papers.nips.cc/paper/9386-screening-sinkhorn-algorithm-for-regularized-optimal-transport), Advances in Neural Information Processing Systems 33 (NIPS). +[26] Alaya M. Z., Bérar M., Gasso G., Rakotomamonjy A. (2019). [Screening Sinkhorn Algorithm for Regularized Optimal Transport](https://papers.nips.cc/paper/9386-screening-sinkhorn-algorithm-for-regularized-optimal-transport), Advances in Neural Information Processing Systems 33 (NeurIPS). diff --git a/test/test_bregman.py b/test/test_bregman.py index bc8f6ae..52e9fb2 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -338,6 +338,7 @@ def test_implemented_methods(): with pytest.raises(ValueError): ot.bregman.sinkhorn2(a, b, M, epsilon, method=method) + def test_screenkhorn(): # test screenkhorn rng = np.random.RandomState(0) @@ -347,4 +348,4 @@ def test_screenkhorn(): x = rng.randn(n, 2) M = ot.dist(x, x) - G_screen = ot.bregman.screenkhorn(a, b, M, 1e-2, uniform=True, verbose=True) \ No newline at end of file + G_screen = ot.bregman.screenkhorn(a, b, M, 1e-2, uniform=True, verbose=True) -- cgit v1.2.3 From 936b5e1eb965e1d8c71b7b26cfa5238face1aaa3 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Thu, 16 Jan 2020 17:13:01 +0100 Subject: update --- .idea/POT.iml | 11 +++++++++++ test/test_bregman.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .idea/POT.iml (limited to 'test') diff --git a/.idea/POT.iml b/.idea/POT.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/POT.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/test/test_bregman.py b/test/test_bregman.py index 52e9fb2..bcec095 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -348,4 +348,4 @@ def test_screenkhorn(): x = rng.randn(n, 2) M = ot.dist(x, x) - G_screen = ot.bregman.screenkhorn(a, b, M, 1e-2, uniform=True, verbose=True) + G_screen = ot.bregman.screenkhorn(a, b, M, 1e-2, uniform=True, verbose=True) \ No newline at end of file -- cgit v1.2.3 From 3be0c215143e16c59ddd3be902416e91c3292937 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Sat, 18 Jan 2020 07:15:09 +0100 Subject: clean --- examples/plot_screenkhorn_1D.py | 2 +- test/test_bregman.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/examples/plot_screenkhorn_1D.py b/examples/plot_screenkhorn_1D.py index 103d54c..7c0de82 100644 --- a/examples/plot_screenkhorn_1D.py +++ b/examples/plot_screenkhorn_1D.py @@ -59,7 +59,7 @@ ot.plot.plot1D_mat(a, b, M, 'Cost matrix M') # ----------------------- # Screenkhorn -lambd = 1e-3 # entropy parameter +lambd = 1e-03 # entropy parameter ns_budget = 30 # budget number of points to be keeped in the source distribution nt_budget = 30 # budget number of points to be keeped in the target distribution diff --git a/test/test_bregman.py b/test/test_bregman.py index bcec095..2398d45 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -348,4 +348,7 @@ def test_screenkhorn(): x = rng.randn(n, 2) M = ot.dist(x, x) - G_screen = ot.bregman.screenkhorn(a, b, M, 1e-2, uniform=True, verbose=True) \ No newline at end of file + G_sink = ot.sinkhorn(a, b, M, 1e-03) + G_screen = ot.bregman.screenkhorn(a, b, M, 1e-03, uniform=True, verbose=True) + np.testing.assert_allclose(G_sink.sum(0), G_screen.sum(0), atol=1e-02) + np.testing.assert_allclose(G_sink.sum(1), G_screen.sum(1), atol=1e-02) \ No newline at end of file -- cgit v1.2.3 From b3fb1ef40a482f0989686b79373060d764b62d38 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Sat, 18 Jan 2020 07:45:34 +0100 Subject: clean --- ot/bregman.py | 3 ++- test/test_bregman.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/ot/bregman.py b/ot/bregman.py index aff9f8c..c304b5d 100644 --- a/ot/bregman.py +++ b/ot/bregman.py @@ -2117,10 +2117,11 @@ def screenkhorn(a, b, M, reg, ns_budget=None, nt_budget=None, uniform=False, res log['v'] = vsc_full log['Isel'] = Isel log['Jsel'] = Jsel + gamma = usc_full[:, None] * K * vsc_full[None, :] gamma = gamma / gamma.sum() if log: return gamma, log else: - return gamma \ No newline at end of file + return gamma diff --git a/test/test_bregman.py b/test/test_bregman.py index 2398d45..e376715 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -348,7 +348,7 @@ def test_screenkhorn(): x = rng.randn(n, 2) M = ot.dist(x, x) - G_sink = ot.sinkhorn(a, b, M, 1e-03) - G_screen = ot.bregman.screenkhorn(a, b, M, 1e-03, uniform=True, verbose=True) - np.testing.assert_allclose(G_sink.sum(0), G_screen.sum(0), atol=1e-02) - np.testing.assert_allclose(G_sink.sum(1), G_screen.sum(1), atol=1e-02) \ No newline at end of file + G_s = ot.sinkhorn(a, b, M, 1e-03) + G_sc = ot.bregman.screenkhorn(a, b, M, 1e-03, uniform=True, verbose=True) + np.testing.assert_allclose(G_s.sum(0), G_sc.sum(0), atol=1e-02) + np.testing.assert_allclose(G_s.sum(1), G_sc.sum(1), atol=1e-02) \ No newline at end of file -- cgit v1.2.3 From 7f7b1c547b54b394db975f4ff9d0287904a7b820 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Sat, 18 Jan 2020 09:04:48 +0100 Subject: make autopep --- test/test_bregman.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/test_bregman.py b/test/test_bregman.py index e376715..fd0679b 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -106,7 +106,6 @@ def test_sinkhorn_variants_log(): @pytest.mark.parametrize("method", ["sinkhorn", "sinkhorn_stabilized"]) def test_barycenter(method): - n_bins = 100 # nb bins # Gaussian distributions @@ -133,7 +132,6 @@ def test_barycenter(method): def test_barycenter_stabilization(): - n_bins = 100 # nb bins # Gaussian distributions @@ -161,7 +159,6 @@ def test_barycenter_stabilization(): def test_wasserstein_bary_2d(): - size = 100 # size of a square image a1 = np.random.randn(size, size) a1 += a1.min() @@ -185,7 +182,6 @@ def test_wasserstein_bary_2d(): def test_unmix(): - n_bins = 50 # nb bins # Gaussian distributions @@ -207,7 +203,7 @@ def test_unmix(): # wasserstein reg = 1e-3 - um = ot.bregman.unmix(a, D, M, M0, h0, reg, 1, alpha=0.01,) + um = ot.bregman.unmix(a, D, M, M0, h0, reg, 1, alpha=0.01, ) np.testing.assert_allclose(1, np.sum(um), rtol=1e-03, atol=1e-03) np.testing.assert_allclose([0.5, 0.5], um, rtol=1e-03, atol=1e-03) @@ -256,7 +252,7 @@ def test_empirical_sinkhorn(): def test_empirical_sinkhorn_divergence(): - #Test sinkhorn divergence + # Test sinkhorn divergence n = 10 a = ot.unif(n) b = ot.unif(n) @@ -348,7 +344,10 @@ def test_screenkhorn(): x = rng.randn(n, 2) M = ot.dist(x, x) - G_s = ot.sinkhorn(a, b, M, 1e-03) - G_sc = ot.bregman.screenkhorn(a, b, M, 1e-03, uniform=True, verbose=True) - np.testing.assert_allclose(G_s.sum(0), G_sc.sum(0), atol=1e-02) - np.testing.assert_allclose(G_s.sum(1), G_sc.sum(1), atol=1e-02) \ No newline at end of file + # sinkhorn + G_sink = ot.sinkhorn(a, b, M, 1e-03) + # screenkhorn + G_screen = ot.bregman.screenkhorn(a, b, M, 1e-03, uniform=True, verbose=True) + # check marginals + np.testing.assert_allclose(G_sink.sum(0), G_screen.sum(0), atol=1e-02) + np.testing.assert_allclose(G_s.sum(1), G_screen.sum(1), atol=1e-02) -- cgit v1.2.3 From a1747a10e80751eacca4273af61083a853fb9dd4 Mon Sep 17 00:00:00 2001 From: "Mokhtar Z. Alaya" Date: Sat, 18 Jan 2020 09:12:55 +0100 Subject: make autopep --- test/test_bregman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_bregman.py b/test/test_bregman.py index fd0679b..f54ba9f 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -350,4 +350,4 @@ def test_screenkhorn(): G_screen = ot.bregman.screenkhorn(a, b, M, 1e-03, uniform=True, verbose=True) # check marginals np.testing.assert_allclose(G_sink.sum(0), G_screen.sum(0), atol=1e-02) - np.testing.assert_allclose(G_s.sum(1), G_screen.sum(1), atol=1e-02) + np.testing.assert_allclose(G_sink.sum(1), G_screen.sum(1), atol=1e-02) -- cgit v1.2.3