示例#1
0
def main(plots, lagtimes_ITS, nRuns, nStates, plot_ITS, plot_CK, save_plot, path):
    if lagtimes_ITS is None:
        lagtimes_ITS = [1, 50, 100, 200, 400, 600, 800, 1000]
    MSM_object = estimate.MSM()
    MSM_object.lagtimes = lagtimes_ITS
    if plot_ITS and save_plot and not os.path.exists(os.path.join(path, "ck_plots")):
        os.makedirs(os.path.join(path, "ck_plots"))
    print("Analysing folder ", path)
    for i in range(nRuns):
        print("Plotting validity checks for run %d" % i)
        MSM = utilities.readClusteringObject(os.path.join(path, "MSM_object_%d.pkl" % i))
        assert len(MSM.dtrajs_full) == len(MSM.dtrajs_active)
        MSM_object.MSM_object = MSM
        MSM_object.dtrajs = MSM.dtrajs_full
        if plot_ITS and (save_plot or plots):
            MSM_object._calculateITS()
            if save_plot:
                plt.savefig(os.path.join(path, "its_%d.png" % i))
        if plot_CK and (save_plot or plots):
            # setting mlags to None chooses automatically the number of lagtimes
            # according to the longest trajectory available
            CK_test = MSM_object.MSM_object.cktest(nStates, mlags=None)
            mplt.plot_cktest(CK_test)
            if save_plot:
                plt.savefig(os.path.join(path, "ck_plots/", "ck_%d.png" % i))
        if plots:
            plt.show()
        plt.close('all')
示例#2
0
 def test_plot_kwargs_no_def_overriding(self):
     plot_cktest(self.ck,
                 marker='o',
                 markerfacecolor='red',
                 linewidth=2,
                 label='testlabel',
                 color='blue',
                 linestyle='solid')
示例#3
0
def plotChapmanKolmogorovTest(CKObject,
                              layout=None,
                              padding_between=0.1,
                              padding_top=0.075):
    """ Plot the results of the Chapman-Kolgomorov tests"""
    mplt.plot_cktest(CKObject,
                     layout=layout,
                     padding_between=padding_between,
                     padding_top=padding_top)
    plt.savefig("CK.eps")
示例#4
0
 def test_plot(self):
     P = np.array([[0.5, .25, .25, 0.],
                   [0., .25, .5, .25],
                   [.25, .25, .5, 0],
                   [.25, .25, .25, .25],
                   ])
     dtrajs = generate_trajs(P, 5, 1000)
     msm_obj = pyemma.msm.MaximumLikelihoodMSM()
     msm_obj.estimate(dtrajs)
     ck = msm_obj.cktest(3)
     plot_cktest(ck)
示例#5
0
文件: model.py 项目: tonigi/htmd
    def cktest(self):
        """ Conducts a Chapman-Kolmogorow test.

        Returns
        -------

        """
        from copy import deepcopy
        from pyemma.plots import plot_cktest
        msm = deepcopy(self.msm)
        ck = msm.cktest(self.macronum)
        plot_cktest(ck)
示例#6
0
文件: model.py 项目: Acellera/htmd
    def cktest(self):
        """ Conducts a Chapman-Kolmogorow test.

        Returns
        -------

        """
        from copy import deepcopy
        from pyemma.plots import plot_cktest
        msm = deepcopy(self.msm)
        ck = msm.cktest(self.macronum)
        plot_cktest(ck)
示例#7
0
 def test_plot_kwargs(self):
     plot_cktest(self.ck,
                 marker='o',
                 markerfacecolor='red',
                 linewidth=2,
                 label='testlabel')
示例#8
0
 def test_plot(self):
     plot_cktest(self.ck)
示例#9
0
#print('%s macrostates chosen from timescale separation' %n_macrostates_timescales)
print('%s macrostates chosen because thats what we want' % n_macrostates)

plt.clf()
lags = [1, 2, 5, 10, 20, 50, 100, 200, 400]
its = msm.its(clkmeans.dtrajs, lags=lags)
mplt.plot_implied_timescales(its)

plt.savefig('implied_timescale_plot.png')
plt.clf()

print('fraction of states used = ', MSM.active_state_fraction)
print('fraction of counts used = ', MSM.active_count_fraction)

mplt.plot_cktest(MSM.cktest(3))

plt.savefig('cktest_msm.png')

plt.clf()
plt.figure(figsize=(8, 5))
mplt.plot_free_energy(np.hstack(Y1),
                      np.hstack(Y2),
                      weights=np.hstack(MSM.trajectory_weights()))
plt.xlabel('tic 1')
plt.ylabel('tic 2')

plt.savefig('reweighted_tic1_tic2.png')

print('running hmm')
HMM = msm.bayesian_hidden_markov_model(clkmeans.dtrajs, n_macrostates, lag=100)
示例#10
0
lag_times=list(range(1, 100,2))
n_timescales=10

msm_timescales = implied_timescales(kmeanslabel, lag_times, n_timescales=n_timescales, msm=MarkovStateModel(verbose=False))
#for i in range(n_timescales):
#   plt.plot(lag_times, msm_timescales[:, i], 'o-')

#plt.title('Discrete-time MSM Relaxation Timescales')
                                                                           
#plt.xlabel('lag time')
#plt.ylabel('Relaxation Time')
#plt.semilogy()
#plt.show()


cont_time_msm = ContinuousTimeMSM(lag_time=10, n_timescales=None)
time_model=cont_time_msm.fit(kmeanslabel)
print (time_model.ratemat_)
P=time_model.transmat_
M = msm.markov_model(P)
NetworkPlot.plot_network(P)

#mplt.plot_markov_model(M);

MLMSM_good = msm.estimate_markov_model(kmeanslabel, 4)
ck_good_msm=MLMSM_good.cktest(4)
fig, axes = mplt.plot_cktest(ck_good_msm)
fig.savefig('my_file.png', dpi=300)

示例#11
0
if args.save:
    pp.savefig(os.path.join(args.save_destination, 'msm_pcca.png'))
if args.display:
    pp.show()
pp.clf()
pp.close()

#####CK TEST, if specified
if args.ck:
    ck = msm_from_data.cktest(n_sets, mlags=11)

    mplt.plot_cktest(ck,
                     diag=False,
                     figsize=(7, 7),
                     layout=(n_sets, n_sets),
                     padding_top=0.1,
                     y01=False,
                     padding_between=0.3,
                     dt=0.1,
                     units='ns')
    if args.save:
        pp.savefig(os.path.join(args.save_destination, 'msm_ck.png'))
    if args.display:
        pp.show()
    pp.clf()
    pp.close()

#####
#make hmm from msm and pcca clusters
hmm = msm_from_data.coarse_grain(n_sets)
print 'hmm'
示例#12
0
    ax = mplt.scatter_contour(cc_x[M.active_set],
                              cc_y[M.active_set],
                              eigenvectors_right[:, eig_ind],
                              fig=f)
    plt.xlabel("IC 1")
    plt.ylabel("IC %d" % (eig_ind + 1))
    f.suptitle("%s eigenvector" % label.capitalize())
    plt.savefig("%s_eig.png" % label)

# M = msm.bayesian_markov_model(dtrajs, msm_lag)
# M = msm.estimate_markov_model(dtrajs, msm_lag)
ck = M.cktest(n_sets, mlags=None, err_est=False, show_progress=False)
# mplt.plot_cktest(ck, diag=True, figsize=(7, 7), layout=(2, 2), padding_top=0.1, y01=False, padding_between=0.3, dt=0.1, units='ns')
mplt.plot_cktest(ck,
                 diag=False,
                 figsize=(7, 7),
                 y01=False,
                 padding_between=0.3)
plt.savefig("ck_test.png")

M.pcca(n_sets)
pcca_dist = M.metastable_distributions
membership = M.metastable_memberships  # get PCCA memberships
# memberships over trajectory
# dist_all = [np.hstack([pcca_dist[i, :][dtraj] for dtraj in M.discrete_trajectories_full]) for i in range(n_sets)]
# mem_all = [np.hstack([membership[:, i][dtraj] for dtraj in M.discrete_trajectories_full]) for i in range(n_sets)]

# fig, axes = plt.subplots(1, n_sets, figsize=(16, 3))
# matplotlib.rcParams.update({'font.size': 12})
# axes = axes.flatten()
# np.seterr(invalid='warn')
示例#13
0
    print input_data.clustercenters[pcca_sets[number],0], input_data.clustercenters[pcca_sets[number],1]
for number in range(n_sets):
    pp.scatter(input_data.clustercenters[pcca_sets[number],0], input_data.clustercenters[pcca_sets[number],1], color=color_list[number])
if args.save:
    pp.savefig(os.path.join(args.save_destination, 'msm_pcca.png'))
if args.display:
    pp.show()
pp.clf()
pp.close()

#####CK TEST, if specified
if args.ck:
    ck = msm_from_data.cktest(n_sets, mlags=11)


    mplt.plot_cktest(ck, diag=False, figsize=(7,7), layout=(n_sets,n_sets), padding_top=0.1, y01=False, padding_between=0.3, dt=0.1, units='ns')
    if args.save:
        pp.savefig(os.path.join(args.save_destination, 'msm_ck.png'))
    if args.display:
        pp.show()
    pp.clf()
    pp.close()

#####
#make hmm from msm and pcca clusters
hmm = msm_from_data.coarse_grain(n_sets)
print 'hmm'
print hmm.stationary_distribution
print hmm.transition_matrix
np.savetxt(os.path.join(args.save_destination, 'msm_populations.txt'), hmm.stationary_distribution)
np.savetxt(os.path.join(args.save_destination, 'msm_transmat.txt'), hmm.transition_matrix)