Exemple #1
0
    def test_insert_lag_time(self):
        lags = [1, 3, 5]
        its = timescales_msm(self.dtraj2, lags=lags, errors='bayes', nsamples=10, show_progress=False)
        new_lags = np.concatenate((lags, [2, 4]+list(range(6, 9))), axis=0)
        its.lags = new_lags
        np.testing.assert_equal(its._lags, new_lags)
        its.estimate(self.dtraj2)

        # compare with a one shot estimation
        its_one_shot = timescales_msm(self.dtraj2, lags=new_lags, errors='bayes', nsamples=10, show_progress=False)

        np.testing.assert_equal(its.timescales, its_one_shot.timescales)

        self.assertEqual([m.lag for m in its.models],
                         [m.lag for m in its_one_shot.models])

        # estimate with different data to trigger re-estimation
        from pyemma.util.testing_tools import MockLoggingHandler
        log_handler = MockLoggingHandler()
        its.logger.addHandler(log_handler)
        extended_new_lags = new_lags.tolist()
        extended_new_lags.append(20)
        its.estimate(self.dtraj4_2, lags=extended_new_lags)

        np.testing.assert_equal(its.models[0].dtrajs_full[0], self.dtraj4_2)
        self.assertIn("estimating from new data", log_handler.messages['warning'][0])

        # remove a lag time and ensure the corresponding model is removed too
        new_lags =  new_lags[:-3]
        new_lags_len = len(new_lags)
        its.lags = new_lags
        np.testing.assert_equal(its.lags, new_lags)
        assert len(its.models) == new_lags_len
        assert len(its.timescales) == new_lags_len
        assert len(its.sample_mean) == new_lags_len
Exemple #2
0
    def test_inefficient_args_log(self):
        from pyemma.util.testing_tools import MockLoggingHandler
        m = MockLoggingHandler()
        cl = cluster_kmeans(self.X, max_iter=1, keep_data=False)
        cl.logger.addHandler(m)
        cl.estimate(self.X, max_iter=1, clustercenters=cl.clustercenters)
        found = False
        for msg in m.messages['warning']:
            if 'inefficient' in msg:
                found = True
                break

        assert found
Exemple #3
0
    def test_too_short_traj_partial_fit(self):
        data = [np.empty((20, 3)), np.empty((10, 3))]
        lag = 11
        tica_obj = tica(lag=lag)
        from pyemma.util.testing_tools import MockLoggingHandler
        log_handler = MockLoggingHandler()
        tica_obj._covar.logger.addHandler(log_handler)
        for x in data:
            tica_obj.partial_fit(x)

        self.assertEqual(tica_obj._used_data, 20 - lag)
        self.assertEqual(len(log_handler.messages['warning']), 1)
        self.assertIn("longer than lag", log_handler.messages['warning'][0])
Exemple #4
0
    def test_too_short_traj_partial_fit(self):
        data = [np.empty((20, 3)), np.empty((10, 3))]
        lag = 11
        tica_obj = tica(lag=lag)
        from pyemma.util.testing_tools import MockLoggingHandler
        log_handler = MockLoggingHandler()
        import logging
        L = logging.getLogger('pyemma.coordinates.estimation.covariance')
        L.addHandler(log_handler)
        try:
            for x in data:
                tica_obj.partial_fit(x)

            #self.assertEqual(tica_obj._used_data, 20 - lag)
            self.assertEqual(len(log_handler.messages['warning']), 1)
            self.assertIn("longer than lag",
                          log_handler.messages['warning'][0])
        finally:
            L.removeHandler(log_handler)