consensus

class corankco.consensus.Consensus(consensus_rankings: List[Ranking], dataset: Dataset | None = None, scoring_scheme: ScoringScheme | None = None, att: Dict[ConsensusFeature, Any] | None = None)

Class to represent the Consensus. A Consensus object is defined by a list of rankings. The dataset of input rankings and scoring scheme associated to the Consensus object may also be stored. Finally, a Consensus object can store several features from the ConsensusFeature enumeration

property associated_dataset: Dataset
Returns:

the Dataset object associated to the Consensus object. Can be None if the Consensus object has not been created during a rank aggregation process

property associated_scoring_scheme: ScoringScheme

Returns the ScoringScheme related to the Consensus object

Returns:

The ScoringScheme associated to the Consensus object. Can be None if the Consensus object has not been created during a rank aggregation process.

property consensus_rankings: List[Ranking]
Returns:

the consensus rankings associated with the Consensus object as a List of Ranking objects

property copeland_scores: Dict[Element, float]

The Copeland scores of the elements of the universe. :return: A dictionary whose keys are the elements and the values are the Copeland score of the elements. See CopelandMethod class for more information on the computation of the scores

property copeland_victories: Dict[int, List[int]]

The Copeland number of victories, defeats, equalities for each element :return: A dictionary whose keys are the elements are the values are a list of 3 integers: the number of victories, defeats, equalities of the associated elements See CopelandMethod class for more information

description() str
Returns:

A textual and complete description of the Consensus object which includes the associated features

property elements: Set[Element]
Returns:

the set of elements that are ranked in the consensus rankings

evaluate_topk_ranking(goldstandard: Iterable, top_k: int = 20) int
Parameters:

goldstandard: Iterable, the elements of the goldstandard top_k (int = 20): the value of k, number of first elements to consider in the consensus

Returns:

a Tuple[int][int] containing the number of elements that are both in the goldstandard and in the top-k of the consensus. More precisely, - the first integer is -the second one is

property features: Dict[ConsensusFeature, Any]
Returns:

The features of the Consensus object. The features can vary according to the rank aggregation algorithm that computed the Consensus object.

classmethod from_raw_lists(rankings: List[List[Set[int | str]]]) Consensus

Constructs a Consensus instance from a List[List[Set[Union[int, str]]]] For instance: [[{1, 2}, {3}], [{1}, {3}, {2}]] contains two consensus rankings :param rankings: A list of raw rankings i.e. List of Set of either int or str :type rankings: List[List[Set[Union[int, str]]] :return: A Consensus instance :rtype: Consensus

classmethod get_consensus_from_file(path: str) Consensus

Constructs a Consensus object from a file containing the rankings to store in the Consensus object :param path: the path of the file :return: a Consensus object whose associated rankings are the rankings stored in the file

property kemeny_score: float

Returns the Kemeny score regarding the scoring scheme of the Consensus object between the consensus ranking and the input rankings in the associated Dataset object. Note that if the Consensus object contains several consensus rankings, we use the first one to compute the score Note also that the score is computed in O(nb_rankings * nb_elements * log(nb_elements)) and saved after the first call to the function :return: the Kemeny score between the first input ranking of the Consensus object and the input rankings of the Dataset associated to the Consensus object, regarding the ScoringScheme associated to the Consensus object

property nb_consensus: int
Returns:

the number of consensus ranking objects. Several algorithm can return more than one equivalent consensus ranking in a same Consensus object.

property nb_elements: int
Returns:

the number of elements that appear in the consensus rankings

property necessarily_optimal: bool
Returns:

True if we know that the consensus is necessarily a Kemeny optimal consensus regarding the scoring scheme associated with the consensus. If false, the consensus might be optimal or not.

class corankco.consensus.ConsensusFeature(value)

Enumeration of possible consensus features that might be stored in a Consensus object. All the features are not computed by each algorithm. For example, the Copeland scores are not computed of the algorithm who returned the Consensus object was not CopelandMethod. Note that the Kemeny score can be accessed whatever the rank aggregation algorithm was IsNecessarilyOptimal: If true, then the ranking is a Kemeny optimal ranking regarding the scoring scheme. If false, the ranking may be or not be a Kemeny optimal ranking regarding the scoring scheme

class corankco.consensus.ConsensusSingleRanking(consensus_ranking: Ranking, dataset: Dataset | None = None, scoring_scheme: ScoringScheme | None = None, att: Dict[ConsensusFeature, Any] | None = None)

Class to represent a Consensus defined by only one consensus ranking. All the remaining features of the Consensus objects remain available.

classmethod from_raw_lists(ranking: List[Set[int | str]]) Consensus

Constructs a ConsensusSingleRanking instance from a raw ranking i.e. a List of Set of either int or str objects. :param ranking: A list of rankings :type ranking: List[Set[Union[int, str]]] :return: A ConsensusSingleRanking instance :rtype: ConsensusSingleRanking

position_element(element: Element) int

Returns the position of the given target element in the consensus ranking :param element: the target element :return: the position of the given target element in the consensus ranking