def test_2_parallel(self): t2 = timescales(self.P2)[1] lags = [1, 2, 3, 4, 5] its = timescales_msm([self.dtraj2], lags=lags, n_jobs=2) est = its.timescales[0] np.testing.assert_array_less(est, t2 + 2.0) np.testing.assert_array_less(t2 - 2.0, est)
def test_insert_remove_lag_time(self): # test insert and removal at the same time lags = [1, 3, 5] its = timescales_msm(self.dtraj4_2, lags=lags, errors='bayes', nsamples=10, show_progress=False) new_lags = lags + [6, 7, 8] new_lags = new_lags[2:] new_lags += [21, 22] # omit the first lag new_lags = new_lags[1:] its.estimate(self.dtraj4_2, lags=new_lags) its_one_shot = timescales_msm(self.dtraj4_2, lags=new_lags) np.testing.assert_allclose(its.timescales, its_one_shot.timescales)
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 pyerna.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) assert log_handler.messages['warning'] 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
def test_no_return_estimators(self): lags = [1, 2, 3, 10, 20] nstates = 10 nits = 3 its = timescales_msm(dtrajs=np.random.randint(0, nstates, size=1000), lags=lags, only_timescales=True, nits=nits) with self.assertRaises(RuntimeError): its.estimators with self.assertRaises(RuntimeError): its.models assert isinstance(its.timescales, np.ndarray) assert its.timescales.shape == (len(lags), nstates - 1 if nstates == nits else nits)
def test_errors(self): dtraj_disconnected = [-2] * 10 with self.assertRaises(RuntimeError) as e: timescales_msm(dtraj_disconnected, lags=[1, 2, 3, 4, 5]) self.assertIn('elements < -1', e.exception.args[0])