Exemplo n.º 1
0
#import seaborn as sns

import numpy as np
import pandas as pd

#votesim.logconfig.setInfo()
#votesim.logconfig.setDebug()
votesim.logconfig.setWarning()
outputfile = 'election3way.pkl'
types = [
    'irv', 'score', 'star', 'plurality', 'smith_minimax', 'approval50',
    'approval75'
]
metric_name = 'stats.regret.vsp'

v = spatial.SimpleVoters(0)
v.add_random(500, ndim=1)
c = spatial.Candidates(v, 0)
e = spatial.Election(v, None, seed=0, scoremax=5)

### Develop parametric study variables
distances = np.linspace(0, 3, 20)[1:]
skew = np.linspace(0, 1, 10)[1:-1]
offset = np.linspace(0, 0.5, 10)

### Loop through parameters
loop_product = itertools.product(distances, skew, offset)
data = []
for ii, (d, s, o) in enumerate(loop_product):
    print(ii, end=',')
    c.reset()
Exemplo n.º 2
0
import matplotlib.pyplot as plt
#import seaborn as sns

import numpy as np
import pandas as pd


#votesim.logconfig.setInfo()
#votesim.logconfig.setDebug()
votesim.logconfig.setWarning()

types = ['irv', 'score', 'star', 'plurality', 'smith_minimax']
metric_name = 'stats.regret.vsp'


v = spatial.SimpleVoters(0, strategy='voter')
v.add_random(500, ndim=1)
c = spatial.Candidates(v, 0)
e = spatial.Election(v, None, seed=0, scoremax=5)

### Develop parametric study variables
distances = np.linspace(0, 2, 10)[1:]
skew = np.linspace(0,1, 10)[1:-1]
offset = np.linspace(0, 0.5, 10 )

### Loop through parameters
loop_product = itertools.product(distances, skew, offset)
for ii, (d, s, o) in enumerate(loop_product):
    print(ii, end=',')
    c.reset()
    a = np.array([0, s, 1]) - 0.5
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
import numpy as np

import sys
import votesim
from votesim.votesystems import tools
from votesim.models import vcalcs, spatial
import matplotlib.pyplot as plt

### Create two simulations using 2 strategies
voternum = 1000
candidates = [-0.3, 0.1, 0.4]
candidates = np.atleast_2d(candidates).T

v1 = spatial.SimpleVoters(seed=0, strategy='candidate')
v1.add_random(voternum)
c1 = spatial.Candidates(voters=v1, seed=0)
c1.add(candidates)
v1.calc_ratings(c1.candidates)

v2 = spatial.SimpleVoters(seed=0, strategy='voter')
v2.add_random(voternum)
c2 = spatial.Candidates(voters=v2, seed=0)
c1.add(candidates)
v2.calc_ratings(c1.candidates)

hist, bins = np.histogram(v1.voters, bins=20, density=True)
bins = (bins[0:-1] + bins[1:]) / 2.

for i in range(3):
Exemplo n.º 4
0
#methods = votesim.votesystems.all_methods.keys()
methods = [
    'plurality', 'irv', 'score5', 'star5', 'star10', 'smith_minimax',
    'approval50', 'approval75', 'ranked_pairs'
]

filename = 'electionNd_data.pkl.zip'

cnums = np.arange(2, 8)

iters = itertools.product(strategies, ndims, cnums)
e = spatial.Election(None, None, seed=seed)
itercount = 0
for (strategy, ndim, cnum) in iters:

    v = spatial.SimpleVoters(seed=seed, strategy=strategy)
    v.add_random(numvoters, ndim=ndim)

    itercount += 1
    print(itercount)

    for trial in range(trialnum):
        c = spatial.Candidates(v, seed=trial)
        c.add_random(cnum, sdev=1.5)
        c.add_random(cnum, sdev=3)
        e.set_models(voters=v, candidates=c)

        for method in methods:
            e.run(etype=method)
print('building dataframe')
df = e.dataframe()