diff --git a/pyemma/coordinates/tests/test_nystroem_tica.py b/pyemma/coordinates/tests/test_nystroem_tica.py index 4b9566baf..9e92eed0d 100644 --- a/pyemma/coordinates/tests/test_nystroem_tica.py +++ b/pyemma/coordinates/tests/test_nystroem_tica.py @@ -75,7 +75,7 @@ class TestNystroemTICA_DoubleWell(unittest.TestCase): def setUpClass(cls): from pyemma.datasets import load_2well_discrete dw = load_2well_discrete() - v = dw.dtraj_T100K_dt10[:10000] + v = dw.dtraj[:10000] cls.T = v.size nstates = 100 b = np.linspace(-1, 1, nstates) diff --git a/pyemma/datasets/double_well_discrete.npz b/pyemma/datasets/double_well_discrete.npz deleted file mode 100644 index eba9753e6..000000000 Binary files a/pyemma/datasets/double_well_discrete.npz and /dev/null differ diff --git a/pyemma/datasets/double_well_discrete.py b/pyemma/datasets/double_well_discrete.py index 80d24b3d9..f8c76633c 100644 --- a/pyemma/datasets/double_well_discrete.py +++ b/pyemma/datasets/double_well_discrete.py @@ -20,21 +20,20 @@ import numpy as np from deeptime.markov.msm import MarkovStateModel +from deeptime.data import DoubleWellDiscrete from pyemma.msm import markov_model -class DoubleWell_Discrete_Data(object): +class DoubleWell_Discrete_Data(DoubleWellDiscrete): """ MCMC process in a symmetric double well potential, spatially discretized to 100 bins """ def __init__(self): - from pkg_resources import resource_filename - filename = resource_filename('pyemma.datasets', 'double_well_discrete.npz') - datafile = np.load(filename) - self._dtraj_T100K_dt10 = datafile['dtraj'] - self._P = datafile['P'] + super().__init__() + self._dtraj_T100K_dt10 = self.dtraj[:] + self._P = self.transition_matrix self._msm_dt = MarkovStateModel(self._P) self._msm = markov_model(self._P) @@ -70,11 +69,6 @@ def dtraj_T100K_dt10_n(self, divides): disc[divides[i]:divides[i + 1]] = i + 1 return disc[self.dtraj_T100K_dt10] - @property - def transition_matrix(self): - """ Exact transition matrix used to generate the data """ - return self._P - @property def msm(self): """ Returns an MSM object with the exact transition matrix """ diff --git a/pyemma/msm/tests/test_amm.py b/pyemma/msm/tests/test_amm.py index cd7364e41..eb94bd4ca 100644 --- a/pyemma/msm/tests/test_amm.py +++ b/pyemma/msm/tests/test_amm.py @@ -94,7 +94,7 @@ class TestAMMDoubleWell(_tmsm): @classmethod def setUpClass(cls): import pyemma.datasets - cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj cls.E_ = np.linspace(0.01, 2.*np.pi, 66).reshape(-1,1)**(0.5) cls.m = np.array([1.9]) cls.w = np.array([2.0]) @@ -381,7 +381,7 @@ class TestCoreAMMDoubleWell(_ctmsm): def setUpClass(cls): import pyemma.datasets cls.core_set = [34, 65] - cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj cls.E_ = np.linspace(0.01, 2.*np.pi, 66).reshape(-1,1)**(0.5) cls.m = np.array([1.9]) cls.w = np.array([2.0]) diff --git a/pyemma/msm/tests/test_bayesian_hmsm.py b/pyemma/msm/tests/test_bayesian_hmsm.py index 0599f5c0c..dbb742505 100644 --- a/pyemma/msm/tests/test_bayesian_hmsm.py +++ b/pyemma/msm/tests/test_bayesian_hmsm.py @@ -19,6 +19,7 @@ import unittest import numpy as np from deeptime.markov.tools.analysis import is_transition_matrix, is_reversible +from numpy.testing import assert_allclose from pyemma.msm import bayesian_hidden_markov_model @@ -29,7 +30,7 @@ class TestBHMM(unittest.TestCase): def setUpClass(cls): # load observations import pyemma.datasets - obs = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + obs = pyemma.datasets.load_2well_discrete().dtraj # hidden states cls.nstates = 2 @@ -331,9 +332,9 @@ def test_separate_states(self): np.array([2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2]),] hmm_bayes = bayesian_hidden_markov_model(dtrajs, 3, lag=1, separate=[0], nsamples=100, store_hidden=True) # we expect zeros in all samples at the following indexes: - pobs_zeros = [[0, 1, 2, 2, 2], [0, 0, 1, 2, 3]] - for s in hmm_bayes.samples: - assert np.allclose(s.observation_probabilities[pobs_zeros], 0) + pobs_zeros = ((0, 1, 2, 2, 2), (0, 0, 1, 2, 3)) + for i, s in enumerate(hmm_bayes.samples): + assert_allclose(s.observation_probabilities[pobs_zeros], 0, err_msg=f"{i}") for strajs in hmm_bayes.sampled_trajs: assert strajs[0][0] == 2 assert strajs[0][6] == 2 @@ -342,7 +343,7 @@ def test_initialized_bhmm(self): import pyemma.datasets as d import pyemma.msm - obs = d.load_2well_discrete().dtraj_T100K_dt10 + obs = d.load_2well_discrete().dtraj init_hmm = pyemma.msm.estimate_hidden_markov_model(obs, 2, 10) bay_hmm = pyemma.msm.estimators.BayesianHMSM(nstates=init_hmm.nstates, lag=init_hmm.lag, diff --git a/pyemma/msm/tests/test_bayesian_msm.py b/pyemma/msm/tests/test_bayesian_msm.py index 485a0aefb..a134f0398 100644 --- a/pyemma/msm/tests/test_bayesian_msm.py +++ b/pyemma/msm/tests/test_bayesian_msm.py @@ -30,7 +30,7 @@ def setUpClass(cls): # load observations import pyemma.datasets data = pyemma.datasets.load_2well_discrete() - obs_micro = data.dtraj_T100K_dt10 + obs_micro = data.dtraj # stationary distribution pi_micro = data.msm.stationary_distribution diff --git a/pyemma/msm/tests/test_cktest.py b/pyemma/msm/tests/test_cktest.py index 87cf912cf..213949820 100644 --- a/pyemma/msm/tests/test_cktest.py +++ b/pyemma/msm/tests/test_cktest.py @@ -155,7 +155,7 @@ def tearDown(self): assert hasattr(restored, 'has_errors') def test_ck_msm(self): - MLMSM = msm.estimate_markov_model([self.double_well_data.dtraj_T100K_dt10_n6good], 40) + MLMSM = msm.estimate_markov_model([self.double_well_data.dtraj_n6good], 40) self.ck = MLMSM.cktest(2, mlags=[0, 1, 10], n_jobs=1) estref = np.array([[[1., 0.], [0., 1.]], @@ -178,7 +178,7 @@ def test_ck_msm(self): assert self.ck.predictions_conf[1] is None def test_its_bmsm(self): - BMSM = msm.bayesian_markov_model([self.double_well_data.dtraj_T100K_dt10_n6good], 40, reversible=True) + BMSM = msm.bayesian_markov_model([self.double_well_data.dtraj_n6good], 40, reversible=True) # also ensure that reversible bit does not flip during cktest assert BMSM.reversible self.ck = BMSM.cktest(2, mlags=[0, 1, 10], n_jobs=1) @@ -216,7 +216,7 @@ def test_its_bmsm(self): assert np.allclose(self.ck.predictions[1], predRref, rtol=0.1, atol=10.0) def test_its_hmsm(self): - MLHMM = msm.estimate_hidden_markov_model([self.double_well_data.dtraj_T100K_dt10_n6good], 2, 10) + MLHMM = msm.estimate_hidden_markov_model([self.double_well_data.dtraj_n6good], 2, 10) self.ck = MLHMM.cktest(mlags=[0, 1, 10], n_jobs=1) estref = np.array([[[1., 0.], [0., 1.]], @@ -239,7 +239,7 @@ def test_its_hmsm(self): assert self.ck.predictions_conf[1] is None def test_its_bhmm(self): - BHMM = msm.bayesian_hidden_markov_model([self.double_well_data.dtraj_T100K_dt10_n6good], 2, 10) + BHMM = msm.bayesian_hidden_markov_model([self.double_well_data.dtraj_n6good], 2, 10) self.ck = BHMM.cktest(mlags=[0, 1, 10], n_jobs=1) estref = np.array([[[1., 0.], [0., 1.]], diff --git a/pyemma/msm/tests/test_cmsm.py b/pyemma/msm/tests/test_cmsm.py index 8443ba9bc..1ff62d57f 100644 --- a/pyemma/msm/tests/test_cmsm.py +++ b/pyemma/msm/tests/test_cmsm.py @@ -66,7 +66,7 @@ def setUpClass(cls): import pyemma.datasets cls.core_set = [34, 65] - cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj nu = 1.*np.bincount(cls.dtraj)[cls.core_set] cls.statdist = nu/nu.sum() @@ -698,7 +698,7 @@ class TestCoreMSM(unittest.TestCase): @classmethod def setUpClass(cls): from pyemma import datasets - cls.dtraj = datasets.load_2well_discrete().dtraj_T100K_dt10 + cls.dtraj = datasets.load_2well_discrete().dtraj def test_core(self): core_set = [15, 16, 17, 45, 46, 47] diff --git a/pyemma/msm/tests/test_hmsm.py b/pyemma/msm/tests/test_hmsm.py index e7447c2c2..7c8691bd8 100644 --- a/pyemma/msm/tests/test_hmsm.py +++ b/pyemma/msm/tests/test_hmsm.py @@ -35,7 +35,7 @@ class TestMLHMM(unittest.TestCase): def setUpClass(cls): # load observations import pyemma.datasets - obs = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + obs = pyemma.datasets.load_2well_discrete().dtraj.copy() obs -= np.min(obs) # remove empty states # hidden states @@ -465,7 +465,7 @@ def test_separate_states(self): np.array([2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2]),] hmm = msm.estimate_hidden_markov_model(dtrajs, 3, lag=1, separate=[0]) # we expect zeros in all samples at the following indexes: - pobs_zeros = [[0, 1, 2, 2, 2], [0, 0, 1, 2, 3]] + pobs_zeros = ((0, 1, 2, 2, 2), (0, 0, 1, 2, 3)) assert np.allclose(hmm.observation_probabilities[pobs_zeros], 0) if __name__=="__main__": diff --git a/pyemma/msm/tests/test_its.py b/pyemma/msm/tests/test_its.py index 5a06c9a92..54745001d 100644 --- a/pyemma/msm/tests/test_its.py +++ b/pyemma/msm/tests/test_its.py @@ -303,7 +303,7 @@ def test_its_cmsm_defined_core(self): core_set = [0, 5] estimator = msm.estimators.MaximumLikelihoodMSM(core_set=core_set) its = msm.ImpliedTimescales(estimator, lags=[1, 10, 100, 1000], n_jobs=1) - its.estimate([self.double_well_data.dtraj_T100K_dt10_n6good]) + its.estimate([self.double_well_data.dtraj_n6good]) assert its.models[0].n_cores == 2 ref = np.array([[339.22244263], [334.56862305], diff --git a/pyemma/msm/tests/test_msm.py b/pyemma/msm/tests/test_msm.py index c493cdc75..5014c2515 100644 --- a/pyemma/msm/tests/test_msm.py +++ b/pyemma/msm/tests/test_msm.py @@ -150,7 +150,7 @@ class TestMSMDoubleWell(unittest.TestCase): @classmethod def setUpClass(cls): import pyemma.datasets - cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + cls.dtraj = pyemma.datasets.load_2well_discrete().dtraj nu = 1.*np.bincount(cls.dtraj) cls.statdist = nu/nu.sum() diff --git a/pyemma/msm/tests/test_msm_serialization.py b/pyemma/msm/tests/test_msm_serialization.py index 55a00ee08..6cf7102de 100644 --- a/pyemma/msm/tests/test_msm_serialization.py +++ b/pyemma/msm/tests/test_msm_serialization.py @@ -30,7 +30,7 @@ class TestMSMSerialization(unittest.TestCase): @classmethod def setUpClass(cls): data = datasets.load_2well_discrete() - cls.obs_micro = data.dtraj_T100K_dt10 + cls.obs_micro = data.dtraj # coarse-grain microstates to two metastable states cg = np.zeros(100, dtype=int) diff --git a/pyemma/msm/tests/test_oom_msm.py b/pyemma/msm/tests/test_oom_msm.py index 26114d2f7..fce892aa3 100644 --- a/pyemma/msm/tests/test_oom_msm.py +++ b/pyemma/msm/tests/test_oom_msm.py @@ -1291,11 +1291,11 @@ def _timescales(self, msm): ts_ref = self.rmsmrev.timescales() assert (np.all(np.isreal(ts))) # HERE: - np.testing.assert_almost_equal(ts, self.tau*ts_ref, decimal=2) + np.testing.assert_almost_equal(ts, self.tau*ts_ref, decimal=1) else: ts_ref = self.rmsm.timescales() # HERE: - np.testing.assert_almost_equal(ts, self.tau*ts_ref, decimal=2) + np.testing.assert_almost_equal(ts, self.tau*ts_ref, decimal=1) def test_timescales(self): self._timescales(self.msmrev) diff --git a/pyemma/util/tests/test_discrete_trajectories.py b/pyemma/util/tests/test_discrete_trajectories.py index a6a7e6bcd..a7f0ead77 100644 --- a/pyemma/util/tests/test_discrete_trajectories.py +++ b/pyemma/util/tests/test_discrete_trajectories.py @@ -114,7 +114,7 @@ def test_count_3(self): def test_count_big(self): import pyemma.datasets - dtraj = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + dtraj = pyemma.datasets.load_2well_discrete().dtraj dt.number_of_states(dtraj) dt.count_states(dtraj) @@ -159,7 +159,7 @@ def test_twotraj(self): def test_big(self): import pyemma.datasets - dtraj = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10 + dtraj = pyemma.datasets.load_2well_discrete().dtraj # just run these to see if there's any exception dt.index_states(dtraj)