Пример #1
0
def find_max(M: np.array):
    """
    Find the max rating.

    :param M: The matrix of ratings. Ratings should be equal or greater than zero. -1 denotes null.
    :return: The max rating value. None if no ratings.
    """
    check_rating_matrix(M)
    return _find_max(M)
Пример #2
0
def rater_max(M: np.array, indexes: list = None) -> np.array:
    """
    Calculate the min ratings of raters.

    :param M: The matrix of ratings. Ratings should be equal or greater than zero. -1 denotes null.
    :param indexes: A list of rows to calculate their average ratings
    :return: The min ratings.
    """
    check_rating_matrix(M)

    return np.array(_rater_max(M, indexes))
Пример #3
0
def rater_median(M: np.array, indexes: list = None) -> np.array:
    """
    Select the median ratings of raters.

    :param M: The matrix of ratings. Ratings should be equal or greater than zero. -1 denotes null.
    :param indexes: A list of rows to select their median ratings
    :return: The median ratings.
    """
    check_rating_matrix(M)

    return np.array(_rater_median(M, indexes))
Пример #4
0
def calibrate(M: np.array,
              scale: (float, float) = (0., 0.),
              additive: bool = True) -> (np.array, np.array, np.array):
    """
    Calibrate ratings and evaluate raters.

    :param M: The matrix of ratings. Ratings should be equal or greater than zero. -1 denotes null.
    :param scale: The range that the ratings are scaled to.
    :param additive: Whether to add three hypothetical objects, one that all raters give the highest rating,
           one that all raters give the lowest rating, and one that all raters give their average ratings.
    :return: The calibrated ratings, the distinction, and the leniency of each rater
    """

    check_rating_matrix(M)

    # m is the number of raters
    # n is the number of objects being rated
    m, n = M.shape

    if additive:
        max_rat = _find_max(M)
        min_rat = _find_min(M)
        best_column = np.full((m, 1), max_rat)
        worst_column = np.full((m, 1), min_rat)
        average_column = _rater_average(M)
        M = np.column_stack((M, best_column, worst_column, average_column))

        assert M.shape[1] == n + 3
        assert np.allclose(_object_average(M, [n, n + 1]), [max_rat, min_rat])

        ratings, distinct, lenient = _calibrate(M)

        ratings = ratings[:-3]
    else:
        ratings, distinct, lenient = _calibrate(M)

    if scale != (0., 0.):
        ratings, lenient = _scale(ratings, lenient, scale)
    return ratings, distinct, lenient