-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_one-to-many.py
57 lines (46 loc) · 1.85 KB
/
plot_one-to-many.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
import csv
import matplotlib.pyplot as plt
import numpy as np
k_value = 4
fileName = 'otm_k%02d_F1.80_d003_0001_strats.csv' % (k_value)
with open(fileName, 'r') as f:
reader = csv.reader(f)
many_y = []
defector_y = []
time = []
for row in reader:
many_pps = 0
defector_pps = 0
for k, elem in enumerate(row):
if 'actvprof' in elem:
if k == 217:
defector_pps += float(row[k+1])
else:
many_pps += float(row[k+1])
many_y = np.append(many_y, float(many_pps))
defector_y = np.append(defector_y, float(defector_pps))
time = np.append(time, float(row[1]))
# print('Avg PPS for many at time: ', row[1], 'is: ', many_pps/59)
# print('PPS for defector trades at time: ', row[1], 'is: ', defector_pps)
# print('Avg PPS for all trades at time: ', row[1], 'is: ', (many_pps + defector_pps)/60)
# print('--------------------------------------------')
for i in range(1, len(many_y)-1):
if many_y[i] == 0:
many_y[i] = (many_y[i-1] + many_y[i+1]) / 2
if defector_y[i] == 0:
defector_y[i] = (defector_y[i-1] + defector_y[i+1]) / 2
time = time / (60*60)
fig, ax = plt.subplots()
plt.ylabel('Profit per second')
plt.xlabel('Time (in hours)')
line, = ax.plot(time, defector_y, 'r-')
line.set_label('defector-profit')
line, = ax.plot(time, many_y/59, 'b-')
line.set_label('avg-many-profit')
line, = ax.plot(time, (many_y + defector_y)/60, 'g-')
line.set_label('Avg Total PPS')
plt.legend()
plt.show()
print('Avg PPS per delta_E for many per agent: ', (np.sum(many_y)/59) / 12)
print('Avg PPS per delta_E for defector: ', np.sum(defector_y) / 12)
print('% increase: ', np.sum(defector_y) / (np.sum(many_y)/59))