import numpy as np
import matplotlib.pyplot as plt
from tabulate import tabulate
from elsim.methods import (fptp, borda, utility_winner, approval)
from elsim.elections import random_utilities
from elsim.strategies import honest_rankings, vote_for_k
from weber_1977_expressions import eff_standard, eff_vote_for_half, eff_borda

n = 2_000
n_voters = 1_000
n_cands_list = (2, 3, 4, 5, 6, 10, 255)

ranked_methods = {'Standard': fptp, 'Borda': borda}

rated_methods = {'Vote-for-half': lambda utilities, tiebreaker:
                 approval(vote_for_k(utilities, 'half'), tiebreaker)}

count = {key: Counter() for key in (ranked_methods.keys() |
                                    rated_methods.keys() | {'UW'})}

start_time = time.monotonic()

for iteration in range(n):
    for n_cands in n_cands_list:
        utilities = random_utilities(n_voters, n_cands)

        # Find the social utility winner and accumulate utilities
        UW = utility_winner(utilities)
        count['UW'][n_cands] += utilities.sum(axis=0)[UW]

        for name, method in rated_methods.items():
Exemplo n.º 2
0
from joblib import Parallel, delayed
from elsim.methods import (fptp, utility_winner, approval)
from elsim.elections import random_utilities
from elsim.strategies import honest_rankings, vote_for_k
from weber_1977_expressions import (eff_standard, eff_vote_for_k,
                                    eff_vote_for_half)

n = 10_000
n_voters = 1_000
n_cands_list = np.arange(2, 11)

ranked_methods = {'Standard': fptp}

rated_methods = {
    'Vote-for-1':
    lambda utilities, tiebreaker: approval(vote_for_k(utilities, 1), tiebreaker
                                           ),
    'Vote-for-2':
    lambda utilities, tiebreaker: approval(vote_for_k(utilities, 2), tiebreaker
                                           ),
    'Vote-for-3':
    lambda utilities, tiebreaker: approval(vote_for_k(utilities, 3), tiebreaker
                                           ),
    'Vote-for-4':
    lambda utilities, tiebreaker: approval(vote_for_k(utilities, 4), tiebreaker
                                           ),
    'Vote-for-half':
    lambda utilities, tiebreaker: approval(vote_for_k(utilities, 'half'),
                                           tiebreaker),
    'Vote-for-(n-1)':
    lambda utilities, tiebreaker: approval(vote_for_k(utilities, -1),
                                           tiebreaker),
Exemplo n.º 3
0
D = 2

ranked_methods = {
    'Plurality': fptp,
    'Runoff': runoff,
    'Hare': irv,
    'Borda': borda,
    'Coombs': coombs,
    'Black': black
}

rated_methods = {
    'SU max':
    utility_winner,
    'Approval':
    lambda utilities, tiebreaker: approval(approval_optimal(utilities),
                                           tiebreaker)
}

# Plot Merrill's results as dotted lines for comparison (traced from plots)
merrill_fig_2c = {
    'Black': {
        2: 100.0,
        3: 100.0,
        4: 100.0,
        5: 100.0,
        7: 100.0
    },
    'Coombs': {
        2: 100.0,
        3: 99.1,
        4: 98.1,
Exemplo n.º 4
0
from tabulate import tabulate
from elsim.methods import (fptp, runoff, irv, approval, borda, coombs,
                           black, utility_winner, condorcet)
from elsim.elections import random_utilities
from elsim.strategies import honest_rankings, approval_optimal

n = 10_000
n_voters = 25
n_cands_list = (2, 3, 4, 5, 7, 10)

ranked_methods = {'Plurality': fptp, 'Runoff': runoff, 'Hare': irv,
                  'Borda': borda, 'Coombs': coombs, 'Black': black}

rated_methods = {'SU max': utility_winner,
                 'Approval': lambda utilities, tiebreaker:
                     approval(approval_optimal(utilities), tiebreaker)}

count = {key: Counter() for key in (ranked_methods.keys() |
                                    rated_methods.keys() | {'CW'})}

start_time = time.monotonic()

for iteration in range(n):
    for n_cands in n_cands_list:
        utilities = random_utilities(n_voters, n_cands)

        """
        "Simulated utilities were normalized by range, that is, each voter's
        set of utilities were linearly expanded so that the highest and lowest
        utilities for each voter were 1 and 0, respectively."