def get_ergodic_set(dtrajs, tau): m = MaximumLikelihoodMSM(lag=tau, connectivity='largest', reversible=True) m.fit(dtrajs) erg_dtrajs = [x for x in m.dtrajs_active if not -1 in x] m = MaximumLikelihoodMSM(lag=tau, connectivity='largest', reversible=True) m.fit(erg_dtrajs) assert m.active_count_fraction == 1.0, 'Active count fraction not 1' return erg_dtrajs
def test_score_cv(self): self._score_cv(MaximumLikelihoodMSM(lag=10, reversible=True)) self._score_cv(MaximumLikelihoodMSM(lag=10, reversible=True, statdist_constraint=self.statdist)) self._score_cv(MaximumLikelihoodMSM(lag=10, reversible=False)) self._score_cv(MaximumLikelihoodMSM(lag=10, reversible=True, sparse=True)) self._score_cv(MaximumLikelihoodMSM(lag=10, reversible=True, statdist_constraint=self.statdist, sparse=True)) self._score_cv(MaximumLikelihoodMSM(lag=10, reversible=False, sparse=True))
def setUpClass(cls): P = np.array([[0.5, .25, .25, 0.], [0., .25, .5, .25], [.25, .25, .5, 0], [.25, .25, .25, .25], ]) # bogus its object lags = [1, 2, 3, 5, 10] dtraj = generate_traj(P, 1000) estimator = MaximumLikelihoodMSM(dt_traj='10 ps') cls.its = ImpliedTimescales(estimator=estimator) cls.its.estimate(dtraj, lags=lags) cls.refs = cls.its.timescales[-1] return cls
def setUpClass(cls): P = np.array([ [0.5, .25, .25, 0.], [0., .25, .5, .25], [.25, .25, .5, 0], [.25, .25, .25, .25], ]) # bogus its object lags = [1, 2, 3, 5, 10] cls.dtraj = MarkovStateModel(P).simulate(1000) cls.estimator = MaximumLikelihoodMSM(dt_traj='10 ps') cls.its = ImpliedTimescales(estimator=cls.estimator, n_jobs=1) cls.its.estimate(cls.dtraj, lags=lags) cls.refs = cls.its.timescales[-1] return cls
from pyemma.msm import MaximumLikelihoodMSM from pyemma.coordinates.util import DtrajReshape from msmbuilder.cluster import NDGrid from sklearn.pipeline import Pipeline import pickle from glob import glob import numpy as np # traj_paths = glob('data/000.5pc/*.npy') # X = [np.load(traj_path) for traj_path in traj_paths] xmin, xmax = -1.2, 1.2 tau = 1 model = Pipeline([('cluster',NDGrid(min=xmin, max=xmax, n_bins_per_feature=200)), ('msm', MaximumLikelihoodMSM(lag=1, score_method='vamp1'))]) pickle.dump(model, open('model_lag1.pickl', 'wb'))
results = { 'tau': [], 'k': [], 'bic': [], 'aic': [], 'icl': [], 'entropy': [], 'n_obs': [], 'dofs': [] } print('tau = ', tau) for k in [ks[-1]]: print('\tk = ', k) m = MaximumLikelihoodMSM(lag=tau, connectivity='largest', reversible=True) m.fit(erg_dtrajs) assert m.active_count_fraction == 1.0, 'Active count fraction not 1.0' print('\tFitting HMM') hmm = estimate_hidden_markov_model(dtrajs=erg_dtrajs, nstates=int(k), lag=tau, stationary=False, reversible=True, connectivity='largest') #hmm = MaximumLikelihoodHMSM(nstates=int(k), lag=tau, stationary=False, reversible=True, connectivity='largest', msm_init=m) #hmm.fit(erg_dtrajs[:2])