From ff0f646d04b8595fe782482f7b36bc3808d2e57f Mon Sep 17 00:00:00 2001 From: Oscar Plaisant Date: Thu, 27 Jun 2024 17:23:19 +0200 Subject: [PATCH] modify documentation --- src/kemeny_young.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/kemeny_young.py b/src/kemeny_young.py index 0849e6b..1c95958 100644 --- a/src/kemeny_young.py +++ b/src/kemeny_young.py @@ -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],