diff options
author | Minhui Huang <32522773+mhhuang95@users.noreply.github.com> | 2021-09-06 08:06:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-06 17:06:50 +0200 |
commit | 96bf1a46e74d6985419e14222afb0b9241a7bb36 (patch) | |
tree | 6d2b89760a5e3568a79df5c96bc30439c2e82297 /test | |
parent | c105dcb892de87ae9c6cfcfc5d9c0b14f2933082 (diff) |
[MRG] Projection Robust Wasserstein (#267)
* ot.dr: PRW code; text.text_dr: PRW test code.
* ot.dr: PRW code; test.test_dr: PRW test code.
* fix errors: pep8(3.8)
* fix errors: pep8(3.8)
* modified readme; prw code review
* fix pep error
* edit comment
* modified math comment
Co-authored-by: RĂ©mi Flamary <remi.flamary@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_dr.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/test_dr.py b/test/test_dr.py index c5df287..fa75a18 100644 --- a/test/test_dr.py +++ b/test/test_dr.py @@ -1,6 +1,7 @@ """Tests for module dr on Dimensionality Reduction """ # Author: Remi Flamary <remi.flamary@unice.fr> +# Minhui Huang <mhhuang@ucdavis.edu> # # License: MIT License @@ -57,3 +58,39 @@ def test_wda(): projwda(xs) np.testing.assert_allclose(np.sum(Pwda**2, 0), np.ones(p)) + + +@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)") +def test_prw(): + d = 100 # Dimension + n = 100 # Number samples + k = 3 # Subspace dimension + dim = 3 + + def fragmented_hypercube(n, d, dim): + assert dim <= d + assert dim >= 1 + assert dim == int(dim) + + a = (1. / n) * np.ones(n) + b = (1. / n) * np.ones(n) + + # First measure : uniform on the hypercube + X = np.random.uniform(-1, 1, size=(n, d)) + + # Second measure : fragmentation + tmp_y = np.random.uniform(-1, 1, size=(n, d)) + Y = tmp_y + 2 * np.sign(tmp_y) * np.array(dim * [1] + (d - dim) * [0]) + return a, b, X, Y + + a, b, X, Y = fragmented_hypercube(n, d, dim) + + tau = 0.002 + reg = 0.2 + + pi, U = ot.dr.projection_robust_wasserstein(X, Y, a, b, tau, reg=reg, k=k, maxiter=1000, verbose=1) + + U0 = np.random.randn(d, k) + U0, _ = np.linalg.qr(U0) + + pi, U = ot.dr.projection_robust_wasserstein(X, Y, a, b, tau, U0=U0, reg=reg, k=k, maxiter=1000, verbose=1) |