本文整理汇总了Python中msmbuilder.MSMLib.build_msm方法的典型用法代码示例。如果您正苦于以下问题:Python MSMLib.build_msm方法的具体用法?Python MSMLib.build_msm怎么用?Python MSMLib.build_msm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msmbuilder.MSMLib
的用法示例。
在下文中一共展示了MSMLib.build_msm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_msm
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def build_msm(self, lag_time=None):
"""Build an MSM from the loaded trajectories."""
if lag_time is None:
lag_time = self.good_lag_time
else:
self.good_lag_time = lag_time
# Do assignment
trajs = get_data.get_shimtraj_from_trajlist(self.traj_list)
metric = classic.Euclidean2d()
# Allocate array
n_trajs = len(self.traj_list)
max_traj_len = max([t.shape[0] for t in self.traj_list])
assignments = -1 * np.ones((n_trajs, max_traj_len), dtype='int')
# Prepare generators
pgens = metric.prepare_trajectory(self.clusterer.get_generators_as_traj())
for i, traj in enumerate(trajs):
ptraj = metric.prepare_trajectory(traj)
for j in xrange(len(traj)):
d = metric.one_to_all(ptraj, pgens, j)
assignments[i, j] = np.argmin(d)
counts = msml.get_count_matrix_from_assignments(assignments, n_states=None, lag_time=lag_time)
rev_counts, t_matrix, populations, mapping = msml.build_msm(counts)
return t_matrix
示例2: test_1
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def test_1(self):
C = MSMLib.get_count_matrix_from_assignments(self.assignments, 2)
rc, t, p, m = MSMLib.build_msm(C, symmetrize="MLE", ergodic_trimming=True)
eq(rc.todense(), np.matrix([[6.46159184, 4.61535527], [4.61535527, 2.30769762]]), decimal=4)
eq(t.todense(), np.matrix([[0.58333689, 0.41666311], [0.66666474, 0.33333526]]), decimal=4)
eq(p, np.array([0.61538595, 0.38461405]), decimal=5)
eq(m, np.array([0, 1]))
示例3: test_4
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def test_4(self):
c, rc, t, p, m = MSMLib.build_msm(self.assignments, lag_time=2, symmetrize=None, sliding_window=True)
npt.assert_array_equal(c.todense(), np.matrix('7 4; 3 2'))
npt.assert_array_almost_equal(rc.todense(), np.matrix('7 4; 3 2'))
npt.assert_array_almost_equal(t.todense(),
np.matrix([[ 0.63636364, 0.36363636],
[ 0.6, 0.4]]))
assert p is None
npt.assert_array_equal(m, [0,1])
示例4: test_3
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def test_3(self):
c, rc, t, p, m = MSMLib.build_msm(self.assignments, self.lag_time, symmetrize='Transpose')
npt.assert_array_equal(c.todense(), np.matrix('7 5; 4 2'))
npt.assert_array_almost_equal(rc.todense(),
np.matrix([[ 7, 4.5],
[ 4.5, 2]]))
npt.assert_array_almost_equal(t.todense(),
np.matrix([[ 0.60869565, 0.39130435],
[ 0.69230769, 0.30769231]]))
npt.assert_array_almost_equal(p, [ 0.63888889, 0.36111111])
npt.assert_array_equal(m, [0,1])
示例5: test_2
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def test_2(self):
c, rc, t, p, m = MSMLib.build_msm(self.assignments, self.lag_time, symmetrize=None)
npt.assert_array_equal(c.todense(), np.matrix('7 5; 4 2'))
npt.assert_array_almost_equal(rc.todense(),
np.matrix([[ 7, 5],
[ 4, 2]]))
npt.assert_array_almost_equal(t.todense(),
np.matrix([[ 0.58333333, 0.41666667],
[ 0.66666667, 0.33333333]]))
assert p is None
npt.assert_array_equal(m, [0,1])
示例6: test_1
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def test_1(self):
c, rc, t, p, m = MSMLib.build_msm(self.assignments, self.lag_time, symmetrize='MLE')
npt.assert_array_equal(c.todense(), np.matrix('7 5; 4 2'))
npt.assert_array_almost_equal(rc.todense(),
np.matrix([[ 6.46159184, 4.61535527],
[ 4.61535527, 2.30769762]]))
npt.assert_array_almost_equal(t.todense(),
np.matrix([[ 0.58333689, 0.41666311],
[ 0.66666474, 0.33333526]]))
npt.assert_array_almost_equal(p, [ 0.61538595, 0.38461405])
npt.assert_array_equal(m, [0,1])
示例7: parallel_get_matrix
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def parallel_get_matrix(input):
print "working"
(Ttest, multinom, NumStates)=input
newT=scipy.sparse.lil_matrix((int(NumStates),int(NumStates)),dtype='float32')
for i in range(0, Ttest.shape[1]):
transitions = numpy.row_stack((numpy.array([i]*NumStates),numpy.arange(0, NumStates)))
pvals=numpy.array([x/sum(Ttest[i]) for x in Ttest[i]])
counts=numpy.random.multinomial(int(multinom), pvals, size=1)
newT=newT+scipy.sparse.coo_matrix((counts[0], transitions),shape=(NumStates,NumStates))
rev_counts, t_matrix, Populations, Mapping = MSMLib.build_msm(newT, symmetrize='MLE', ergodic_trimming=True)
return rev_counts, t_matrix, Populations, Mapping
示例8: msm
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def msm(traj_list, n_clusters, n_medoid_iters=10, lag_time=1, distance_cutoff=None):
"""Use classic clustering methods."""
print "Building a classic MSM"
hkm = cluster(traj_list, n_clusters, n_medoid_iters, distance_cutoff)
# centroids = hkm.get_generators_as_traj()
# centroids_nf = centroids['XYZList'][:, 0, 0:dim]
counts = msml.get_count_matrix_from_assignments(hkm.get_assignments(), n_clusters, lag_time)
rev_counts, t_matrix, populations, mapping = msml.build_msm(counts)
return t_matrix
示例9: test_2_point_1
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def test_2_point_1(self):
"This doesn't work"
# same as test_2, just with get_populations=True
c, rc, t, p, m = MSMLib.build_msm(self.assignments, self.lag_time, symmetrize=None,
get_populations=True)
npt.assert_array_equal(c.todense(), np.matrix('7 5; 4 2'))
npt.assert_array_almost_equal(rc.todense(),
np.matrix([[ 7, 5],
[ 4, 2]]))
npt.assert_array_almost_equal(t.todense(),
np.matrix([[ 0.58333333, 0.41666667],
[ 0.66666667, 0.33333333]]))
npt.assert_array_almost_equal(p, [ 0.61538595, 0.38461405])
npt.assert_array_equal(m, [0,1])
示例10: run
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def run(lagtime, assignments, symmetrize='MLE', input_mapping="None", trim=True, out_dir="./Data/"):
# set the filenames for output
FnTProb = os.path.join(out_dir, "tProb.mtx")
FnTCounts = os.path.join(out_dir, "tCounts.mtx")
FnMap = os.path.join(out_dir, "Mapping.dat")
FnAss = os.path.join(out_dir, "Assignments.Fixed.h5")
FnPops = os.path.join(out_dir, "Populations.dat")
# make sure none are taken
outputlist = [FnTProb, FnTCounts, FnMap, FnAss, FnPops]
arglib.die_if_path_exists(outputlist)
# Check for valid lag time
assert lagtime > 0, 'Please specify a positive lag time.'
# if given, apply mapping to assignments
if input_mapping != "None":
MSMLib.apply_mapping_to_assignments(assignments, input_mapping)
n_assigns_before_trim = len(np.where(assignments.flatten() != -1)[0])
counts = MSMLib.get_count_matrix_from_assignments(assignments, lag_time=lagtime, sliding_window=True)
rev_counts, t_matrix, populations, mapping = MSMLib.build_msm(counts, symmetrize=symmetrize, ergodic_trimming=trim)
if trim:
MSMLib.apply_mapping_to_assignments(assignments, mapping)
n_assigns_after_trim = len(np.where(assignments.flatten() != -1)[0])
# if had input mapping, then update it
if input_mapping != "None":
mapping = mapping[input_mapping]
# Print a statement showing how much data was discarded in trimming
percent = (1.0 - float(n_assigns_after_trim) / float(n_assigns_before_trim)) * 100.0
logger.warning("Ergodic trimming discarded: %f percent of your data", percent)
else:
logger.warning("No ergodic trimming applied")
# Save all output
np.savetxt(FnPops, populations)
np.savetxt(FnMap, mapping, "%d")
scipy.io.mmwrite(str(FnTProb), t_matrix)
scipy.io.mmwrite(str(FnTCounts), rev_counts)
io.saveh(FnAss, assignments)
for output in outputlist:
logger.info("Wrote: %s", output)
return
示例11: run
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def run(LagTime, assignments, Symmetrize='MLE', input_mapping="None", Prior=0.0, OutDir="./Data/"):
# set the filenames for output
FnTProb = os.path.join(OutDir, "tProb.mtx")
FnTCounts = os.path.join(OutDir, "tCounts.mtx")
FnMap = os.path.join(OutDir, "Mapping.dat")
FnAss = os.path.join(OutDir, "Assignments.Fixed.h5")
FnPops = os.path.join(OutDir, "Populations.dat")
# make sure none are taken
outputlist = [FnTProb, FnTCounts, FnMap, FnAss, FnPops]
arglib.die_if_path_exists(outputlist)
# if given, apply mapping to assignments
if input_mapping != "None":
MSMLib.apply_mapping_to_assignments(assignments, input_mapping)
n_states = np.max(assignments.flatten()) + 1
n_assigns_before_trim = len( np.where( assignments.flatten() != -1 )[0] )
rev_counts, t_matrix, populations, mapping = MSMLib.build_msm(assignments,
lag_time=LagTime, symmetrize=Symmetrize,
sliding_window=True, trim=True)
MSMLib.apply_mapping_to_assignments(assignments, mapping)
n_assigns_after_trim = len( np.where( assignments.flatten() != -1 )[0] )
# if had input mapping, then update it
if input_mapping != "None":
mapping = mapping[input_mapping]
# Print a statement showing how much data was discarded in trimming
percent = (1.0 - float(n_assigns_after_trim) / float(n_assigns_before_trim)) * 100.0
logger.warning("Ergodic trimming discarded: %f percent of your data", percent)
# Save all output
np.savetxt(FnPops, populations)
np.savetxt(FnMap, mapping,"%d")
scipy.io.mmwrite(str(FnTProb), t_matrix)
scipy.io.mmwrite(str(FnTCounts), rev_counts)
msmbuilder.io.saveh(FnAss, assignments)
for output in outputlist:
logger.info("Wrote: %s", output)
return
示例12: build_classic_from_memberships
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def build_classic_from_memberships(memberships, lag_time=1):
"""Build a classic msm by turning a membership array into a state list.
This function uses msmbuilder code to calculate the count matrix. Use this
for compairing quantized versions of the fuzzy count matrix building
for consistency.
"""
states = np.zeros(memberships.shape[0], dtype='int')
n_states = memberships.shape[1]
for i in xrange(memberships.shape[0]):
memb = memberships[i]
state = np.argmax(memb)
states[i] = state
counts = msm.get_counts_from_traj(states, n_states, lag_time)
rev_counts, t_matrix, populations, mapping = msm.build_msm(counts)
return rev_counts, t_matrix, populations, mapping
示例13: classic
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def classic(trajs, n_clusters, n_medoid_iters, metric, dim=2, lag_time=1, show=False, desc=None):
"""Use classic clustering methods."""
if desc is None:
desc = "Classic, n_clusters=%d" % n_clusters
hkm = clustering.HybridKMedoids(metric, trajs, k=n_clusters, local_num_iters=n_medoid_iters)
centroids = hkm.get_generators_as_traj()
centroids_nf = centroids['XYZList'][:, 0, 0:dim]
plot_centroids(centroids_nf)
if show: pp.show()
counts = msml.get_count_matrix_from_assignments(hkm.get_assignments(), n_clusters, lag_time)
rev_counts, t_matrix, populations, mapping = msml.build_msm(counts)
analyze_msm(t_matrix, centroids_nf, desc, show=show)
return t_matrix
示例14: get_eigenvalues
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def get_eigenvalues( count_matrix ):
bad_states = np.array(np.where( count_matrix.sum(axis=1) == 0 )[0]).flatten()
i_ary = count_matrix.nonzero()[0]
j_ary = count_matrix.nonzero()[1]
i_ary = np.concatenate( (i_ary, bad_states) )
j_ary = np.concatenate( (j_ary, bad_states) )
new_data = np.concatenate( (count_matrix.data, np.ones(len(bad_states))) )
print i_ary.shape, count_matrix.data.shape, new_data.shape, len(bad_states)
count_matrix = scipy.sparse.csr_matrix( (new_data, (i_ary, j_ary)) )
#count_matrix = count_matrix.tolil()
#count_matrix[(bad_states, bad_states)] = 1
#count_matrix = count_matrix.tocsr()
print count_matrix.data.shape, count_matrix.nonzero()[0].shape
#NZ = np.array(count_matrix.nonzero()).T
#keep_ind = []
#for i in xrange(len(NZ)):
# if NZ[i][0] in bad_states or NZ[i][1] in bad_states:
# pass
# else:
# keep_ind.append(i)
#keep_ind = np.array(keep_ind)
#N = NZ.max()+1
#count_matrix = scipy.sparse.csr_matrix( (np.array(count_matrix.data)[keep_ind], NZ[keep_ind].T), shape=(N,N), copy=True )
try:
t_matrix = MSMLib.build_msm(count_matrix, symmetrize=args.symmetrize)[1]
except:
return None
vals = msm_analysis.get_eigenvectors(t_matrix, args.num_vals, epsilon=1)[0]
vals.sort()
return vals[::-1]
示例15: __init__
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import build_msm [as 别名]
def __init__(self):
super(FourStateTmat, self).__init__()
counts = [
[100, 30, 1, 1],
[30, 100, 1, 1],
[3, 3, 100, 30],
[3, 3, 30, 100]
]
counts = np.array(counts)
counts = scipy.sparse.csr_matrix(counts, dtype=np.int)
rev_counts, tmat, populations, mapping = msml.build_msm(
counts, symmetrize='MLE', ergodic_trimming=True)
self.n_states = tmat.shape[0]
self.tmat = tmat
self.counts = counts
self.rev_counts = rev_counts
self.step_func = self.step_sparse