pairwisebasedalgorithm

class corankco.algorithms.pairwisebasedalgorithm.PairwiseBasedAlgorithm

Class to gather several useful methods for pairwise based algorithms. Class for code factorisation.

static can_be_all_tied(id_elements_to_check: Set[int], cost_matrix: ndarray) bool

Check if all elements in a given set can be tied together with minimal cost.

This method goes through all pairs of elements in the given set, checking the cost of tying them together. If the cost of tying any pair is higher than placing one before or after the other, the function returns False, indicating that not all elements in the set can be tied together with minimal cost.

Parameters:
  • id_elements_to_check (Set[int]) – a set of IDs of the elements to be checked.

  • cost_matrix (ndarray) – a 3D matrix where cost_matrix[i][j][k] denotes the cost of placing i and j in k-th relative position in the consensus.

Returns:

True if all elements can be tied together with minimal cost, False otherwise.

Return type:

bool

static graph_of_elements(positions: ndarray, matrix_scoring_scheme: ndarray) Tuple[Graph, ndarray, Set[Tuple[int, int]]]

Compute the graph of elements, the cost of pairwise relative positions and the set of robust arcs defined in the Future Generation Computer Systems article (as mentioned in the Class docstring)

This function generates a graph of elements as defined in the Future Generation Computer Systems article (as mentioned in the Class docstring) and computes the cost of pairwise relative positions. The latter is a 3D matrix where matrix[i][j][0], then [1], then [2] denote the cost to have i before j, i after j, i tied with j in the consensus according to the scoring scheme.

Parameters:
  • positions – a matrix where pos[i][j] denotes the position of element i in ranking j (-1 if non-ranked)

  • matrix_scoring_scheme – the numpy ndarray version of the scoring scheme

Returns:

A tuple containing the Graph of elements defined in the FGCS article, the 3D matrix of costs of

pairwise relative positions, and the set of the robust arcs defined in the FGCS article

static pairwise_cost_matrix(positions: ndarray, matrix_scoring_scheme: ndarray) ndarray

Compute the graph of elements and the cost of pairwise relative positions.

This function generates a graph of elements as defined in the Future Generation Computer Systems article (as mentioned in the Class docstring) and computes the cost of pairwise relative positions. The latter is a 3D matrix where matrix[i][j][0], then [1], then [2] denote the cost to have i before j, i after j, i tied with j in the consensus according to the scoring scheme.

Parameters:
  • positions – a matrix where pos[i][j] denotes the position of element i in ranking j (-1 if non-ranked)

  • matrix_scoring_scheme – the numpy ndarray version of the scoring scheme

Returns:

A tuple containing the Graph of elements defined in the FGCS article and the 3D matrix of costs of

pairwise relative positions.