summaryrefslogtreecommitdiff
path: root/test/test_dr.py
diff options
context:
space:
mode:
authorGard Spreemann <gspr@nonempty.org>2020-01-20 14:07:53 +0100
committerGard Spreemann <gspr@nonempty.org>2020-01-20 14:07:53 +0100
commitbdfb24ff37ea777d6e266b145047cd4e281ebac3 (patch)
tree00cbac5f3dc25a4ee76164828abd72c1cbab37cc /test/test_dr.py
parentabc441b00f0fe2fa4ef0efc4e1aa67b27cca9a13 (diff)
parent5e70a77fbb2feec513f21c9ef65dcc535329ace6 (diff)
Merge tag '0.6.0' into debian/sid
Diffstat (limited to 'test/test_dr.py')
-rw-r--r--test/test_dr.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/test_dr.py b/test/test_dr.py
new file mode 100644
index 0000000..c5df287
--- /dev/null
+++ b/test/test_dr.py
@@ -0,0 +1,59 @@
+"""Tests for module dr on Dimensionality Reduction """
+
+# Author: Remi Flamary <remi.flamary@unice.fr>
+#
+# License: MIT License
+
+import numpy as np
+import ot
+import pytest
+
+try: # test if autograd and pymanopt are installed
+ import ot.dr
+ nogo = False
+except ImportError:
+ nogo = True
+
+
+@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)")
+def test_fda():
+
+ n_samples = 90 # nb samples in source and target datasets
+ np.random.seed(0)
+
+ # generate gaussian dataset
+ xs, ys = ot.datasets.make_data_classif('gaussrot', n_samples)
+
+ n_features_noise = 8
+
+ xs = np.hstack((xs, np.random.randn(n_samples, n_features_noise)))
+
+ p = 1
+
+ Pfda, projfda = ot.dr.fda(xs, ys, p)
+
+ projfda(xs)
+
+ np.testing.assert_allclose(np.sum(Pfda**2, 0), np.ones(p))
+
+
+@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)")
+def test_wda():
+
+ n_samples = 100 # nb samples in source and target datasets
+ np.random.seed(0)
+
+ # generate gaussian dataset
+ xs, ys = ot.datasets.make_data_classif('gaussrot', n_samples)
+
+ n_features_noise = 8
+
+ xs = np.hstack((xs, np.random.randn(n_samples, n_features_noise)))
+
+ p = 2
+
+ Pwda, projwda = ot.dr.wda(xs, ys, p, maxiter=10)
+
+ projwda(xs)
+
+ np.testing.assert_allclose(np.sum(Pwda**2, 0), np.ones(p))