correlation_analysis.py 文件源码

python
阅读 87 收藏 0 点赞 0 评论 0

项目:Waskom_PNAS_2017 作者: WagnerLabPapers 项目源码 文件源码
def tail_correlations(corrmat, tails, mask=None):
    """Compute the mean within and between tail correlations."""
    assert corrmat.shape == (len(tails), len(tails))
    if mask is not None:
        assert corrmat.shape == mask.shape

    def is_within(pair):
        a, b = pair
        return a == b

    # Identify cells in the matrix that represent within or between pairs
    pairs = product(tails, tails)
    wmat = np.reshape(map(is_within, pairs), corrmat.shape)
    bmat = ~wmat

    # Possibly exclude cells with the mask
    if mask is not None:
        wmat &= mask
        bmat &= mask

    # Remove the diagonal from the within matrix
    wmat[np.diag_indices_from(wmat)] = False

    # Average the correlations for within and between pairs
    corr_w = corrmat[wmat].mean()
    corr_b = corrmat[bmat].mean()

    return corr_w, corr_b
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号