gs_kernel_slow.py 文件源码

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

项目:microbiome-summer-school-2017 作者: aldro61 项目源码 文件源码
def compute_psi_dict(amino_acids, aa_descriptors):
    """
    This function pre-compute the square Euclidean distance
    between all amino acids descriptors and stock the distance
    in an hash table for easy and fast access during the
    GS kernel computation.

    amino_acids -- List of all amino acids in aa_descriptors

    aa_descriptors -- The i-th row of this matrix contain the
        descriptors of the i-th amino acid of amino_acids list.
    """

    # For every amino acids couple (a_1, a_2) psiDict is a hash table
    # that contain the squared Euclidean distance between the descriptors
    # of a_1 and a_2
    psiDict = {}

    # Fill the hash table psiDict
    for i in xrange(len(amino_acids)):
        for j in xrange(len(amino_acids)):
            c = aa_descriptors[i] - aa_descriptors[j]
            psiDict[amino_acids[i], amino_acids[j]] = np.dot(c,c)

    return psiDict
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号