本文整理汇总了Python中msmbuilder.MSMLib.ergodic_trim方法的典型用法代码示例。如果您正苦于以下问题:Python MSMLib.ergodic_trim方法的具体用法?Python MSMLib.ergodic_trim怎么用?Python MSMLib.ergodic_trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msmbuilder.MSMLib
的用法示例。
在下文中一共展示了MSMLib.ergodic_trim方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: construct_counts_matrix
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def construct_counts_matrix(assignments):
"""Build and return a counts matrix from assignments.
Symmetrize either with transpose or MLE based on the value of the
self.symmetrize variable
Also modifies the assignments file that you pass it to reflect ergodic
trimming
Parameters
----------
assignments : np.ndarray
2D array of MSMBuilder assignments
Returns
-------
counts : scipy.sparse.csr_matrix
transition counts
"""
n_states = np.max(assignments.flatten()) + 1
raw_counts = MSMLib.get_count_matrix_from_assignments(assignments, n_states,
lag_time=Project().lagtime,
sliding_window=True)
ergodic_counts = None
if Project().trim:
raise NotImplementedError(('Trimming is not yet supported because '
'we need to keep track of the mapping from trimmed to '
' untrimmed states for joint clustering to be right'))
try:
ergodic_counts, mapping = MSMLib.ergodic_trim(raw_counts)
MSMLib.apply_mapping_to_assignments(assignments, mapping)
counts = ergodic_counts
except Exception as e:
logger.warning("MSMLib.ergodic_trim failed with message '{0}'".format(e))
else:
logger.info("Ignoring ergodic trimming")
counts = raw_counts
if Project().symmetrize == 'transpose':
logger.debug('Transpose symmetrizing')
counts = counts + counts.T
elif Project().symmetrize == 'mle':
logger.debug('MLE symmetrizing')
counts = MSMLib.mle_reversible_count_matrix(counts)
elif Project().symmetrize == 'none' or (not Project().symmetrize):
logger.debug('Skipping symmetrization')
else:
raise ValueError("Could not understand symmetrization method: %s" % Project().symmetrize)
return counts
示例2: test_trim_states
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def test_trim_states():
# run the (just tested) ergodic trim
counts = scipy.sparse.csr_matrix(np.matrix('2 1 0; 1 2 0; 0 0 1'))
trimmed, mapping = MSMLib.ergodic_trim(counts)
# now try the segmented method
states_to_trim = MSMLib.ergodic_trim_indices(counts)
trimmed_counts = MSMLib.trim_states(states_to_trim, counts, assignments=None)
eq(trimmed.todense(), trimmed_counts.todense())
示例3: compare_kyle_to_lutz
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def compare_kyle_to_lutz(self, raw_counts):
"""Kyle wrote the most recent MLE code. We compare to the previous
code that was written by Lutz.
"""
counts = MSMLib.ergodic_trim(raw_counts)[0]
x_kyle = MSMLib.mle_reversible_count_matrix(counts)
x_kyle /= x_kyle.sum()
x_lutz = MSMLib.__mle_reversible_count_matrix_lutz__(counts)
x_lutz /= x_lutz.sum()
eq(x_kyle.toarray(), x_lutz.toarray())
示例4: test_trim_states
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def test_trim_states():
# run the (just tested) ergodic trim
counts = scipy.sparse.csr_matrix(np.matrix('2 1 0; 1 2 0; 0 0 1'))
trimmed, mapping = MSMLib.ergodic_trim(counts)
# now try the segmented method
states_to_trim = MSMLib.ergodic_trim_indices(counts)
trimmed_counts = MSMLib.trim_states(
states_to_trim, counts, assignments=None)
eq(trimmed.todense(), trimmed_counts.todense())
assignments = np.array([np.arange(counts.shape[0])])
states_to_trim = MSMLib.ergodic_trim_indices(counts)
trimmed_counts, trimmed_assignments = MSMLib.trim_states(states_to_trim, counts, assignments=assignments) # Test that code works with assignments given
trimmed_assignments_ref = np.array([[0, 1, -1]]) # State 2 is strong-disconnected so set to -1
eq(trimmed_assignments, trimmed_assignments_ref)
示例5: test_ergodic_trim
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def test_ergodic_trim():
counts = scipy.sparse.csr_matrix(np.matrix("2 1 0; 1 2 0; 0 0 1"))
trimmed, mapping = MSMLib.ergodic_trim(counts)
eq(trimmed.todense(), np.matrix("2 1; 1 2"))
eq(mapping, np.array([0, 1, -1]))
示例6: compare_kyle_to_reference
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def compare_kyle_to_reference(self, raw_counts, reference):
"""Compare MLE estimated reversible counts to a reference matrix"""
counts = MSMLib.ergodic_trim(raw_counts)[0]
x_kyle = MSMLib.mle_reversible_count_matrix(counts)
eq(x_kyle.toarray(), reference.toarray())
示例7: test_ergodic_trim
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import ergodic_trim [as 别名]
def test_ergodic_trim():
counts = scipy.sparse.csr_matrix(np.matrix('2 1 0; 1 2 0; 0 0 1'))
trimmed, mapping = MSMLib.ergodic_trim(counts)
npt.assert_equal(trimmed.todense(), np.matrix('2 1; 1 2'))
npt.assert_equal(mapping, np.array([0, 1, -1]))