Esempio n. 1
0
 def test_spectral_oasis_multiple(self):
     oasis = oASIS_Nystroem(self.d, self.C0_k, self.initial_columns)
     oasis.set_selection_strategy(strategy='spectral-oasis', nsel=5)
     newcols = oasis.select_columns()
     c = self.C0[:, newcols]
     assert np.all(np.equal(oasis.add_columns(c, newcols), newcols))
     assert oasis.select_columns() is None
     np.testing.assert_allclose(oasis.error, 0, rtol=1e-08, atol=1e-10)
Esempio n. 2
0
 def _test_oasis_single(self, strategy):
     oasis = oASIS_Nystroem(self.d, self.C0_k, self.initial_columns)
     oasis.set_selection_strategy(strategy=strategy, nsel=1)
     for _ in range(5):
         newcol = oasis.select_columns()
         c = self.C0[:, newcol]
         assert oasis.add_columns(c, newcol) == newcol
     assert oasis.select_columns() is None
     np.testing.assert_allclose(oasis.error, 0, rtol=1e-08, atol=1e-10)
     return oasis
Esempio n. 3
0
 def test_initial_zero(self):
     X = np.zeros((3, 3))
     X[:, 2:3] = np.ones((3, 1))
     C0 = np.dot(X.T, X)
     initial_columns = np.array([0, 1])
     oasis = oASIS_Nystroem(np.diag(C0), C0[:, initial_columns],
                            initial_columns)
     np.testing.assert_allclose(np.abs(oasis.error), np.array([0, 0, 3]))
     np.testing.assert_allclose(oasis.approximate_matrix(), np.zeros(
         (3, 3)))
     for strategy in ['random', 'oasis', 'spectral-oasis']:
         oasis.set_selection_strategy(strategy=strategy, nsel=1)
         assert oasis.select_columns() == np.array([2])
Esempio n. 4
0
 def test_constant_evec(self):
     U = np.vstack([
         1 + np.random.randn(1, 4) * 1e-6,
         np.array([1, -1, 0, 0]),
         np.array([0, 0, 1, -1])
     ]).T
     M = np.dot(U, np.dot(np.diag([1, 0.95, 0.7]), U.T))
     oasis = oASIS_Nystroem(np.diag(M), M[:, 0:2], np.array([0, 1]))
     from pyemma.coordinates.transform.nystroem_tica import SelectionStrategySpectralOasis
     sel = SelectionStrategySpectralOasis(oasis, strategy='spectral-oasis')
     evecs = oasis.approximate_eig()[1]
     fixed_evecs = sel._fix_constant_evec(evecs)
     assert np.all(fixed_evecs[:, 0] == 1)
     assert evecs.shape == fixed_evecs.shape
Esempio n. 5
0
 def test_random(self):
     oasis = oASIS_Nystroem(self.d, self.C0_k, self.initial_columns)
     oasis.set_selection_strategy(strategy='random', nsel=1)
     while oasis.k < 6:
         newcol = oasis.select_columns()
         c = self.C0[:, newcol]
         added_columns = oasis.add_columns(c, newcol)
         assert ((len(added_columns) > 0
                  and np.any(np.in1d(self.variable_columns, added_columns)))
                 or
                 (len(added_columns) == 0
                  and not np.all(np.in1d(self.variable_columns, newcol))))
     assert oasis.select_columns() is None
     np.testing.assert_allclose(oasis.error, 0, rtol=1e-08, atol=1e-10)