def cvs_to_tica(cv_coordinates, drop): from deeptime.decomposition import TICA data = [] cvs = list([i for i in range(cv_coordinates.shape[2]) if i not in drop]) for i in range(cv_coordinates.shape[0]): data.append(cv_coordinates[i, :, cvs].T) tica = TICA(lagtime=1) data = tica.fit(data, lagtime=1, progress=True).fetch_model().transform(data) return data
def test_mlmsm_pipeline(self): file = mdshare.fetch('hmm-doublewell-2d-100k.npz', working_directory='data') with np.load(file) as fh: data = fh['trajectory'] transition_matrix = fh['transition_matrix'] pipeline = Pipeline(steps=[ ('tica', TICA(dim=1, lagtime=1)), ('cluster', KMeans(n_clusters=2, max_iter=500)), ('counts', TransitionCountEstimator(lagtime=1, count_mode="sliding")) ]) pipeline.fit(data) counts = pipeline[-1].fetch_model().submodel_largest() mlmsm = MaximumLikelihoodMSM().fit(counts).fetch_model() P = mlmsm.pcca(2).coarse_grained_transition_matrix mindist = min(np.linalg.norm(P - transition_matrix), np.linalg.norm(P - transition_matrix.T)) assert mindist < 0.05
def test_mlmsm_pipeline(self): hmm = HiddenMarkovModel(transition_model=MarkovStateModel([[.8, .2], [.1, .9]]), output_model=GaussianOutputModel( n_states=2, means=[-10, 10], sigmas=[.1, .1])) htraj, traj = hmm.simulate(10000) transition_matrix = hmm.transition_model.transition_matrix pipeline = Pipeline(steps=[( 'tica', TICA(dim=1, lagtime=1) ), ( 'cluster', KMeans(n_clusters=2, max_iter=500) ), ('counts', TransitionCountEstimator(lagtime=1, count_mode="sliding"))]) pipeline.fit(traj[..., None]) counts = pipeline[-1].fetch_model().submodel_largest() mlmsm = MaximumLikelihoodMSM().fit(counts).fetch_model() P = mlmsm.pcca(2).coarse_grained_transition_matrix mindist = min(np.linalg.norm(P - transition_matrix), np.linalg.norm(P - transition_matrix.T)) assert mindist < 0.05
def tica(data, lag, weights=None, **params): from deeptime.decomposition import TICA return TICA(var_cutoff=0.95, lagtime=lag, **params).fit_from_timeseries( data, weights=weights).fetch_model()
ax.set_title(title) ax.set_aspect('equal') ax.set_xlabel('x') ax.set_ylabel('y') data = ellipsoids(seed=17) discrete_trajectory = data.discrete_trajectory(n_steps=1000) feature_trajectory = data.map_discrete_to_observations(discrete_trajectory) vamp = VAMP(dim=1, lagtime=1) vamp = vamp.fit(feature_trajectory).fetch_model() vamp_projection = vamp.transform(feature_trajectory) dxy_vamp = vamp.singular_vectors_left[:, 0] # dominant vamp component tica = TICA(dim=1, lagtime=1) tica = tica.fit(feature_trajectory).fetch_model() tica_projection = tica.transform(feature_trajectory) dxy_tica = tica.singular_vectors_left[:, 0] # dominant tica component pca = PCA(n_components=1) pca.fit(feature_trajectory) pca_projection = pca.transform(feature_trajectory) dxy_pca = pca.components_[0] # dominant pca component f = plt.figure(constrained_layout=False, figsize=(14, 14)) gs = f.add_gridspec(nrows=2, ncols=3) ax_projections = f.add_subplot(gs[0, :]) ax_tica = f.add_subplot(gs[1, 0]) ax_vamp = f.add_subplot(gs[1, 1]) ax_pca = f.add_subplot(gs[1, 2])