MatrixMajority

class whalrus.MatrixMajority(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, matrix_weighted_majority: whalrus.matrices.matrix.Matrix = None, greater: numbers.Number = 1, lower: numbers.Number = 0, equal: numbers.Number = Fraction(1, 2), diagonal: numbers.Number = Fraction(1, 2), **kwargs)[source]

The majority matrix.

Parameters
  • args – Cf. parent class.

  • converter (ConverterBallot) – Default: ConverterBallotToOrder.

  • matrix_weighted_majority (Matrix.) – Algorithm used to compute the weighted majority matrix W. Default: MatrixWeightedMajority.

  • greater (Number) – Value used when W(c, d) > W(d, c).

  • lower (Number) – Value used when W(c, d) < W(d, c).

  • equal (Number) – Value used when W(c, d) = W(d, c) (except for diagonal coefficients).

  • diagonal (Number) – Value used for the diagonal coefficients.

  • kwargs – Cf. parent class.

Examples

First, we compute a matrix W with the algorithm given in the parameter matrix_weighted_majority. Then for each pair of candidates (c, d), the coefficient of the majority matrix is set to greater, lower, equal or diagonal, depending on the values of W(c, d) and W(d, c).

>>> MatrixMajority(ballots=['a > b ~ c', 'b > a > c', 'c > a > b']).as_array_
array([[Fraction(1, 2), 1, 1],
       [0, Fraction(1, 2), Fraction(1, 2)],
       [0, Fraction(1, 2), Fraction(1, 2)]], dtype=object)

Using the options:

>>> MatrixMajority(ballots=['a > b ~ c', 'b > a > c', 'c > a > b'], equal=0, diagonal=0).as_array_
array([[0, 1, 1],
       [0, 0, 0],
       [0, 0, 0]])
property as_array_

The matrix, as a numpy array. Each row and each column corresponds to a candidate (in the order of candidates_as_list_).

Type

Array

property as_array_of_floats_

The matrix, as a numpy array. It is the same as as_array_, but converted to floats.

Type

Array

property matrix_weighted_majority_

The weighted majority matrix (upon which the computation of the majority matrix is based), once computed with the given profile.

Type

Matrix