NiceStatsProfileOrdinal

class poisson_approval.NiceStatsProfileOrdinal(tests_profile=None, tests_strategy=None, tests_strategy_dist=None, tests_strategy_winners=None, conditional_on=None, factory_profiles=None)[source]

Compute nice stats on ordinal profiles.

Parameters:
  • tests_profile (list) – A list of pairs (test, name). test is a function ProfileOrdinal -> bool. name is a string.
  • tests_strategy (list) – A list of pairs (test, name). test is a function StrategyOrdinal -> bool. name is a string. For these tests, we compute only the probability that a equilibrium meeting the test exists.
  • tests_strategy_dist (list) – A list of pairs (test, name). test is a function StrategyOrdinal -> bool. name is a string. For these tests, we compute the distribution of numbers of equilibria meeting the test.
  • tests_strategy_winners (list) – A list of pairs (test, name). test is a function StrategyOrdinal -> bool. name is a string. For these tests, we compute the distribution of numbers of winners in equilibria meeting the test.
  • conditional_on (callable) – A function ProfileOrdinal -> bool.
  • factory_profiles (callable) – A callable that inputs nothing and outputs a profile. Default: RandProfileOrdinalUniform().

Notes

The tests in tests_profile concern the profile: what proportions of profiles meet the condition?

The tests in tests_strategy concern the strategies, in the cases where they are equilibrium. For each ordinal profile, we compute the probability (for a uniform distribution of utilities) that at least one strategy is an equilibrium and meet the given condition. This is used to draw plots à la Antonin.

The tests in tests_strategy_dist or tests_strategy_winners concern also the strategies, in the cases where they are equilibrium.

Examples

>>> initialize_random_seeds()
>>> nice_stats = NiceStatsProfileOrdinal(
...     tests_profile=[
...         (lambda profile: any([strategy for strategy in profile.analyzed_strategies_ordinal.equilibria
...                               if strategy.profile.condorcet_winners == strategy.winners]),
...          'There exists a true equilibrium electing the CW'),
...     ],
...     tests_strategy=[
...         (lambda strategy: strategy.profile.condorcet_winners == strategy.winners,
...          'There exists an equilibrium that elects the CW')
...     ],
...     tests_strategy_dist=[
...         (lambda strategy: strategy.profile.condorcet_winners == strategy.winners,
...          'There exists an equilibrium that elects the CW')
...     ],
...     tests_strategy_winners = [
...         (lambda sigma: True, 'Number of possible winners')
...     ],
...     conditional_on=lambda profile: profile.is_profile_condorcet == 1.
... )
>>> nice_stats.run(n_samples=10)
>>> profile = nice_stats.find_example('There exists a true equilibrium electing the CW', False)
>>> print(profile)
<abc: 0.4236547993389047, acb: 0.12122838365799216, bac: 0.0039303209304278885, bca: 0.05394987214431912, cab: 0.1124259903007756, cba: 0.2848106336275805> (Condorcet winner: a)
display_results()[source]

Display the results.

find_example(test, value=True)[source]

Find an example profile.

Parameters:
  • test (str or int) – Name or index of a test in tests_profile.
  • value (bool) – Whether we want an example (True) or a counter-example (False).
Returns:

A profile for which the test returned value in the simulation.

Return type:

ProfileOrdinal

plot_cutoff(test, left='', right='', style='')[source]

Plot the cutoff of a test on the profile.

Parameters:
  • test (str or int) – Name or index of a test in tests_profile.
  • left (str) – Text to be written on the left.
  • right (str) – Text to be written on the right.
  • style (str) – Cf. matplotlib.pyplot.plot().
plot_test_strategy(test, ylabel=True, legend=False, replacement_name=None, style='')[source]

Plot a test on strategy.

Parameters:
  • test (str or int) – Name or index of a test in tests_strategy.
  • ylabel (bool) – If True, the name is used in the y-label. Otherwise, the label is P (probability).
  • legend (bool) – If True, the legend is displayed.
  • replacement_name (str, optional) – If specified, it will be used instead of the test name in the plot.
  • style (str) – Cf. matplotlib.pyplot.plot().
run(n_samples)[source]

Run the simulations and store the results.

Parameters:n_samples (int) – Number of profiles meeting the precondition conditional_on.