class whalrus.Scorer(*args, scale: whalrus.scales.scale.Scale = None, **kwargs)[source]

A “scorer”.

A Scorer is a callable whose inputs are a ballot, a voter and a set of candidates (the set of candidates of the election). When the scorer is called, it loads its arguments. The output of the call is the scorer itself. But after the call, you can access to the computed variables (ending with an underscore), such as scores_.

At the initialization of a Scorer object, some options can be given, such as a scale. In some subclasses, there can be some additional options.

  • args – If present, these parameters will be passed to __call__ immediately after initialization.
  • scale (Scale) – The scale in which scores are computed.
  • kwargs – If present, these parameters will be passed to __call__ immediately after initialization.

This attribute stores the ballot given in argument of the __call__.


This attribute stores the voter given in argument of the __call__.


This attribute stores the candidates given in argument of the __call__.



Cf. ScorerLevels for some examples.


The scores. To each candidate, this dictionary associates either a level in the scale or None. For the meaning of None, cf. RuleRangeVoting for example. Intuitively: a score of 0 means that the value 0 is counted in the average, whereas None is not counted at all (i.e. the weight of the voter is not even counted in the denominator when computing the average).


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.