clustering.py 文件源码

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

项目:Robo-Plot 作者: JackBuck 项目源码 文件源码
def _compute_indices_of_one_pair_of_mergeable_groups(distance_matrix, min_dist_between_items_in_different_groups):
    """
    This function semantically operates on a collection of grouped items.
    It returns a pair of indices corresponding to a pair of groups which are close enough to merge.

    Args:
        distance_matrix (np.ndarray): the matrix containing distances between all groups
        min_dist_between_items_in_different_groups (float): the algorithm will only suggest a pair of groups to be
                                                            merged if they each contain an item which is within this
                                                            value of the other.

    Returns:
        a pair of indices corresponding to a mergeable pair of groups
    """
    # Get all indices (i,j) with i<j, in a 2-element tuple (all rows indices, all column indices).
    inds = np.triu_indices_from(distance_matrix, 1)  # type: tuple
    # Get a boolean vector which indexes both elements of inds and tells whether the pair of groups should be merged
    groups_could_be_merged = distance_matrix[inds] < min_dist_between_items_in_different_groups
    # Get the subset of indices for groups we can merge
    inds_of_mergeable_groups = [inds[i][groups_could_be_merged] for i in range(len(inds))]
    # Return the first pair of indices, if any were found
    indices_matrix = np.transpose(inds_of_mergeable_groups)
    return indices_matrix[0] if len(indices_matrix) > 0 else None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号