diff options
author | Antoine Rolet <antoine.rolet@gmail.com> | 2017-09-05 15:30:50 +0900 |
---|---|---|
committer | Antoine Rolet <antoine.rolet@gmail.com> | 2017-09-05 15:30:50 +0900 |
commit | 13dfb3ddbbd8926b4751b82dd41c5570253b1f07 (patch) | |
tree | b28098e98640c64483a599103e2fdb5df46d2c79 /test/test_dr.py | |
parent | 185eb3e2ef34b5ce6b8f90a28a5bcc78432b7fd3 (diff) | |
parent | 16697047eff9326a0ecb483317c13a854a3d3a71 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'test/test_dr.py')
-rw-r--r-- | test/test_dr.py | 59 |
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..915012d --- /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.get_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.get_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)) |