本文整理汇总了Python中msmbuilder.MSMLib类的典型用法代码示例。如果您正苦于以下问题:Python MSMLib类的具体用法?Python MSMLib怎么用?Python MSMLib使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MSMLib类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test(self):
num_macro = 5
TC = get("PCCA_ref/tProb.mtx")
A = get("PCCA_ref/Assignments.Fixed.h5")['arr_0']
print A
macro_map, macro_assign = PCCA.run_pcca(num_macro, A, TC)
r_macro_map = get("PCCA_ref/MacroMapping.dat")
macro_map = macro_map.astype(np.int)
r_macro_map = r_macro_map.astype(np.int)
# The order of macrostates might be different between the reference and
# new lumping. We therefore find a permutation to match them.
permutation_mapping = np.zeros(macro_assign.max() + 1, 'int')
for i in range(num_macro):
j = np.where(macro_map == i)[0][0]
permutation_mapping[i] = r_macro_map[j]
macro_map_permuted = permutation_mapping[macro_map]
MSMLib.apply_mapping_to_assignments(macro_assign, permutation_mapping)
r_macro_assign = get("PCCA_ref/MacroAssignments.h5")['arr_0']
eq(macro_map_permuted, r_macro_map)
eq(macro_assign, r_macro_assign)
示例2: test_estimate_rate_matrix_1
def test_estimate_rate_matrix_1():
np.random.seed(42)
assignments = np.random.randint(2, size=(10, 10))
counts = MSMLib.get_count_matrix_from_assignments(assignments)
K = MSMLib.estimate_rate_matrix(counts, assignments).todense()
correct = np.matrix([[-40.40909091, 0.5], [0.33928571, -50.55357143]])
eq(K, correct)
示例3: test_apply_mapping_to_assignments_1
def test_apply_mapping_to_assignments_1():
l = 100
assignments = np.random.randint(l, size=(10, 10))
mapping = np.ones(l)
MSMLib.apply_mapping_to_assignments(assignments, mapping)
eq(assignments, np.ones((10, 10)))
示例4: test_1
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]))
示例5: test_get_count_matrix_from_assignments_3
def test_get_count_matrix_from_assignments_3():
np.random.seed(42)
assignments = np.random.randint(3, size=(10, 10))
val = MSMLib.get_count_matrix_from_assignments(assignments, lag_time=2, sliding_window=False).todense()
eq(val, np.matrix([[5.0, 3.0, 4.0], [2.0, 12.0, 3.0], [4.0, 3.0, 4.0]]))
val = MSMLib.get_count_matrix_from_assignments(assignments, lag_time=2, sliding_window=True).todense()
eq(val, np.matrix([[8.0, 9.0, 11.0], [5.0, 18.0, 6.0], [11.0, 5.0, 7.0]]))
示例6: run_pcca_plus
def run_pcca_plus(num_macrostates, assignments, tProb, flux_cutoff=0.0,
objective_function="crispness",do_minimization=True):
logger.info("Running PCCA+...")
A, chi, vr, MAP = lumping.pcca_plus(tProb, num_macrostates, flux_cutoff=flux_cutoff,
do_minimization=do_minimization, objective_function=objective_function)
MSMLib.apply_mapping_to_assignments(assignments, MAP)
return chi, A, MAP, assignments
示例7: construct_counts_matrix
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
示例8: test_trim_states
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())
示例9: run_pcca
def run_pcca(num_macrostates, assignments, tProb):
logger.info("Running PCCA...")
if len(np.unique(assignments[np.where(assignments != -1)])) != tProb.shape[0]:
raise ValueError('Different number of states in assignments and tProb!')
MAP = lumping.PCCA(tProb, num_macrostates)
# MAP the new assignments and save, make sure don't
# mess up negaitve one's (ie where don't have data)
MSMLib.apply_mapping_to_assignments(assignments, MAP)
return MAP, assignments
示例10: test_get_count_matrix_from_assignments_3
def test_get_count_matrix_from_assignments_3():
np.random.seed(42)
assignments = np.random.randint(3, size=(10,10))
val = MSMLib.get_count_matrix_from_assignments(assignments, lag_time=2, sliding_window=False).todense()
npt.assert_equal(val, np.matrix([[ 5., 3., 4.],
[ 2., 12., 3.],
[ 4., 3., 4.]]))
val = MSMLib.get_count_matrix_from_assignments(assignments, lag_time=2, sliding_window=True).todense()
npt.assert_equal(val, np.matrix([[8., 9., 11.],
[ 5., 18., 6.],
[ 11., 5., 7.]]))
示例11: compare_kyle_to_lutz
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())
示例12: test_apply_mapping_to_assignments_2
def test_apply_mapping_to_assignments_2():
"preseve the -1s"
l = 100
assignments = np.random.randint(l, size=(10, 10))
assignments[0, 0] = -1
mapping = np.ones(l)
correct = np.ones((10, 10))
correct[0, 0] = -1
MSMLib.apply_mapping_to_assignments(assignments, mapping)
eq(assignments, correct)
示例13: test_estimate_rate_matrix_2
def test_estimate_rate_matrix_2():
np.random.seed(42)
counts_dense = np.random.randint(100, size=(4, 4))
counts_sparse = scipy.sparse.csr_matrix(counts_dense)
t_mat_dense = MSMLib.estimate_transition_matrix(counts_dense)
t_mat_sparse = MSMLib.estimate_transition_matrix(counts_sparse)
correct = np.array([[0.22368421, 0.40350877, 0.06140351, 0.31140351],
[0.24193548, 0.08064516, 0.33064516, 0.34677419],
[0.22155689, 0.22155689, 0.26047904, 0.29640719],
[0.23469388, 0.02040816, 0.21428571, 0.53061224]])
eq(t_mat_dense, correct)
eq(t_mat_dense, np.array(t_mat_sparse.todense()))
示例14: test_estimate_transition_matrix_1
def test_estimate_transition_matrix_1():
np.random.seed(42)
count_matrix = np.array([[6, 3, 7], [4, 6, 9], [2, 6, 7]])
t = MSMLib.estimate_transition_matrix(count_matrix)
eq(t, np.array([[0.375, 0.1875, 0.4375],
[0.21052632, 0.31578947, 0.47368421],
[0.13333333, 0.4, 0.46666667]]))
示例15: run_pcca
def run_pcca(num_macrostates, assignments, tProb, output_dir):
MacroAssignmentsFn = os.path.join(output_dir, "MacroAssignments.h5")
MacroMapFn = os.path.join(output_dir, "MacroMapping.dat")
arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn])
logger.info("Running PCCA...")
MAP = lumping.PCCA(tProb, num_macrostates)
# MAP the new assignments and save, make sure don't
# mess up negaitve one's (ie where don't have data)
MSMLib.apply_mapping_to_assignments(assignments, MAP)
np.savetxt(MacroMapFn, MAP, "%d")
msmbuilder.io.saveh(MacroAssignmentsFn, assignments)
logger.info("Saved output to: %s, %s", MacroAssignmentsFn, MacroMapFn)