-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.py
249 lines (240 loc) · 4.75 KB
/
generator.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import policy
import election
import numpy as np
from agent import agent
def rAgent(
name,
income=None,
gullibility=None,
politician=None,
district=None,
proImm=None,
prolgbt=None,
proWar=None,
race=None,
disposableIncome=None,
):
return agent(
name,
(income if (income != None) else (np.random.rand() * 0.006) + 0.027),
(gullibility if (gullibility != None) else np.random.rand()),
(politician if (politician != None) else False),
(district if (district != None) else 0),
(proImm if (proImm != None) else (np.random.rand() > 0.5)),
(prolgbt if (prolgbt != None) else (np.random.rand() > 0.5)),
(proWar if (proWar != None) else (np.random.rand() > 0.5)),
(
race
if (race != None)
else {
"white": np.random.rand(),
"black": np.random.rand(),
"amind": np.random.rand(),
"asian": np.random.rand(),
"hawaii": np.random.rand(),
"other": np.random.rand(),
}
),
(disposableIncome if (disposableIncome != None) else np.random.rand()),
)
def population(
count=3257,
avginc=[
0.045,
0.0733,
0.0515,
0.042,
0.065,
0.064,
0.071,
0.061,
0.049,
0.051,
0.073,
0.048,
0.06,
0.05,
0.055,
0.054,
0.045,
0.046,
0.051,
0.076,
0.071,
0.051,
0.063,
0.041,
0.05,
0.05,
0.055,
0.052,
0.07,
0.072,
0.045,
0.061,
0.048,
0.061,
0.051,
0.049,
0.054,
0.056,
0.058,
0.047,
0.053,
0.047,
0.056,
0.063,
0.057,
0.066,
0.64,
0.042,
0.056,
0.06,
],
districts=[
50,
7,
69,
30,
393,
56,
37,
11,
207,
104,
15,
17,
129,
67,
32,
29,
45,
47,
13,
61,
69,
99,
56,
31,
62,
10,
20,
29,
14,
90,
22,
197,
101,
8,
119,
40,
41,
129,
11,
51,
9,
67,
280,
31,
9,
84,
74,
18,
59,
8,
],
immigration=0.67 * np.ones(50),
lgbt=[
0.32,
0.54,
0.58,
0.36,
0.61,
0.6,
0.67,
0.57,
0.52,
0.44,
0.64,
0.53,
0.59,
0.47,
0.57,
0.5,
0.4,
0.42,
0.63,
0.56,
0.73,
0.55,
0.58,
0.32,
0.57,
0.47,
0.54,
0.6,
0.75,
0.66,
0.58,
0.63,
0.44,
0.5,
0.53,
0.57,
0.63,
0.56,
0.7,
0.39,
0.44,
0.39,
0.48,
0.43,
0.67,
0.5,
0.63,
0.37,
0.59,
0.41,
],
wars=0.43 * np.ones(50),
):
retval = {}
if districts == []:
districts = [count]
for i in range(len(districts)):
for j in range(districts[i]):
name = str(i) + "_" + str(j)
retval[name] = rAgent(
name,
income=(np.random.rand() * 0.006) + (avginc[i] - 0.003),
district=i,
proImm=True if (np.random.rand() <= immigration[i]) else False,
prolgbt=True if (np.random.rand() <= lgbt[i]) else False,
proWar=True if (np.random.rand() <= wars[i]) else False,
).tojson()
return retval
def policyGen(count=3000, seed=1234, data=False, translator=False, previous=None):
# np.random.seed(seed)
if translator:
if previous == None:
print("No previous data")
else:
retval = previous
else:
retval = []
for i in range(count):
retval.append(policy.random(name="law_" + str(i)))
if not data:
return retval
data = np.zeros((count, 13))
for i in range(count):
data[i, :] = retval[i].toDatum()
return data
def publicOpinion(population, policies):
totals = np.zeros(len(policies))
for p in range(len(policies)):
total = 0.0
for k in population.keys():
total += election.quickAgent(population[k]).proCon(policies[p])
totals[p] = total
return totals/len(population.keys())