def test_from_msm(): assignments, _ = _metastable_system() msm = MarkovStateModel() msm.fit(assignments) pcca = PCCA.from_msm(msm, 2) msm = MarkovStateModel() msm.fit(assignments) pccaplus = PCCAPlus.from_msm(msm, 2)
def test_pcca_1(): assignments, ref_macrostate_assignments = _metastable_system() pipeline = Pipeline([('msm', MarkovStateModel()), ('pcca+', PCCA(2))]) macro_assignments = pipeline.fit_transform(assignments)[0] # we need to consider any permutation of the state labels when we # test for equality. Since it's only a 2-state that's simple using # the logical_not to flip the assignments. assert (np.all(macro_assignments == ref_macrostate_assignments) or np.all( macro_assignments == np.logical_not(ref_macrostate_assignments)))
for this_assign in geo_assign: this_list = [] for this_item in this_assign: try: this_list.append(partial_raw_to_micro_mapping[this_item]) except KeyError: pass partial_micro_assign.append(this_list) unique_assign = [] for this_assign in partial_micro_assign: unique_assign.extend(np.unique(this_assign)) unique_assign = np.unique(np.array(unique_assign)) N_MACRO = 10 pcca = PCCA.from_msm(micro_msm,N_MACRO) micro_to_macro_mapping = {} for ii in range(len(pcca.microstate_mapping_)): micro_to_macro_mapping[ii] = pcca.microstate_mapping_[ii] # for n macrostates, any frame that does not belong to any microstate and thus macrostate is labeled to be in the nth macrostate for ii in range(len(raw_clusters)): if ii in micro_to_macro_mapping.keys(): pass else: micro_to_macro_mapping[ii] = N_MACRO # assignments to macro states macro_assign = [] for this_assign in geo_assign:
for this_assign in geo_assign: this_list = [] for this_item in this_assign: try: this_list.append(partial_raw_to_micro_mapping[this_item]) except KeyError: pass partial_micro_assign.append(this_list) unique_assign = [] for this_assign in partial_micro_assign: unique_assign.extend(np.unique(this_assign)) unique_assign = np.unique(np.array(unique_assign)) N_MACRO = 5 pcca = PCCA.from_msm(micro_msm, N_MACRO) micro_to_macro_mapping = {} for ii in range(len(pcca.microstate_mapping_)): micro_to_macro_mapping[ii] = pcca.microstate_mapping_[ii] # for n macrostates, any frame that does not belong to any microstate and thus macrostate is labeled to be in the nth macrostate for ii in range(len(raw_clusters)): if ii in micro_to_macro_mapping.keys(): pass else: micro_to_macro_mapping[ii] = N_MACRO # assignments to macro states macro_assign = [] for this_assign in geo_assign:
from msmbuilder.msm import MarkovStateModel assign, ref_macro_assign = tlp._metastable_system() fig1 = plt.figure() plt.plot(assign, 'o') plt.title('microstate assignments') plt.savefig('/home/shenglan/TryMSMbuilder/output/test_microassign.png') plt.close(fig1) print assign.shape print ref_macro_assign.shape print assign[0] test = PCCA(2).fit(assign) macro_assign = test.fit_transform(assign)[0] print test.n_states_ print test.mapping_ print macro_assign.shape print np.sum(macro_assign) print len(np.unique(macro_assign)) == 2 fig2 = plt.figure() plt.plot(macro_assign, 'o') plt.title('macro assignments') plt.savefig('/home/shenglan/TryMSMbuilder/output/test_macroassign.png') plt.close(fig2)