本文整理汇总了Python中msmbuilder.MSMLib.apply_mapping_to_assignments方法的典型用法代码示例。如果您正苦于以下问题:Python MSMLib.apply_mapping_to_assignments方法的具体用法?Python MSMLib.apply_mapping_to_assignments怎么用?Python MSMLib.apply_mapping_to_assignments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msmbuilder.MSMLib
的用法示例。
在下文中一共展示了MSMLib.apply_mapping_to_assignments方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
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_apply_mapping_to_assignments_1
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
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)))
示例3: run_pcca_plus
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
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
示例4: construct_counts_matrix
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [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
示例5: run_pcca
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
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
示例6: test_apply_mapping_to_assignments_2
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
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)
示例7: run
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [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
示例8: run_pcca
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
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)
示例9: run
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [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
示例10: run_pcca_plus
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
def run_pcca_plus(num_macrostates, assignments, tProb, output_dir, flux_cutoff=0.0,objective_function="crispness",do_minimization=True):
MacroAssignmentsFn = os.path.join(output_dir, "MacroAssignments.h5")
MacroMapFn = os.path.join(output_dir, "MacroMapping.dat")
ChiFn = os.path.join(output_dir, 'Chi.dat')
AFn = os.path.join(output_dir, 'A.dat')
arglib.die_if_path_exists([MacroAssignmentsFn, MacroMapFn, ChiFn, AFn])
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)
np.savetxt(ChiFn, chi)
np.savetxt(AFn, A)
np.savetxt(MacroMapFn, MAP,"%d")
msmbuilder.io.saveh(MacroAssignmentsFn, assignments)
logger.info('Saved output to: %s, %s, %s, %s', ChiFn, AFn, MacroMapFn, MacroAssignmentsFn)
示例11: run
# 需要导入模块: from msmbuilder import MSMLib [as 别名]
# 或者: from msmbuilder.MSMLib import apply_mapping_to_assignments [as 别名]
def run(lag_time, assignments_list, symmetrize='MLE', input_mapping="None",
out_dir="./Data/"):
# set the filenames for output
tProb_fn = os.path.join(out_dir, "tProb.mtx")
tCounts_fn = os.path.join(out_dir, "tCounts.mtx")
map_fn = os.path.join(out_dir, "Mapping.dat")
pops_fn = os.path.join(out_dir, "Populations.dat")
if len(assignments_list) == 1:
assignments_fn_list = [os.path.join(out_dir, "Assignments.Fixed.h5")]
else:
assignments_fn_list = [os.path.join(out_dir,
"Assignments.Fixed.%d.h5" % i)
for i in xrange(len(assignments_list))]
# make sure none are taken
output_list = [tProb_fn, tCounts_fn, map_fn, pops_fn] + assignments_fn_list
arglib.die_if_path_exists(output_list)
# if given, apply mapping to assignments
for i in xrange(len(assignments_list)):
if input_mapping != "None":
MSMLib.apply_mapping_to_assignments(assignments_list[i],
input_mapping)
n_assigns_before_trim = get_num_assignments(assignments_list)
#num_states = np.unique(np.concatenate([ np.unique(ass[np.where(ass != -1)])
# for ass in assignments_list])).shape[0]
num_states = np.max([np.max(ass) for ass in assignments_list]) + 1
counts = MSMLib.get_count_matrix_from_assignments(assignments_list[0],
n_states=None,
lag_time=lag_time,
sliding_window=False)
for i in xrange(1, len(assignments_list)):
print i
counts = counts + \
MSMLib.get_count_matrix_from_assignments(assignments_list[i],
n_states=num_states,
lag_time=lag_time,
sliding_window=False)
rev_counts, t_matrix, populations, mapping = \
MSMLib.build_msm(counts, symmetrize=symmetrize, ergodic_trimming=True)
for i in xrange(len(assignments_list)):
MSMLib.apply_mapping_to_assignments(assignments_list[i], mapping)
n_assigns_after_trim = get_num_assignments(assignments_list)
# 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
scipy.io.mmwrite(tProb_fn, t_matrix)
scipy.io.mmwrite(tCounts_fn, rev_counts)
np.savetxt(map_fn, mapping, "%d")
np.savetxt(pops_fn, populations)
for i in xrange(len(assignments_fn_list)):
assignments_fn = assignments_fn_list[i]
assignments = assignments_list[i]
msmbuilder.io.saveh(assignments_fn, assignments)
for output in output_list:
logger.info("Wrote: %s", output)
return