-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot_results.py
237 lines (195 loc) · 6.04 KB
/
plot_results.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
import os
import numpy as np
import matplotlib.pyplot as plt
RESULTS_FOLDER = './Results/test/'
NUM_BINS = 100
BITS_IN_BYTE = 8.0
MILLISEC_IN_SEC = 1000.0
M_IN_B = 1000000.0
VIDEO_LEN = 48
VIDEO_BIT_RATE = [300, 750, 1200, 1850, 2850, 4300]
K_IN_M = 1000.0
REBUF_P = 4.3
SMOOTH_P = 1
COLOR_MAP = plt.cm.jet #nipy_spectral, Set1,Paired
SIM_DP = 'sim_dp'
#SCHEMES = ['BB', 'RB', 'FIXED', 'FESTIVE', 'BOLA', 'RL', 'sim_rl', SIM_DP]
SCHEMES = ['test_ppo']
def main():
time_all = {}
bit_rate_all = {}
buff_all = {}
bw_all = {}
raw_reward_all = {}
for scheme in SCHEMES:
time_all[scheme] = {}
raw_reward_all[scheme] = {}
bit_rate_all[scheme] = {}
buff_all[scheme] = {}
bw_all[scheme] = {}
log_files = os.listdir(RESULTS_FOLDER)
for log_file in log_files:
time_ms = []
bit_rate = []
buff = []
bw = []
reward = []
print(log_file)
with open(RESULTS_FOLDER + log_file, 'rb') as f:
if SIM_DP in log_file:
last_t = 0
last_b = 0
last_q = 1
lines = []
for line in f:
lines.append(line)
parse = line.split()
if len(parse) >= 6:
time_ms.append(float(parse[3]))
bit_rate.append(VIDEO_BIT_RATE[int(parse[6])])
buff.append(float(parse[4]))
bw.append(float(parse[5]))
for line in reversed(lines):
parse = line.split()
r = 0
if len(parse) > 1:
t = float(parse[3])
b = float(parse[4])
q = int(parse[6])
if b == 4:
rebuff = (t - last_t) - last_b
assert rebuff >= -1e-4
r -= REBUF_P * rebuff
r += VIDEO_BIT_RATE[q] / K_IN_M
r -= SMOOTH_P * np.abs(VIDEO_BIT_RATE[q] - VIDEO_BIT_RATE[last_q]) / K_IN_M
reward.append(r)
last_t = t
last_b = b
last_q = q
else:
for line in f:
parse = line.split()
if len(parse) <= 1:
break
time_ms.append(float(parse[0]))
bit_rate.append(int(parse[1]))
buff.append(float(parse[2]))
bw.append(float(parse[4]) / float(parse[5]) * BITS_IN_BYTE * MILLISEC_IN_SEC / M_IN_B)
reward.append(float(parse[6]))
if SIM_DP in log_file:
time_ms = time_ms[::-1]
bit_rate = bit_rate[::-1]
buff = buff[::-1]
bw = bw[::-1]
time_ms = np.array(time_ms)
time_ms -= time_ms[0]
# print log_file
for scheme in SCHEMES:
if scheme in log_file:
time_all[scheme][log_file[len('log_' + str(scheme) + '_'):]] = time_ms
bit_rate_all[scheme][log_file[len('log_' + str(scheme) + '_'):]] = bit_rate
buff_all[scheme][log_file[len('log_' + str(scheme) + '_'):]] = buff
bw_all[scheme][log_file[len('log_' + str(scheme) + '_'):]] = bw
raw_reward_all[scheme][log_file[len('log_' + str(scheme) + '_'):]] = reward
break
# ---- ---- ---- ----
# Reward records
# ---- ---- ---- ----
log_file_all = []
reward_all = {}
for scheme in SCHEMES:
reward_all[scheme] = []
for l in time_all[SCHEMES[0]]:
schemes_check = True
for scheme in SCHEMES:
if l not in time_all[scheme] or len(time_all[scheme][l]) < VIDEO_LEN:
schemes_check = False
break
if schemes_check:
log_file_all.append(l)
for scheme in SCHEMES:
reward_all[scheme].append(np.sum(raw_reward_all[scheme][l][1:VIDEO_LEN]))
mean_rewards = {}
for scheme in SCHEMES:
mean_rewards[scheme] = np.mean(reward_all[scheme])
fig = plt.figure()
ax = fig.add_subplot(111)
for scheme in SCHEMES:
ax.plot(reward_all[scheme])
SCHEMES_REW = []
for scheme in SCHEMES:
SCHEMES_REW.append(scheme + ': ' + str(mean_rewards[scheme]))
colors = [COLOR_MAP(i) for i in np.linspace(0, 1, len(ax.lines))]
for i,j in enumerate(ax.lines):
j.set_color(colors[i])
ax.legend(SCHEMES_REW, loc=4)
plt.ylabel('total reward')
plt.xlabel('trace index')
plt.show()
# ---- ---- ---- ----
# CDF
# ---- ---- ---- ----
fig = plt.figure()
ax = fig.add_subplot(111)
for scheme in SCHEMES:
values, base = np.histogram(reward_all[scheme], bins=NUM_BINS)
cumulative = np.cumsum(values)
ax.plot(base[:-1], cumulative)
colors = [COLOR_MAP(i) for i in np.linspace(0, 1, len(ax.lines))]
for i,j in enumerate(ax.lines):
j.set_color(colors[i])
legend = ax.legend(SCHEMES_REW, loc=4, fontsize = 16)
frame = legend.get_frame()
frame.set_alpha(0)
frame.set_facecolor('none')
plt.ylabel('CDF (Perc. of sessions)', fontsize = 20)
plt.xlabel("Average Values of Chunk's $QoE_{log}$", fontsize = 18)
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(2.5)
ax.spines['left'].set_linewidth(2.5)
plt.title('HSDPA and FCC') # HSDPA , FCC , Oboe
plt.show()
# ---- ---- ---- ----
# check each trace
# ---- ---- ---- ----
for l in time_all[SCHEMES[0]]:
schemes_check = True
for scheme in SCHEMES:
if l not in time_all[scheme] or len(time_all[scheme][l]) < VIDEO_LEN:
schemes_check = False
break
if schemes_check:
fig = plt.figure()
ax = fig.add_subplot(311)
for scheme in SCHEMES:
ax.plot(time_all[scheme][l][:VIDEO_LEN], bit_rate_all[scheme][l][:VIDEO_LEN])
colors = [COLOR_MAP(i) for i in np.linspace(0, 1, len(ax.lines))]
for i,j in enumerate(ax.lines):
j.set_color(colors[i])
plt.title(l)
plt.ylabel('bit rate selection (kbps)')
ax = fig.add_subplot(312)
for scheme in SCHEMES:
ax.plot(time_all[scheme][l][:VIDEO_LEN], buff_all[scheme][l][:VIDEO_LEN])
colors = [COLOR_MAP(i) for i in np.linspace(0, 1, len(ax.lines))]
for i,j in enumerate(ax.lines):
j.set_color(colors[i])
plt.ylabel('buffer size (sec)')
ax = fig.add_subplot(313)
for scheme in SCHEMES:
ax.plot(time_all[scheme][l][:VIDEO_LEN], bw_all[scheme][l][:VIDEO_LEN])
colors = [COLOR_MAP(i) for i in np.linspace(0, 1, len(ax.lines))]
for i,j in enumerate(ax.lines):
j.set_color(colors[i])
plt.ylabel('bandwidth (mbps)')
plt.xlabel('time (sec)')
SCHEMES_REW = []
for scheme in SCHEMES:
SCHEMES_REW.append(scheme + ': ' + str(np.sum(raw_reward_all[scheme][l][1:VIDEO_LEN])))
ax.legend(SCHEMES_REW, loc=9, bbox_to_anchor=(0.5, -0.1), ncol=int(np.ceil(len(SCHEMES) / 2.0)))
plt.show()
if __name__ == '__main__':
main()