summaryrefslogtreecommitdiff
path: root/test/test_dr.py
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2017-07-24 15:14:59 +0200
committerRémi Flamary <remi.flamary@gmail.com>2017-07-24 15:14:59 +0200
commit709d8cbc9f9961a5175eb64ae497b854e0b9b184 (patch)
tree4be68b8291433c23972831000020832ccf440d3c /test/test_dr.py
parent7d9c5e7ef81cfb1cd4725058c09a7f683ca03eef (diff)
add dr tests
Diffstat (limited to 'test/test_dr.py')
-rw-r--r--test/test_dr.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/test_dr.py b/test/test_dr.py
new file mode 100644
index 0000000..24ccaa1
--- /dev/null
+++ b/test/test_dr.py
@@ -0,0 +1,63 @@
+import ot
+import numpy as np
+import pytest
+
+try: # test if cudamat installed
+ import ot.dr
+ nogo = False
+except ImportError:
+ nogo = True
+
+
+@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)")
+def test_fda():
+
+ n = 100 # nb samples in source and target datasets
+ nz = 0.2
+ np.random.seed(0)
+
+ # generate circle dataset
+ t = np.random.rand(n) * 2 * np.pi
+ ys = np.floor((np.arange(n) * 1.0 / n * 3)) + 1
+ xs = np.concatenate(
+ (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1)
+ xs = xs * ys.reshape(-1, 1) + nz * np.random.randn(n, 2)
+
+ nbnoise = 8
+
+ xs = np.hstack((xs, np.random.randn(n, nbnoise)))
+
+ p = 2
+
+ Pfda, projfda = ot.dr.fda(xs, ys, p)
+
+ projfda(xs)
+
+ assert np.allclose(np.sum(Pfda**2, 0), np.ones(p))
+
+
+@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)")
+def test_wda():
+
+ n = 100 # nb samples in source and target datasets
+ nz = 0.2
+ np.random.seed(0)
+
+ # generate circle dataset
+ t = np.random.rand(n) * 2 * np.pi
+ ys = np.floor((np.arange(n) * 1.0 / n * 3)) + 1
+ xs = np.concatenate(
+ (np.cos(t).reshape((-1, 1)), np.sin(t).reshape((-1, 1))), 1)
+ xs = xs * ys.reshape(-1, 1) + nz * np.random.randn(n, 2)
+
+ nbnoise = 8
+
+ xs = np.hstack((xs, np.random.randn(n, nbnoise)))
+
+ p = 2
+
+ Pwda, projwda = ot.dr.wda(xs, ys, p, maxiter=10)
+
+ projwda(xs)
+
+ assert np.allclose(np.sum(Pwda**2, 0), np.ones(p))