-
Notifications
You must be signed in to change notification settings - Fork 3
/
fig_reward.py
executable file
·58 lines (45 loc) · 1.86 KB
/
fig_reward.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
import os
# os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
import numpy as np
import ipdb as pdb
import matplotlib.pyplot as plt
from helper import *
from matplotlib.font_manager import FontProperties
def moving_average(a, n=10) :
ret = np.cumsum(a, dtype=float, axis=0)
ret[n:] = ret[n:] - ret[:-n]
return ret[n - 1:] / n
def output_avg(dir):
dir_path = dir
fileList = os.listdir(dir_path)
fileList = [name for name in fileList if '.npz' in name]
avg_rs = []
for name in fileList:
path = dir_path + name
res = np.load(path)
temp_rs = np.array(res['arr_0'])
avg_rs.append(temp_rs)
avg_rs = moving_average(np.mean(avg_rs, axis=0, keepdims=True)[0],30)
return avg_rs
ddpg_reward = output_avg('test_S_ddpg_sigma0_02_rate3_lane2/step_result/')
GD_local_reward = output_avg('test_S_GD_local_lane2/step_result/')
GD_offload_reward = output_avg('test_S_GD_Offload_lane2/step_result/')
font = FontProperties(fname="C:/Windows/Fonts/SimSun.ttc", size=22)
font1 = {'family' : 'SimSun',
'weight' : 'normal',
'size' : 22,
}
figure, ax = plt.subplots(figsize=(7.5, 6))
#设置坐标刻度值的大小以及刻度值的字体
plt.tick_params(labelsize=22)
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels]
# plt.plot(range(step_op.shape[0]), step_op, color='#1f77b4', label="任务卸载功率", lw=1 )
plt.plot(range(ddpg_reward.shape[0]), ddpg_reward, color='0.25', label='最优策略',lw=1 )
plt.plot(range(GD_local_reward.shape[0]), GD_local_reward, color='0.5', label='本地贪婪策略',lw=1)
plt.plot(range(GD_offload_reward.shape[0]), GD_offload_reward, color='0.75',label='卸载贪婪策略',lw=1)
plt.legend(prop=font1)
plt.grid(linestyle=':')
plt.ylabel("奖励",fontproperties=font)
plt.xlabel("时隙数",fontproperties=font)
plt.show()