Election#
[1]:
import svvamp
Create a population of 9 voters with preferences over 5 candidates, using the Spheroid model (which extends Impartial Culture to utilities):
[2]:
random_profile = svvamp.GeneratorProfileSpheroid(n_v=9, n_c=5)
profile = random_profile()
Preference rankings of the voters:
[3]:
profile.preferences_rk
[3]:
array([[2, 0, 4, 1, 3],
[4, 1, 0, 2, 3],
[3, 0, 4, 1, 2],
[3, 1, 4, 2, 0],
[0, 2, 4, 3, 1],
[4, 3, 0, 1, 2],
[1, 4, 2, 0, 3],
[2, 0, 3, 1, 4],
[0, 4, 3, 2, 1]])
Define a voting rule:
[4]:
rule = svvamp.RulePlurality()
Load the profile into the voting rule:
[5]:
rule(profile)
[5]:
<svvamp.rules.rule_plurality.RulePlurality at 0x17b8f9d6270>
Ballots:
[6]:
rule.ballots_
[6]:
array([2, 4, 3, 3, 0, 4, 1, 2, 0])
Scores:
[7]:
rule.scores_
[7]:
array([2, 1, 2, 2, 2])
Order the candidates according to their scores:
[8]:
rule.candidates_by_scores_best_to_worst_
[8]:
array([0, 2, 3, 4, 1])
[9]:
rule.scores_best_to_worst_
[9]:
array([2, 2, 2, 2, 1])
The winner, her score and her total utility:
[10]:
rule.w_
[10]:
0
[11]:
rule.score_w_
[11]:
np.int64(2)
[12]:
rule.total_utility_w_
[12]:
0.7459377376822462
Decide whether the winner of the election is a Condorcet winner:
[13]:
rule.w_is_condorcet_winner_ut_abs_
[13]:
True