UtilPreferences Module

poisson_approval.utils.UtilPreferences.d_candidate_ordinal_utility(order)[source]

Ordinal utilities of the candidates.

Parameters

order (str) – For example 'abc' (ranking) or 'a~b>c' (weak order).

Returns

Key: candidate. Value: an ordinal utility.

Return type

dict

Examples

>>> d_candidate_ordinal_utility('abc')
{'a': 1, 'b': 0.5, 'c': 0}
>>> d_candidate_ordinal_utility('a>b~c')
{'a': 1, 'b': 0, 'c': 0}
>>> d_candidate_ordinal_utility('a~b>c')
{'a': 1, 'b': 1, 'c': 0}
poisson_approval.utils.UtilPreferences.is_hater(weak_order)[source]

Whether a weak order represents a “hater”.

Parameters

weak_order (str) – A weak order, e.g. 'a>b~c', 'a~b>c', etc.

Returns

True iff the weak order is of the form 'a~b>c'.

Return type

bool

Examples

>>> is_hater('a~b>c')
True
poisson_approval.utils.UtilPreferences.is_lover(weak_order)[source]

Whether a weak order represents a “lover”.

Parameters

weak_order (str) – A weak order, e.g. 'a>b~c', 'a~b>c', etc.

Returns

True iff the weak order is of the form 'a>b~c'.

Return type

bool

Examples

>>> is_lover('a>b~c')
True
poisson_approval.utils.UtilPreferences.is_weak_order(o)[source]

Whether an object is a weak order.

Parameters

o (object) –

Returns

True iff o is a string that represent a weak order, i.e. of the form 'a>b~c' (lover) or 'a~b>c' (hater).

Return type

bool

Examples

>>> is_weak_order('a>b~c')
True
>>> is_weak_order('a>b~')
False
>>> is_weak_order(42)
False
poisson_approval.utils.UtilPreferences.sort_weak_order(weak_order)[source]

Put a weak order in normalized format (with the indifferent candidates sorted alphabetically).

Parameters

weak_order (str) – A weak order, e.g. 'a>b~c', 'a~b>c', etc.

Returns

The same weak order in normalized format.

Return type

str

Examples

>>> sort_weak_order('a>c~b')
'a>b~c'
>>> sort_weak_order('b~a>c')
'a~b>c'