def setUpClass(cls) -> None: dtraj = DoubleWellDiscrete().dtraj initial_hmm_10 = init.discrete.metastable_from_data(dtraj, n_hidden_states=2, lagtime=10) cls.hmm_lag10 = MaximumLikelihoodHMM(initial_hmm_10, lagtime=10).fit(dtraj).fetch_model() cls.hmm_lag10_largest = cls.hmm_lag10.submodel_largest(dtrajs=dtraj) cls.msm_lag10 = estimate_markov_model(dtraj, 10, reversible=True) initial_hmm_1 = init.discrete.metastable_from_data(dtraj, n_hidden_states=2, lagtime=1) cls.hmm_lag1 = MaximumLikelihoodHMM(initial_hmm_1).fit(dtraj).fetch_model() cls.hmm_lag1_largest = cls.hmm_lag1.submodel_largest(dtrajs=dtraj) cls.msm_lag1 = estimate_markov_model(dtraj, 1, reversible=True) cls.dtrajs = dtraj
def test_score_vs_MSM(self): trajs_test, trajs_train = cvsplit_dtrajs(self.trajs, random_state=32) dtrajs_test, dtrajs_train = cvsplit_dtrajs(self.dtrajs, random_state=32) methods = ('VAMP1', 'VAMP2', 'VAMPE') for m in methods: msm_train = estimate_markov_model(dtrajs=dtrajs_train, lag=self.lag, reversible=False) score_msm = msm_train.score(dtrajs_test, score_method=m, score_k=None) vamp_train = VAMP( lagtime=self.lag, var_cutoff=1.0).fit_from_timeseries(trajs_train).fetch_model() vamp_test = VAMP( lagtime=self.lag, var_cutoff=1.0).fit_from_timeseries(trajs_test).fetch_model() score_vamp = vamp_train.score(test_model=vamp_test, score_method=m) self.assertAlmostEqual(score_msm, score_vamp, places=2 if m == 'VAMPE' else 3, msg=m)
def setUpClass(cls): N_steps = 10000 N_traj = 20 lag = 1 T = np.linalg.matrix_power( np.array([[0.7, 0.2, 0.1], [0.1, 0.8, 0.1], [0.1, 0.1, 0.8]]), lag) dtrajs = [generate(T, N_steps) for _ in range(N_traj)] p0 = np.zeros(3) p1 = np.zeros(3) trajs = [] for dtraj in dtrajs: traj = np.zeros((N_steps, T.shape[0])) traj[np.arange(len(dtraj)), dtraj] = 1.0 trajs.append(traj) p0 += traj[:-lag, :].sum(axis=0) p1 += traj[lag:, :].sum(axis=0) estimator = VAMP(scaling=None, var_cutoff=1.0) cov = VAMP.covariance_estimator(lagtime=lag).fit(trajs).fetch_model() vamp = estimator.fit(cov).fetch_model() msm = estimate_markov_model(dtrajs, lag=lag, reversible=False) cls.trajs = trajs cls.dtrajs = dtrajs cls.trajs_timeshifted = list( timeshifted_split(cls.trajs, lagtime=lag, chunksize=5000)) cls.lag = lag cls.msm = msm cls.vamp = vamp cls.estimator = estimator cls.p0 = p0 / p0.sum() cls.p1 = p1 / p1.sum() cls.atol = np.finfo(np.float32).eps * 1000.0