-
Notifications
You must be signed in to change notification settings - Fork 2
/
experiments_aaai.py
92 lines (73 loc) · 2.71 KB
/
experiments_aaai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Experiments used in the paper
# Perpetual Voting: Fairness in Long-Term Decision Making
# Martin Lackner
# Proceedings of AAAI 2020
from __future__ import print_function
import pickle
from os.path import exists
import random
import experiments
from experiments import basic_stats, run_exp_for_history, \
statistical_significance, plot_data
rules = ["av",
"per_pav",
"per_equality",
"per_quota",
"per_nash",
"per_reset",
"per_unitcost",
"per_consensus",
"serial_dictatorship",
]
random.seed(31415)
exp_specs = [
[10000, 20, 5, 20, 0.2, "eucl2", "uniform_square", 1.5]]
instances = experiments.generate_instances(exp_specs)
# run experiments, analyze and plot
for spec in exp_specs:
if spec == "full":
curr_instances = [inst for coll in instances.values()
for inst in coll]
else:
curr_instances = instances[str(spec)]
name = str(spec).replace("]", "").replace("[", "")
exp_name = str(name).replace(" ", "").replace("'", "")
aver_quotacompl = {rule: [] for rule in rules}
max_quotadeviation = {rule: [] for rule in rules}
aver_satisfaction = {rule: [] for rule in rules}
aver_influencegini = {rule: [] for rule in rules}
print()
print(spec, "with", len(curr_instances), "instances")
basic_stats(curr_instances)
picklefile = "../pickle/computation-" + name + ".pickle"
if not exists(picklefile):
print("computing perpetual voting rules")
for history in curr_instances:
run_exp_for_history(history,
aver_quotacompl,
max_quotadeviation,
aver_satisfaction,
aver_influencegini,
rules)
print("writing results to", picklefile)
with open(picklefile, 'wb') as f:
pickle.dump([aver_quotacompl, max_quotadeviation,
aver_satisfaction, aver_influencegini], f,
protocol=2)
else:
print("loading results from", picklefile)
with open(picklefile, 'rb') as f:
(aver_quotacompl, max_quotadeviation,
aver_satisfaction, aver_influencegini) = pickle.load(f)
statistical_significance("perpetual lower quota compliance",
aver_quotacompl)
statistical_significance("Gini influence coefficient",
aver_influencegini)
# create plots
plot_data(exp_name,
aver_quotacompl,
max_quotadeviation,
aver_satisfaction,
aver_influencegini,
rules)
print("Done")