def test_2(): model = MarkovStateModel(verbose=False) C = np.array([[4380, 153, 15, 2, 0, 0], [211, 4788, 1, 0, 0, 0], [169, 1, 4604, 226, 0, 0], [3, 13, 158, 4823, 3, 0], [0, 0, 0, 4, 4978, 18], [7, 5, 0, 0, 62, 4926]], dtype=float) C = C + 1.0 / 6.0 model.n_states_ = C.shape[0] model.countsmat_ = C model.transmat_, model.populations_ = model._fit_mle(C) n_trials = 5000 random = np.random.RandomState(0) all_timescales = np.zeros((n_trials, model.n_states_ - 1)) all_eigenvalues = np.zeros((n_trials, model.n_states_)) for i in range(n_trials): T = np.vstack([random.dirichlet(C[i]) for i in range(C.shape[0])]) u = _solve_msm_eigensystem(T, k=6)[0] all_eigenvalues[i] = u all_timescales[i] = -1 / np.log(u[1:]) pp.figure(figsize=(12, 8)) for i in range(3): pp.subplot(2, 3, i + 1) pp.title('Timescale %d' % i) kde = scipy.stats.gaussian_kde(all_timescales[:, i]) xx = np.linspace(all_timescales[:, i].min(), all_timescales[:, i].max()) r = scipy.stats.norm(loc=model.timescales_[i], scale=model.uncertainty_timescales()[i]) pp.plot(xx, kde.evaluate(xx), c='r', label='Samples') pp.plot(xx, r.pdf(xx), c='b', label='Analytic') for i in range(1, 4): pp.subplot(2, 3, 3 + i) pp.title('Eigenvalue %d' % i) kde = scipy.stats.gaussian_kde(all_eigenvalues[:, i]) xx = np.linspace(all_eigenvalues[:, i].min(), all_eigenvalues[:, i].max()) r = scipy.stats.norm(loc=model.eigenvalues_[i], scale=model.uncertainty_eigenvalues()[i]) pp.plot(xx, kde.evaluate(xx), c='r', label='Samples') pp.plot(xx, r.pdf(xx), c='b', label='Analytic') pp.tight_layout() pp.legend(loc=4) pp.savefig('test_msm_uncertainty_plots.png')
def test_2(): model = MarkovStateModel(verbose=False) C = np.array([ [4380, 153, 15, 2, 0, 0], [211, 4788, 1, 0, 0, 0], [169, 1, 4604, 226, 0, 0], [3, 13, 158, 4823, 3, 0], [0, 0, 0, 4, 4978, 18], [7, 5, 0, 0, 62, 4926]], dtype=float) C = C + 1.0 / 6.0 model.n_states_ = C.shape[0] model.countsmat_ = C model.transmat_, model.populations_ = model._fit_mle(C) n_trials = 5000 random = np.random.RandomState(0) all_timescales = np.zeros((n_trials, model.n_states_ - 1)) all_eigenvalues = np.zeros((n_trials, model.n_states_)) for i in range(n_trials): T = np.vstack([random.dirichlet(C[i]) for i in range(C.shape[0])]) u = _solve_msm_eigensystem(T, k=6)[0] all_eigenvalues[i] = u all_timescales[i] = -1 / np.log(u[1:]) pp.figure(figsize=(12, 8)) for i in range(3): pp.subplot(2,3,i+1) pp.title('Timescale %d' % i) kde = scipy.stats.gaussian_kde(all_timescales[:, i]) xx = np.linspace(all_timescales[:,i].min(), all_timescales[:,i].max()) r = scipy.stats.norm(loc=model.timescales_[i], scale=model.uncertainty_timescales()[i]) pp.plot(xx, kde.evaluate(xx), c='r', label='Samples') pp.plot(xx, r.pdf(xx), c='b', label='Analytic') for i in range(1, 4): pp.subplot(2,3,3+i) pp.title('Eigenvalue %d' % i) kde = scipy.stats.gaussian_kde(all_eigenvalues[:, i]) xx = np.linspace(all_eigenvalues[:,i].min(), all_eigenvalues[:,i].max()) r = scipy.stats.norm(loc=model.eigenvalues_[i], scale=model.uncertainty_eigenvalues()[i]) pp.plot(xx, kde.evaluate(xx), c='r', label='Samples') pp.plot(xx, r.pdf(xx), c='b', label='Analytic') pp.tight_layout() pp.legend(loc=4) pp.savefig('test_msm_uncertainty_plots.png')
f = open('macrostate_info-%s.txt' % (it + 1), 'w') f.write('Cluster centers \n\n') for val in clusterer.cluster_centers_: f.write(str(val) + '\n') f.write('\nPopulations\n\n') for val in msm.populations_: f.write(str(val) + '\n') f.write('\nState labels\n\n') for val in msm.state_labels_: f.write(str(val) + '\n') f.write('\nEigen uncertainty\n\n') for val in msm.uncertainty_eigenvalues(): f.write(str(val) + '\n') f.write('\nEigen values\n\n') for val in msm.eigenvalues_: f.write(str(val) + '\n') f.write('\nLeft eigenvectors\n\n') for val in msm.left_eigenvectors_: f.write(str(val) + '\n') f.write('\nRight eigenvectors\n\n') for val in msm.right_eigenvectors_: f.write(str(val) + '\n') f.close()