modify documentation
This commit is contained in:
parent
0835eff420
commit
ff0f646d04
@ -1,3 +1,7 @@
|
||||
"""
|
||||
This Module defines functions to compute the kendall tau distance between two
|
||||
rankings, and the kemeny-young rank aggregation method.
|
||||
"""
|
||||
import numpy as np
|
||||
from numba import jit, njit
|
||||
from itertools import permutations
|
||||
@ -18,7 +22,6 @@ Number = int|float
|
||||
|
||||
|
||||
|
||||
|
||||
def kendall_tau_dist(ranking_a: list[int], ranking_b: list[int]) -> Number:
|
||||
"""The kendall τ distance between two rankings / permutations.
|
||||
It is the number of inversions that don't have the same sign within all pairs of an inversion of ranking_a and an inversion of ranking_b.
|
||||
@ -42,9 +45,9 @@ def __tau(A: list[int], B: list[int]) -> int:
|
||||
|
||||
|
||||
def rank_aggregation(rankings: list[list[int]]) -> tuple[int, tuple[int, ...]]:
|
||||
"""Brute-force kemeny-young rank aggregation.
|
||||
"""Return the order elected by the kemeny-young method.
|
||||
Args:
|
||||
ranks: A list of the ranks (2D numpy array).
|
||||
ranks: A list of the ranks (2D numpy array) to elect from.
|
||||
Returns:
|
||||
int, list: The minimal sum of distances to ranks, the rank of minimal distance.
|
||||
"""
|
||||
@ -67,6 +70,9 @@ def rank_aggregation(rankings: list[list[int]]) -> tuple[int, tuple[int, ...]]:
|
||||
return min_dist, best_ranking
|
||||
|
||||
|
||||
|
||||
#################################### TESTS #####################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
ranks = np.array([[0, 1, 2, 3, 4],
|
||||
[0, 1, 3, 2, 4],
|
||||
|
Loading…
x
Reference in New Issue
Block a user