-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_2.py
69 lines (52 loc) · 1.72 KB
/
exp_2.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
"""
Experiment 2: tests varying the win reward
"""
import random
from scipy.stats import norm
import numpy as np
from donor import Donor
from election import Election
import continuous_solver
import baseline_solver
from matplotlib import pyplot as plt
from tqdm import tqdm
POLLING_SD = 0.005
INITIAL_FUNDS = 1000
# for pomcpow
N = 10000
KA = 30
AA = 1.0/30
KO = 5
AO = 0.01
C = 200
START_SUPPORTS = [x/100.0 for x in range(0, 101, 10)]
ROUNDS = 10
MAX_WIN_REWARDS = [x for x in range(100, 1100, 100)]
scores = np.zeros(shape = (len(START_SUPPORTS), len(MAX_WIN_REWARDS)))
contributions = np.zeros(shape = (len(START_SUPPORTS), len(MAX_WIN_REWARDS), ROUNDS))
for i in tqdm(range(len(START_SUPPORTS))):
for j in tqdm(range(len(MAX_WIN_REWARDS))):
max_possible = 0
s = START_SUPPORTS[i]
w = MAX_WIN_REWARDS[j]
election = Election(ROUNDS, s, INITIAL_FUNDS)
donor = Donor(INITIAL_FUNDS)
q = []
c = []
score = 0
while(election.n_rounds != 0):
poll = election.generatePoll()
contribution = continuous_solver.plan_pomcpow(poll, N, election.n_rounds, KA, AA, KO,
AO, C, election.support, donor.funds, election.money + election.opp_money,
election.n_rounds, w)
#contribution = baseline_solver.make_contribution(poll, donor.funds, election.money, election.opp_money)
contributions[i][j][election.n_rounds-1] = contribution
donor.makeContribution(contribution)
election.updateSupport(contribution, verbose=False)
score -= contribution
if(election.support > 0.5):
score += w * ((ROUNDS-election.n_rounds+1)/(ROUNDS+1))
scores[i][j] = score
print(scores)
np.save("win_reward_big_pomcpow_contributions.npy", contributions)
np.save('win_reward_big_pomcpow_scores.npy', np.array(scores))