# IterableStrategyThresholdGrid¶

class poisson_approval.IterableStrategyThresholdGrid(denominator_threshold, denominator_ratio_optimistic=None, profile=None, voting_rule=None, d_ranking_fixed_strategy=None, test=None, **kwargs)[source]

Iterate over threshold strategies (StrategyThreshold).

Parameters: denominator_threshold (int or iterable) – The grain(s) of the grid for the utility thresholds. denominator_ratio_optimistic (int or iterable, optional) – The grain(s) of the grid for the ratios of optimistic voters. profile (Profile, optional) – voting_rule (str, optional) – The voting rule. Possible values are APPROVAL, PLURALITY and ANTI_PLURALITY. Default: the same voting rule as profile if a profile is specified, APPROVAL otherwise. d_ranking_fixed_strategy (dict) – Key: ranking. Value: fixed strategy. Cf. examples below. test (callable.) – A function StrategyThreshold -> bool. Only strategies meeting this test are given.

Examples

Basic usage:

>>> for strategy in IterableStrategyThresholdGrid(denominator_threshold=3):  # doctest: +ELLIPSIS
...     print(strategy)
<abc: ab, acb: ac, bac: ab, bca: bc, cab: ac, cba: bc>
<abc: ab, acb: ac, bac: ab, bca: bc, cab: ac, cba: utility-dependent (1/3)>
<abc: ab, acb: ac, bac: ab, bca: bc, cab: ac, cba: utility-dependent (2/3)>
<abc: ab, acb: ac, bac: ab, bca: bc, cab: ac, cba: c>
<abc: ab, acb: ac, bac: ab, bca: bc, cab: utility-dependent (1/3), cba: bc>
...
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: c>


Specify a profile:

>>> from poisson_approval import ProfileHistogram
>>> profile = ProfileHistogram({'abc': 0.75, 'bac': 0.25}, {'abc': [1], 'bac': [1]})
>>> for strategy in IterableStrategyThresholdGrid(denominator_threshold=2, profile=profile):
...     print(strategy)
<abc: ab, bac: ab> ==> a, b
<abc: ab, bac: utility-dependent (1/2)> ==> b
<abc: ab, bac: b> ==> b
<abc: utility-dependent (1/2), bac: ab> ==> a
<abc: utility-dependent (1/2), bac: utility-dependent (1/2)> ==> a
<abc: utility-dependent (1/2), bac: b> ==> a
<abc: a, bac: ab> ==> a
<abc: a, bac: utility-dependent (1/2)> ==> a
<abc: a, bac: b> ==> a


Specify some fixed strategies:

>>> iterable = IterableStrategyThresholdGrid(
...     denominator_threshold=2,
...     d_ranking_fixed_strategy={'abc': 1, 'acb': 1, 'bac': 1, 'bca': 1})
>>> for strategy in iterable:
...     print(strategy)
<abc: a, acb: a, bac: b, bca: b, cab: ac, cba: bc>
<abc: a, acb: a, bac: b, bca: b, cab: ac, cba: utility-dependent (1/2)>
<abc: a, acb: a, bac: b, bca: b, cab: ac, cba: c>
<abc: a, acb: a, bac: b, bca: b, cab: utility-dependent (1/2), cba: bc>
<abc: a, acb: a, bac: b, bca: b, cab: utility-dependent (1/2), cba: utility-dependent (1/2)>
<abc: a, acb: a, bac: b, bca: b, cab: utility-dependent (1/2), cba: c>
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: bc>
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: utility-dependent (1/2)>
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: c>


Use a condition with the parameter test:

>>> profile = ProfileHistogram({'abc': 0.75, 'bac': 0.25}, {'abc': [1], 'bac': [1]})
>>> def test_a_wins(strategy):
...     return strategy.winners == {'a'}
>>> for strategy in IterableStrategyThresholdGrid(denominator_threshold=2, profile=profile, test=test_a_wins):
...     print(strategy)
<abc: utility-dependent (1/2), bac: ab> ==> a
<abc: utility-dependent (1/2), bac: utility-dependent (1/2)> ==> a
<abc: utility-dependent (1/2), bac: b> ==> a
<abc: a, bac: ab> ==> a
<abc: a, bac: utility-dependent (1/2)> ==> a
<abc: a, bac: b> ==> a


Loop also over the ratios of optimistic voters:

>>> from poisson_approval import ProfileDiscrete
>>> profile = ProfileDiscrete({('abc', 0.2): 0.75, ('bac', 0.4): 0.25})
>>> iterable = IterableStrategyThresholdGrid(denominator_threshold=2, denominator_ratio_optimistic=2,
...                                          profile=profile)
>>> for strategy in iterable:  # doctest: +ELLIPSIS
...     print(repr(strategy))
StrategyThreshold({'abc': 0, 'bac': 0})
StrategyThreshold({'abc': 0, 'bac': (Fraction(1, 2), 0)})
StrategyThreshold({'abc': 0, 'bac': (Fraction(1, 2), Fraction(1, 2))})
StrategyThreshold({'abc': 0, 'bac': (Fraction(1, 2), 1)})
StrategyThreshold({'abc': 0, 'bac': 1})
StrategyThreshold({'abc': (Fraction(1, 2), 0), 'bac': 0})
...
StrategyThreshold({'abc': 1, 'bac': 1})