corankco package

Subpackages

Submodules

corankco.consensus module

Module to manage consensus objects. A consensus is defined as a list of rankings (consensus rankings).

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

Bases: object

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.

Returns:

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

Returns:

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) int
Parameters:
  • goldstandard – Iterable, the elements of the goldstandard

  • top_k – the value of k, number of first elements to consider in the consensus

Returns:

the number of elements that are both in the goldstandard and in the top-k of the consensus.

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.

topk_ranking(top_k: int) Set[Element]

Returns the set of elements that are in the top k of the first consensus ranking in the Consensus object. Note that the top-k may be ambiguous if the consensus ranking contains tied elements. In this situation, the set returned is the biggest top_k2 with k2 <= k such that the top_k2 is not ambiguous.

Parameters:

top_k – The top-k to consider

Returns:

A Set of Element, top-k elements of the first consensus ranking

class corankco.consensus.ConsensusFeature(value)

Bases: Enum

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

ASSOCIATED_ALGORITHM = 'computed by:'
COPELAND_SCORES = 'copeland scores:'
COPELAND_VICTORIES = 'copeland victories:'
KEMENY_SCORE = 'kemeny score:'
NECESSARILY_OPTIMAL = 'necessarily optimal:'
ROBUST_PARTITIONING = 'robust partitioning (consistant with all optimal consensus)'
WEAK_PARTITIONING = 'weak partitioning (consistant with at least one optimal consensus)'

corankco.dataset module

Module providing the Dataset class, and a DatasetSelector class to filter datasets according to the number of rankings and/or elements. A Dataset is basically a list of rankings.

class corankco.dataset.Dataset(rankings: List[Ranking], name: str = 'None', repetitions: List[int] | None = None, weights: List[float] | None = None)

Bases: object

Class representing a dataset containing rankings.

Parameters:
  • rankings (List[Ranking]) – The rankings in the dataset.

  • name (str, optional) – Name of the dataset. Defaults to “None”.

  • repetitions (List[int], optional) – A list of integers indicating the number of occurrences for each ranking. If set, its length must match that of rankings.

  • weights (List[float], optional) – A list of floats indicating the weight of each ranking. If set, its length must match that of rankings.

Note:

If both repetitions and weights are set, the ranking at index k is repeated repetitions[k] times with the

same weight weights[k].

contains_element(element: str | int) bool
Parameters:

element – the element to find

Returns:

true iif the target element is ranked in at least one input ranking of the dataset

description() str
Returns:

A complete description of the Dataset object containing all the available information

classmethod from_file(path: str) Dataset

Create a Dataset from a file containing rankings.

Parameters:

path (str) – The path to the file.

Returns:

A new Dataset object.

Return type:

Dataset

classmethod from_raw_list(rankings: List[List[Set[int]] | List[Set[str]] | List[Set[Element]]], name: str = '') Dataset

Create a Dataset from a raw list of rankings.

Parameters:
  • rankings (List[Union[List[Set[int]], List[Set[str]], List[Set[Element]]]]) – A list of rankings.

  • name (str, optional) – The name of the dataset.

Returns:

A new Dataset object.

Return type:

Dataset

get_bucket_ids() ndarray
Returns:

A (nb_elements, nb_rankings) numpy matrix where m[i][j] denotes the bucket id of element i in ranking j position = -1 if element i is non-ranked in ranking j

static get_dataset_from_file(path: str) Dataset

Read a file of rankings and return a Dataset object.

Parameters:

path (str) – The path to the ranking file to read.

Returns:

A Dataset object containing the read rankings.

Return type:

Dataset

static get_datasets_from_folder(path_folder: str) List[Dataset]

Get a List of Dataset, one by file of the folder path :param path_folder: the path of the folder containing the datasets :return: a List containing one Dataset by dataset file in the input folder path

get_positions() ndarray
Returns:

A (nb_elements, nb_rankings) numpy matrix where m[i][j] denotes the position of element i in ranking j position = -1 if element i is non-ranked in ranking j

static get_random_dataset_markov(nb_elem: int, nb_rankings: int, steps: int, complete: bool = False) Dataset

Get a Dataset generated using a Markov chain. Note that if complete is set to false, the return dataset may contain fewer elements than initially wanted if one or more elements have been removed from all the rankings during the markov walking :param nb_elem: the number of elements in the wanted dataset :param nb_rankings: the number of rankings in the wanted dataset :param steps: the number of steps in the Markov chain for each ranking to generate :param complete: true iif the wanted dataset must be complete that is if all the elements must be ranked in all the rankings :return: A Dataset generated using a Markov chain, see details in corankco.rankingsgeneration.rankingsgenerate

static get_uniform_permutation_dataset(nb_elem: int, nb_rankings: int)

Get a Dataset of nb_elem elements and nb_rankings complete rankings without ties where each ranking is uniformly generated :param nb_elem: the number of wanted elements for the dataset :param nb_rankings: the number of rankings for the dataset :return: a new Dataset instance whose rankings are uniformly generated complete rankings without ties

property is_complete: bool

Method to check if the dataset is complete that is if all the rankings of the dataset have the same domain.

Returns:

Returns True if the object is complete, False otherwise.

Return type:

bool

property mapping_elem_id: Dict[Element, int]

Method to get the mapping element -> unique int ID for each element of the universe of the dataset

Returns:

Returns a dictionary that associates for each element of the universe a unique int ID.

Return type:

Dict[Element, int]

property mapping_id_elem: Dict[int, Element]

Method to get the mapping element -> unique int ID for each element of the universe of the dataset

Returns:

Returns a dictionary that associates for each element of the universe a unique int ID.

Return type:

Dict[Element, int]

property name: str

Method to get the name of the dataset.

Returns:

Returns the name of the dataset.

Return type:

str

property nb_elements: int

Get the total number of elements that appear in at least one ranking of the Dataset.

Returns:

The total number of elements in the Dataset.

Return type:

int

property nb_rankings: int

Method to get the number of rankings of the dataset.

Returns:

Returns the number of rankings.

Return type:

int

property rankings: List[Ranking]

Get the rankings from the Dataset.

Returns:

The list of rankings in this Dataset object.

Return type:

List[Ranking]

remove_elements(elements_to_remove: Set)

Remove elements from all rankings in the dataset.

Parameters:

elements_to_remove (Set[Element]) – Set of elements to remove.

Returns:

None

remove_elements_rate_presence_lower_than(rate_presence: float)

Remove elements whose rate of presence in the rankings is lower than the provided threshold.

Parameters:

rate_presence (float) – Threshold below which elements are removed.

Returns:

None

remove_empty_rankings()

Remove empty rankings from the dataset.

Returns:

None

sub_problem_from_elements(elements_to_keep: Set[Element]) Dataset

Generates a sub-problem Dataset by projecting the original Dataset on a given set of elements.

The resulting Dataset only includes the rankings that contain at least one of the elements from the ‘elements_to_keep’ set. Similarly, within each ranking, only buckets that contain at least one of the elements from the ‘elements_to_keep’ set are kept.

Parameters:

elements_to_keep (Set[Element]) – A set of elements which the sub-problem should be based on.

Returns:

A Dataset representing the sub-problem, which only includes the elements from ‘elements_to_keep’ set.

Return type:

Dataset

sub_problem_from_ids(id_elements_to_keep: Set[int]) Dataset

Generates a sub-problem Dataset by projecting the original Dataset on a given set of int IDs of elements.

The resulting Dataset only includes the rankings that contain at least one of the elements from the ‘elements_to_keep’ set. Similarly, within each ranking, only buckets that contain at least one of the elements from the ‘elements_to_keep’ set are kept.

Parameters:

id_elements_to_keep (Set[int]) – A set of elements which the sub-problem should be based on.

Returns:

A Dataset representing the sub-problem which only includes the elements from ‘id_elements_to_keep’ set.

Return type:

Dataset

unified_dataset()

Get a new Dataset object, representing the unified version of the instance dataset. In the returned dataset, for each input ranking r, all the elements of the universe non-ranked in r are added in a unifying bucket at the end of r. :return: a new Dataset object representing the unified version of the current instance

unified_rankings() List[Ranking]

Get a unified version of the dataset as a List of Ranking objects, that is a list of the input rankings such that for each ranking r, all the elements of the universe non-ranked in r are added in a unifying bucket at the end of r. :return: the unified rankings of the Dataset within a new Ranking List

property universe: Set

Method to get the set of elements that appear in at least one input ranking of the dataset.

Returns:

Returns a set of elements.

Return type:

Set

property without_ties: bool

Method to check if the dataset is a list of rankings without ties :return: Returns True iif all the rankings of the dataset are without ties :rtype: bool

write(path) None

Stores the input rankings of the dataset in a file :param path: the path to store the dataset :return: None

class corankco.dataset.DatasetSelector(nb_elem_min: int = 0, nb_elem_max: int | float = inf, nb_rankings_min: int = 0, nb_rankings_max: int | float = inf)

Bases: object

Class usable to filter datasets according to their number of elements and / or rankings

property nb_elem_max: int | float
Returns:

The value of the attribute, that is the maximal number of elements to retain a dataset

property nb_elem_min: int
Returns:

The value of the attribute, that is the minimal number of elements to retain a dataset

property nb_rankings_max: int | float
Returns:

The value of the attribute, that is the maximal number of rankings to retain a dataset

property nb_rankings_min: int
Returns:

The value of the attribute, that is the minimal number of rankings to retain a dataset

select_datasets(list_datasets: List[Dataset]) List[Dataset]

Given a list of Dataset objects, returns the List of Dataset references that fit with the filter :param list_datasets: the list of datasets to filter :return: the list l of Dataset references such that d in l iif: * self.nb_elem_min <= d.nb_elements <= self.nb_elem_max * self.nb_rankings_min <= d.nb_rankings <= self.nb_rankings_max

exception corankco.dataset.EmptyDatasetException

Bases: Exception

Custom exception for empty dataset

corankco.element module

This module contains the Element class used to encapsulate an element to be ranked. An element is defined as an int or a string.

class corankco.element.Element(value: int | str | Element)

Bases: object

A class to represent an element of a ranking.

Parameters:

value (Union[int, str]) – the value of the element, either an integer or a string

can_be_int()
Returns:

True iif the value of Element object is an int or a str that can be converted to int

property type: Type

returns the type of the instance :return: type of the instance :rtype: Type

property value: int | str

returns the value of the instance :return: value of the instance :rtype: Union[int, str]

corankco.kemeny_score_computation module

Module for computation of Kemeny scores. The algorithme of score computation is m * n * log(n) where n is the number of elements and m the number of rankings. The algorithm is based on the number of inversion counting.

exception corankco.kemeny_score_computation.InvalidRankingsForComputingDistance

Bases: Exception

Exception if the ranking used as consensus is not complete towards the dataset.

class corankco.kemeny_score_computation.KemenyComputingFactory(scoring_scheme: ScoringScheme)

Bases: object

Class to compute Kemeny scores given a ScoringScheme, according to the framework defined in P.Andrieu, S.Cohen-Boulakia, M.Couceiro, A.Denise, A.Pierrot. A Unifying Rank Aggregation Model to Suitably and Efficiently Aggregate Any Kind of Rankings. https://dx.doi.org/10.2139/ssrn.4353494 The Kemeny score is generalized within a framework to handle incomplete rankings with ties

get_kemeny_score(ranking: Ranking, dataset: Dataset) float

Note that a Consensus object can be defined by several consensus rankings. Only the first one will be considered to compute the score. All consensus rankings of a Consensus object should be equivalent in quality

property scoring_scheme
Returns:

the scoring scheme used for the computation of kemeny scores

Return type:

ScoringScheme

corankco.ranking module

Module Ranking, containing one class (Ranking). A Ranking is defined as List of buckets, more formally a List of disjoint sets of elements.

class corankco.ranking.Ranking(buckets: List[Set[int]] | List[Set[str]] | List[Set[Element]])

Bases: object

A class to represent a ranking, defined as a List of disjoint Set of Elements

property buckets: List[Set[Element]]

Returns the buckets of the ranking.

Returns:

The buckets of the ranking

Return type:

List[Set[Element]]

can_be_of_int() bool

Returns true iif all the elements in the ranking can be converted to int

Returns:

true iif all the elements in the ranking can be converted to int

Return type:

bool

property domain: Set[Element]

Returns the set of all elements in the Ranking.

Returns:

A set of Elements which are the unique elements in the Ranking.

classmethod from_file(file_path: str) Ranking

Constructs a Ranking instance from a file.

Parameters:

file_path – The path to a file containing a ranking representation.

Returns:

A Ranking instance.

classmethod from_string(ranking_str: str) Ranking

Constructs a Ranking instance from a string representation.

Parameters:

ranking_str (str) – A string representation of a ranking

Returns:

A Ranking instance

Return type:

Ranking

static generate_rankings(nb_elements: int, nb_rankings: int, steps: int, complete=False) List[Ranking]

Method to generate a List of nb_rankings rankings of nb_elements elements, possibly incomplete with ties. Each ranking is initially [{0}, {1}, …, {n-1}], then modifications are done using a Markov chain. For each step from range 1 … step parameter: an element is uniformly selected and may uniformly: - be added in the ranking if the element is currently non-ranked - be removed in the ranking if the element is currently ranked - be in a new bucket at the left of the current left neighbor bucket - be in a new bucket at the right of the current right neighbor bucket - be added in the current left neighbor bucket - be added in the current right neighbor bucket

Parameters:

nb_elements – number of elements of the universe. Note that according to the steps of the Markov chain,

the final list of rankings may have less than the given number of elements (if an element has been removed from

all the input ranking)

Parameters:
  • nb_rankings – the number of rankings to generate

  • steps – the number of steps in the markov chain

  • complete – does the final rankings need to be complete ? Default = False

Returns:

a List of Ranking generated as described in the above description

property nb_elements: int

Returns the number of unique elements in the Ranking. This is equivalent to the size of the domain of the Ranking.

Returns:

An integer which is the number of unique elements in the Ranking.

property positions: Dict[Element, int]

Returns the positions of the elements in the ranking.

Returns:

The positions of the elements in the ranking

Return type:

Dict[Element, int]

static uniform_permutations(nb_elem: int, nb_rankings: int) List[Ranking]

Method to get a List of random uniform Rankings that are complete and without ties.

Parameters:
  • nb_elem – the number of elements in the rankings

  • nb_rankings – the number of rankings to generate

Returns:

a list of random complete rankings without ties on {0, …, n-1}

corankco.scoringscheme module

Module to manage Scoring Schemes. The scoring schemes are two penalty vectors of 6 real values each. The details can be found in the docstring of the ScoringScheme class

exception corankco.scoringscheme.ForbiddenAssociationPenaltiesScoringScheme(message='The first value of the first List must be 0. The second value of the first List must be > 0The fourth value of the first List must be <= the fifth value of the second ListThe first and second values of the second List must be equal. The fourth and the fifth values of the second List must be equalThe third value of the second List must be > 0For instance, [[0., 1., 1., 0., 0., 0.], [1., 1., 0., 1., 1., 0.]]')

Bases: Exception

Customized exception when the ScoringScheme is invalid because wring association of penalties.

exception corankco.scoringscheme.InvalidScoringScheme(message='Scoring scheme must be 2 Lists. Each list must be a list of 6 real >= 0 values. For instance, [[0., 1., 1., 0., 0., 0.], [1., 1., 0., 1., 1., 0.]]')

Bases: Exception

Customized exception when the ScoringScheme is invalid because of the structure.

exception corankco.scoringscheme.NonRealPositiveValuesScoringScheme(message='Each list must be a list of 6 real >= 0 values. For instance, [[0., 1., 1., 0., 0., 0.], [1., 1., 0., 1., 1., 0.]]')

Bases: Exception

Customized exception when the ScoringScheme is invalid because of a value found, not real positive.

class corankco.scoringscheme.ScoringScheme(penalties: List[List[float]])

Bases: object

The ScoringScheme class represents a scoring scheme for comparing rankings.

Parameters:

penalties – A list of 2 penalty vectors i.e. two lists of size 6. Let B be the first penalty vector and T be the second one, c be a consensus ranking (complete) and r be a ranking. B: costs to pay for each elements x,y such that x < y in the consensus, more precisely: B[0] if x < y in r, B[1] if x > y in r, B[2] if x is tied with y in r, B[3] if x is ranked and y is not, B[4] if y is ranked and x is not, B[5] if x and y are non-ranked. T: costs to pay for each elements x,y such that x is tied with y in the consensus, more precisely: T[0] if x < y in r, T[1] if x > y in r, T[2] if x is tied with y in r, T[3] if x is ranked and y is not, T[4] if y is ranked and x is not, T[5] if x and y are non-ranked

Raises:
  • InvalidScoringScheme – If penalties is not of a correct format.

  • NonRealPositiveValuesScoringScheme – If one penalty is not a real value>= 0.

  • ForbiddenAssociationPenaltiesScoringScheme – If one of the following is not respected: - first value of first list must be 0 - second value of the first List must be > 0 - fourth value of the first List must be <= the fifth value of the second List - third value of second list must be > 0 - first and second values of the second List must be equal - fourth and fifth values of the second List must be equal

property b_vector: List[float]

Returns the List of 6 floats that corresponds to vector B according to Andrieu et al., IJAR 2022 :return: vector B of the Scoring Scheme as a List of 6 floats. :rtype: List[float]

description() str

Returns a string that gives details on the ScoringScheme :return: a string that gives details on the ScoringScheme :rtype: str

static get_extended_measure_scoring_scheme()

Get the ScoringScheme defined in [] :return: The ScoringScheme

static get_induced_measure_scoring_scheme()

Get the induced mesure scoring scheme defined in “Bryan Brancotte, Agrégation de classements avec égalités : algorithmes, guides à l’utilisateur et applications aux données biologiques. University of Paris-Sud, Orsay, France, 2015”. This measure is a fusion between the measure to handle incomplete rankings defined in: C. Dwork, R. Kumar, M. Naor, and D. Sivakumar. 2001. Rank aggregation methods for the Web. In Proceedings of the 10th international conference on World Wide Web (WWW ‘01), and the distance to handle ties proposed by R. Fagin, R. Kumar, M. Mahdian, D. Sivakumar, and Erik Vee. 2004. Comparing and aggregating rankings with ties. In Proceedings of the twenty-third ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systems (PODS ‘04). :return: The ScoringScheme [[0., 1., 1., 0., 0., 0.], [1., 1., 0., 0., 0., 0.]]

static get_induced_measure_scoring_scheme_p(p_cost: float)

Get the ScoringScheme that imitates the unification process, that is the non-ranked elements can be virtually considered as tied at the last position or the ranking :param p_cost: the cost to create / break ties :return: The ScoringScheme [[0., 1., p, 0., 1., p], [p, p, 0., p, p, 0.]]

get_nickname() str

Get a nickname of the scoring scheme.

Returns:

A string representing a nickname of the scoring scheme.

static get_pseudodistance_scoring_scheme() ScoringScheme

Get the pseudo-distance defined in: Brancotte, Bryan & Rance, Bastien & Denise, Alain & Cohen-Boulakia, Sarah. (2014). ConQuR-Bio: Consensus Ranking with Query Reformulation for Biological Data. 10.1007/978-3-319-08590-6_13. .

Returns:

The ScoringScheme [[0., 1., 1., 0., 1., 0.], [1., 1., 0., 1., 1., 0.]]

static get_pseudodistance_scoring_scheme_p(p_cost: float)

Get the pseudo-distance scoring scheme defined in: Brancotte, Bryan & Rance, Bastien & Denise, Alain & Cohen-Boulakia, Sarah. (2014). ConQuR-Bio: Consensus Ranking with Query Reformulation for Biological Data. 10.1007/978-3-319-08590-6_13 with reap parameter p = cost of creating / breaking ties :param p_cost: the cost to create / break ties :return: The ScoringScheme [[0., 1., 1., 0., 1., 0.], [1., 1., 0., 1., 1., 0.]]

static get_unifying_scoring_scheme()

Get the ScoringScheme that imitates the unification process, that is the non-ranked elements can be virtually considered as tied at the last position or the ranking :return: The ScoringScheme [[0., 1., 1., 0., 1., 1.], [1., 1., 0., 1., 1., 0.]]

static get_unifying_scoring_scheme_p(p_cost: float)

Get the ScoringScheme that imitates the unification process, that is the non-ranked elements can be virtually considered as tied at the last position or the ranking :param p_cost: the cost to create / break ties :return: The ScoringScheme [[0., 1., p, 0., 1., p], [p, p, 0., p, p, 0.]]

is_equivalent_to(other) bool

Check if the current scoring scheme is equivalent to the given scoring scheme.

Parameters:

other – A ScoringScheme object.

Returns:

True if the scoring schemes are equivalent, False otherwise.

is_equivalent_to_on_complete_rankings_only(other) bool

Check if the current scoring scheme is equivalent to the given scoring scheme on complete rankings

Parameters:

other – A ScoringScheme object.

Returns:

True if the scoring schemes are equivalent, False otherwise.

property penalty_vectors: List[List[float]]

Returns the List of two penalty vectors (each one is a List of 6 floats) of the ScoringScheme

Returns:

List of two penalty vectors (each one is a List of 6 floats) of the ScoringScheme. For instance, [[0., 1., 0.5, 0., 1., 0.], [0.5, 0.5, 0., 0.5, 0.5, 0.]]

Return type:

List[List[float]]

property t_vector: List[float]

Returns the List of 6 floats that corresponds to vector T according to Andrieu et al., IJAR 2022 :return: penalty vector T of the Scoring Scheme as a List of 6 floats. :rtype: List[float]

corankco.utils module

Module with useful functions to interact with files or the os.

corankco.utils.get_rankings_from_file(file: str) List[List[Set[Element]]]
Parameters:

file – The file to get the rankings

Returns:

A List of Set of Element, i.e. a ranking, not yet encapsulated.

corankco.utils.get_rankings_from_folder(folder: str) List[Tuple[List[List[Set[Element]]], str]]
Parameters:

folder – The path of the folder where the datasets are stored.

Returns:

A List of list of rankings (i.e. datasets not yet encapsulated) with the name of the file.

corankco.utils.join_paths(path: str, *paths) str

Joins multiple path strings into a single path string.

Parameters:
  • path – The initial path string.

  • paths – Additional path strings to be appended to the initial path.

Returns:

The resulting path string after joining all input path strings.

corankco.utils.name_file(path_file: str) str
Parameters:

path_file – The path of the target file.

Returns:

The name of the file.

corankco.utils.parse_ranking_with_ties(ranking: str, converter: Callable[[str], Element]) List[Set[Element]]

Function to parse rankings with ties. The rankings can be rankings of int or str Example: [{Bob}, {Martin, John}] or [{0}, {2, 1}]

Parameters:
  • ranking – The str that corresponds to a ranking, for instance [{Bob}, {Martin, John}]

  • converter – The function to convert the elements into str or int

Returns:

a List of Set of Elements, i.e. a raw Ranking, not yet encapsulated

corankco.utils.parse_ranking_with_ties_of_int(ranking: str) List[Set[Element]]
Parameters:

ranking – The ranking str to parse, casting all elements to int.

Returns:

A List of Set of Element, i.e. a ranking, not yet encapsulated.

corankco.utils.parse_ranking_with_ties_of_str(ranking: str) List[Set[Element]]
Parameters:

ranking – The ranking str to parse, casting all elements to str.

Returns:

A List of Set of Element, i.e. a ranking, not yet encapsulated.

corankco.utils.write_rankings(rankings: List[List[Set[Element]]], path: str) None
Parameters:
  • rankings – The rankings to write in a file.

  • path – The path of the file where the rankings should be stored.

Returns:

None

Module contents