def weeds_prec()

in hypernymysuite/unsup.py [0:0]


def weeds_prec(x_row, y_row):
    """
    WeedsPrec similarity

    Args:
        x_row, y_row: ndarray[float]. Vectors for x and y.

    Returns:
        float. Estimation of distributional inclusion.
    """
    # Get the mutual contexts: use y as a binary vector and apply dot product
    # with x: If c is a mutual context, it is 1 in y_non_zero and the value
    # ppmi(x, c) is added to the sum Otherwise, if it is 0 in either x or y, it
    # adds 0 to the sum.
    numerator = np.sum(x_row * (y_row > 0), axis=1)
    # The sum of x's contexts (for ppmi) is the sum of x_row.
    denominator = x_row.sum(axis=1)
    return numerator / (denominator + 1e-12)