Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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