当前位置: 首页>>代码示例>>Python>>正文


Python MatrixUtil.is_symmetric_irreducible方法代码示例

本文整理汇总了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
开发者ID:argriffing,项目名称:xgcode,代码行数:53,代码来源:20120529a.py


注:本文中的MatrixUtil.is_symmetric_irreducible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。