本文整理汇总了Python中MatrixUtil.is_symmetric_irreducible方法的典型用法代码示例。如果您正苦于以下问题:Python MatrixUtil.is_symmetric_irreducible方法的具体用法?Python MatrixUtil.is_symmetric_irreducible怎么用?Python MatrixUtil.is_symmetric_irreducible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixUtil
的用法示例。
在下文中一共展示了MatrixUtil.is_symmetric_irreducible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_input_matrix
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import is_symmetric_irreducible [as 别名]
def get_input_matrix(fs):
"""
@return: M
"""
# get the positive strict lower triangular part of the S matrix
L = []
for i, line in enumerate(fs.lowtri):
values = line.split()
if len(values) != i + 1:
raise ValueError(
'expected %d values on line "%s"' % (i+1, line))
vs = [float(v) for v in values]
if any(x<0 for x in vs):
raise ValueError('exchangeabilities must be nonnegative')
L.append(vs)
# get the stationary distribution weights
distn_weights = [float(v) for v in fs.distn_weights]
if any(x<=0 for x in distn_weights):
raise ValueError('stationary weights must be positive')
# normalize weights to distributions
distn = [v / sum(distn_weights) for v in distn_weights]
# get the exchangeability matrix
nstates = len(L) + 1
S = np.zeros((nstates, nstates))
for i, row in enumerate(L):
for j, v in enumerate(row):
S[i+1, j] = v
S[j, i+1] = v
# check the state space sizes implied by the inputs
if len(set(len(x) for x in (S, distn_weights))) != 1:
raise ValueError('the inputs do not agree on the state space size')
# check for sufficient number of states
if nstates < 2:
raise ValueError('at least two states are required')
# check reducibility of the exchangeability
if not MatrixUtil.is_symmetric_irreducible(S):
raise ValueError('exchangeability is not irreducible')
# get the mutation rate matrix
M = S * distn * fs.scale
M -= np.diag(np.sum(M, axis=1))
# check sign symmetry and irreducibility
if not MatrixUtil.is_symmetric_irreducible(np.sign(M)):
raise ValueError(
'mutation rate matrix is not sign symmetric irreducible')
# check the stationary distributions
distn_observed = mrate.R_to_distn(M)
if not np.allclose(distn_observed, distn):
raise ValueError(
'internal mut stationary distribution computation error')
# return the values
return M