RuleMajorityJudgment

class whalrus.RuleMajorityJudgment(*args, converter: whalrus.converters_ballot.converter_ballot.ConverterBallot = None, scorer: whalrus.scorers.scorer.Scorer = None, scale: whalrus.scales.scale.Scale = None, default_median: object = None, **kwargs)[source]

Majority Judgment.

Parameters
  • args – Cf. parent class.

  • converter (ConverterBallot) – Default: ConverterBallotToLevels, with scale=scorer.scale.

  • scorer (Scorer) – Default: ScorerLevels. Alternatively, you may provide an argument scale. In that case, the scorer will be ScorerLevels(scale).

  • default_median (object) – The median level that a candidate has when it receives absolutely no evaluation whatsoever.

  • kwargs – Cf. parent class.

Examples

>>> rule = RuleMajorityJudgment([{'a': 1, 'b': 1}, {'a': .5, 'b': .6},
...                              {'a': .5, 'b': .4}, {'a': .3, 'b': .2}])
>>> rule.scores_as_floats_
{'a': (0.5, -0.25, 0.25), 'b': (0.4, 0.5, -0.25)}
>>> rule.winner_
'a'

For each candidate, its median evaluation m is computed. When a candidate has two medians (like candidate b in the above example, with .4 and .6), the lower value is considered. Let p (resp. q) denote the proportion of the voters who evaluate the candidate better (resp. worse) than its median. The score of the candidate is the tuple (m, p, -q) if p > q, and (m, -q, p) otherwise. Scores are compared lexicographically.

For Majority Judgment, verbal evaluation are generally used. The following example is actually the same as above, but with verbal evaluations instead of grades:

>>> rule = RuleMajorityJudgment([
...     {'a': 'Excellent', 'b': 'Excellent'}, {'a': 'Good', 'b': 'Very Good'},
...     {'a': 'Good', 'b': 'Acceptable'}, {'a': 'Poor', 'b': 'To Reject'}
... ], scale=ScaleFromList(['To Reject', 'Poor', 'Acceptable', 'Good', 'Very Good', 'Excellent']))
>>> rule.scores_as_floats_
{'a': ('Good', -0.25, 0.25), 'b': ('Acceptable', 0.5, -0.25)}
>>> rule.winner_
'a'

By changing the scorer, you may define a very different rule. The following one rewards the candidate with best median Borda score (with secondary criteria that are similar to Majority Judgment, i.e. the proportions of voters who give a candidate more / less than its median Borda score):

>>> from whalrus.scorers.scorer_borda import ScorerBorda
>>> from whalrus.converters_ballot.converter_ballot_to_order import ConverterBallotToOrder
>>> rule = RuleMajorityJudgment(scorer=ScorerBorda(), converter=ConverterBallotToOrder())
>>> rule(['a > b ~ c > d', 'c > a > b > d']).scores_as_floats_
{'a': (2.0, 0.5, 0.0), 'b': (1.0, 0.5, 0.0), 'c': (1.5, 0.5, 0.0), 'd': (0.0, 0.0, 0.0)}
>>> rule.winner_
'a'
property best_score_

The best score.

Type

object

compare_scores(one: tuple, another: tuple) → int[source]

Compare two scores.

Parameters
  • one (object) – A score.

  • another (object) – A score.

Returns

0 if they are equal, a positive number if one is greater than another, a negative number otherwise.

Return type

int

property cotrailers_

“Cotrailers”. The set of candidates with the worst score.

Type

NiceSet

property cowinners_

Cowinners. The set of candidates with the best score.

Type

NiceSet

property n_candidates_

Number of candidates.

Type

int

property order_

Result of the election as a (weak) order over the candidates. It is a list of NiceSet. The first set contains the candidates that have the best score, the second set contains those with the second best score, etc.

Type

list

property scores_

The scores. A NiceDict of triples.

Type

NiceDict

property scores_as_floats_

Scores as floats. It is the same as scores_, but converted to floats.

Type

NiceDict

property strict_order_

Result of the election as a strict order over the candidates. The first element is the winner, etc. This may use the tie-breaking rule.

Type

list

property trailer_

The “trailer” of the election. This is the last candidate in strict_order_ and also the unfavorable choice of the tie-breaking rule in cotrailers_.

Type

object

property winner_

The winner of the election. This is the first candidate in strict_order_ and also the choice of the tie-breaking rule in cowinners_.

Type

object

property worst_score_

The worst score.

Type

object