本文整理汇总了Python中MatrixUtil.row_major_to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python MatrixUtil.row_major_to_dict方法的具体用法?Python MatrixUtil.row_major_to_dict怎么用?Python MatrixUtil.row_major_to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixUtil
的用法示例。
在下文中一共展示了MatrixUtil.row_major_to_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rescale
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import row_major_to_dict [as 别名]
def rescale(self, scaling_factor):
"""
Rescale the rate matrix.
Some cached values are invalidated.
The stationary distribution is not affected.
@param scaling_factor: each element of the rate matrix is multiplied by this factor
"""
# TODO the object should keep track of the current scaling,
# and this function should just change that number;
# the cached transition matrices could be preserved.
#
# handle a degenerate case
if scaling_factor == 1:
return
# invalidate all cached transition matrices
self.branch_length_to_numpy_transition_matrix = {}
self.branch_length_to_dictionary_transition_matrix = {}
# modify the row major rate matrix
self.row_major_rate_matrix = [[x * scaling_factor for x in row] for row in self.row_major_rate_matrix]
# regenerate the rate matrices using different formats
self.dictionary_rate_matrix = MatrixUtil.row_major_to_dict(self.row_major_rate_matrix, self.states, self.states)
self.numpy_rate_matrix = np.array(self.row_major_rate_matrix)
示例2: get_response_content
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import row_major_to_dict [as 别名]
def get_response_content(fs):
# define the states using the default transition matrix
default_transition_matrix = EnglishModel.get_transition_matrix()
states = list(sorted(set(a for a, b in default_transition_matrix)))
# read the constraints from the form data
if fs.first not in states:
raise HandlingError("invalid first letter")
if fs.last not in states:
raise HandlingError("invalid last letter")
if fs.count == 1 and fs.first != fs.last:
msg_a = "if a single letter is to be simulated "
msg_b = "then the first letter must be the same as the last letter."
raise HandlingError(msg_a + msg_b)
# read the transition matrix from the form data
T = fs.matrix
if T.shape[0] != len(states):
msg = "expected the transition matrix to have %d lines" % len(states)
raise HandlingError(msg)
matrix = MatrixUtil.row_major_to_dict(T.tolist(), states, states)
# simulate the path
path = PathSampler.get_discrete_path_sample(fs.first, fs.last, states, fs.count, matrix)
# show the simulated path in convenient text form
return "".join(path) + "\n"
示例3: __init__
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import row_major_to_dict [as 别名]
def __init__(self, row_major_matrix, ordered_states):
"""
@param row_major_matrix: the rate matrix in row major form
@param ordered_states: the state labels in an order that corresponds to the row_major_matrix order
"""
# do some sanity checks
assert row_major_matrix
nrows = len(row_major_matrix)
ncols = len(row_major_matrix[0])
assert nrows == ncols
assert len(ordered_states) == nrows
assert len(ordered_states) == ncols
# create the dictionary rate matrix
self.dictionary_rate_matrix = MatrixUtil.row_major_to_dict(row_major_matrix, ordered_states, ordered_states)
# create the numpy matrix
self.numpy_rate_matrix = np.array(row_major_matrix)
# cache some stuff
self.row_major_rate_matrix = row_major_matrix
self.states = ordered_states
self.state_to_index = dict((state, i) for i, state in enumerate(self.states))
# create some more or less uninitialized variables
self.branch_length_to_numpy_transition_matrix = {}
self.branch_length_to_dictionary_transition_matrix = {}
self.stationary_distribution = None