ScorerBorda¶
-
class
whalrus.
ScorerBorda
(*args, absent_give_points: bool = True, absent_receive_points: Optional[bool] = True, unordered_give_points: bool = True, unordered_receive_points: Optional[bool] = True, **kwargs)[source]¶ A Borda scorer for
BallotOrder
.- Parameters
args – Cf. parent class.
absent_give_points (bool) – Whether absent candidates give points to the other candidates.
absent_receive_points (bool or None) – Whether absent candidates receives points. Remark: 0 means that any absent candidate receives the score 0 (which will be counted in its average Borda score, median Borda score, etc); in contrast, None means that the absent candidate receives no score (hence this voter will be excluded from the computation of its average Borda score, median Borda score, etc).
unordered_give_points (bool) – Whether unordered candidates give points to the ordered candidates, i.e. they are considered as being in a lower position in the ranking.
unordered_receive_points (bool or None) – Whether unordered candidates receive points. Like for
absent_receive_points
, None means that an unordered candidate receives no score at all.kwargs – Cf. parent class.
Examples
Typical usage:
>>> ScorerBorda(ballot=BallotOrder('a > b > c'), voter='Alice', ... candidates={'a', 'b', 'c'}).scores_ {'a': 2, 'b': 1, 'c': 0}
In the example below, candidates a, b and c are “ordered”, d and e are “unordered”, and f and g are “absent” in the ballot, meaning that these candidates were not even available when the voter cast her ballot. The options allows for different ways to take these special cases into account:
>>> ballot = BallotOrder('a > b ~ c', candidates={'a', 'b', 'c', 'd', 'e'}) >>> candidates_election = {'a', 'b', 'c', 'd', 'e', 'f', 'g'} >>> ScorerBorda(ballot, candidates=candidates_election).scores_as_floats_ {'a': 6.0, 'b': 4.5, 'c': 4.5, 'd': 2.5, 'e': 2.5, 'f': 0.5, 'g': 0.5} >>> ScorerBorda(ballot, candidates=candidates_election, ... absent_receive_points=False).scores_as_floats_ {'a': 6.0, 'b': 4.5, 'c': 4.5, 'd': 2.5, 'e': 2.5, 'f': 0.0, 'g': 0.0} >>> ScorerBorda(ballot, candidates=candidates_election, ... absent_receive_points=False, absent_give_points=False).scores_as_floats_ {'a': 4.0, 'b': 2.5, 'c': 2.5, 'd': 0.5, 'e': 0.5, 'f': 0.0, 'g': 0.0} >>> ScorerBorda(ballot, candidates=candidates_election, ... absent_receive_points=False, absent_give_points=False, ... unordered_receive_points=False).scores_as_floats_ {'a': 4.0, 'b': 2.5, 'c': 2.5, 'd': 0.0, 'e': 0.0, 'f': 0.0, 'g': 0.0} >>> ScorerBorda(ballot, candidates=candidates_election, ... absent_receive_points=False, absent_give_points=False, ... unordered_receive_points=False, unordered_give_points=False).scores_as_floats_ {'a': 2.0, 'b': 0.5, 'c': 0.5, 'd': 0.0, 'e': 0.0, 'f': 0.0, 'g': 0.0}
Usage of None in the options:
>>> ScorerBorda(ballot, candidates=candidates_election, ... absent_receive_points=None, unordered_receive_points=None).scores_as_floats_ {'a': 6.0, 'b': 4.5, 'c': 4.5}
-
property
scores_as_floats_
¶ The scores, given as floats. It is the same as
scores_
, but converted to floats.Like all conversions to floats, it is advised to use this attribute for display purposes only. For computation, you should always use
scores_
, which usually manipulates fractions and therefore allows for exact computation.- Raises
ValueError – If the scores cannot be converted to floats.
- Type