Пример #1
0
 def test_kinetic_map(self):
     tica = TICA(lagtime=self.lagtime, dim=None,
                 scaling='kinetic_map').fit(self.data).fetch_model()
     O = tica.transform(self.data)
     vars = np.var(O, axis=0)
     refs = tica.eigenvalues**2
     assert np.max(np.abs(vars - refs)) < 0.01
Пример #2
0
    def test_dimension(self):
        assert self.model_unscaled.output_dimension == 1
        assert self.model_nonrev.output_dimension == 1
        # Test other variants
        model = TICA(lagtime=self.lagtime,
                     dim=1.0).fit(self.data).fetch_model()
        assert model.output_dimension == 2
        model = TICA(lagtime=self.lagtime, dim=.9).fit(self.data).fetch_model()
        assert model.output_dimension == 1

        invalid_dims = [0, 0.0, 1.1, -1]
        for invalid_dim in invalid_dims:
            with self.assertRaises(ValueError):
                TICA(lagtime=self.lagtime, dim=invalid_dim)
Пример #3
0
    def setUpClass(cls):
        test_data = generate_hmm_test_data()
        cls.lagtime = test_data['lagtime']
        cls.cov_ref_00 = test_data['cov_ref_00']
        cls.cov_ref_00_nr = test_data['cov_ref_00_nr']
        cls.cov_ref_0t = test_data['cov_ref_0t']
        cls.cov_ref_0t_nr = test_data['cov_ref_0t_nr']
        cls.data = test_data['data']

        # perform unscaled TICA
        cls.model_unscaled = TICA(lagtime=cls.lagtime, dim=1,
                                  scaling=None).fit(cls.data).fetch_model()
        cls.transformed_data_unscaled = cls.model_unscaled.transform(cls.data)

        # non-reversible TICA
        cls.model_nonrev = TICA(lagtime=cls.lagtime, dim=1, scaling=None, reversible=False).fit(cls.data) \
            .fetch_model()
        cls.transformed_data_nonrev = cls.model_nonrev.transform(cls.data)
Пример #4
0
 def test_constant_features(self):
     z = np.zeros((100, 10))
     o = np.ones((100, 10))
     z_lagged = (z[:-10], z[10:])
     o_lagged = (o[:-10], o[10:])
     tica_obj = TICA(lagtime=1)
     model = tica_obj.partial_fit(z_lagged).fetch_model()
     with self.assertRaises(ZeroRankError):
         _ = model.timescales(lagtime=1)
     with self.assertRaises(ZeroRankError):
         tica_obj.transform(z)
     model = tica_obj.partial_fit(o_lagged).fetch_model()
     try:
         _ = model.timescales(lagtime=1)
         tica_obj.transform(z)
     except ZeroRankError:
         self.fail('ZeroRankError was raised unexpectedly.')
Пример #5
0
    def test_fit_reset(self):
        chunk = 40
        lag = 100
        np.random.seed(0)
        data = np.random.randn(23000, 3)

        est = TICA(lagtime=lag, dim=1)
        for X, Y in timeshifted_split(data, lagtime=lag, chunksize=chunk):
            est.partial_fit((X, Y))
        model1 = est.fetch_model().copy()
        # ------- run again with new chunksize -------
        est.fit(data)
        model2 = est.fetch_model().copy()

        assert model1 != model2
        np.testing.assert_array_almost_equal(model1.mean_0, model2.mean_0)
        np.testing.assert_array_almost_equal(model1.cov_00, model2.cov_00)
        np.testing.assert_array_almost_equal(model1.cov_0t, model2.cov_0t)
Пример #6
0
 def tica(data, lag, weights=None, **params):
     from sktime.decomposition.tica import TICA
     t = TICA(lagtime=lag, **params)
     t.fit(data, weights=weights)
     return t.fetch_model()