forked from qiongwu86/MIMO-NOMA_AoI_GA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfig_AoI_users.py
More file actions
executable file
·69 lines (54 loc) · 2.04 KB
/
Copy pathfig_AoI_users.py
File metadata and controls
executable file
·69 lines (54 loc) · 2.04 KB
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
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 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_3'])
avg_rs.append(temp_rs)
# for debug-----------to check each test result
# n = 9
# path = dir_path + fileList[n]
# print (fileList,fileList[n])
# res = np.load(path)
# temp_rs = np.array(res['arr_3'])
# avg_rs.append(temp_rs)
avg_rs = np.mean(avg_rs, axis=0, keepdims=True)[0]
return avg_rs
user_num_list = [2,3,4,5,6]
# user_num_list = [2]
AoI_ddpg = []
AoI_max = []
AoI_random = []
Data_file = 'Data_t_0.5_σ_0.004'
for user_num in user_num_list:
res_path_ddpg = Data_file + '/test/ddpg/varying_usernum/usernum_' + str(user_num) + '/'
res_path_maxpower = Data_file + '/test/max/varying_usernum/usernum_' + str(user_num) + '/'
res_path_random_power = Data_file + '/test/random/varying_usernum/usernum_' + str(user_num) + '/'
AoI_ddpg.append(np.mean(output_avg(res_path_ddpg), axis=0))
# AoI_max.append(np.mean(output_avg(res_path_maxpower), axis=0))
AoI_random.append(np.mean(output_avg(res_path_random_power), axis=0))
x = np.arange(len(user_num_list))
width = 0.25
print (AoI_ddpg, AoI_random)
plt.bar(x, AoI_ddpg, width=width, label='ddpg')
plt.bar(x + width, AoI_random, width=width, label='random', color='darkred', tick_label=user_num_list)
# plt.bar(x + 2 *width, AoI_max, width=width, label='max', color='salmon')
plt.xticks()
plt.ylabel('AoI')
plt.xlabel('$M$')
plt.grid(linestyle=':')
# font = FontProperties(fname="C:/Windows/Fonts/SimSun.ttc", size=15)
# plt.legend(prop = font)
plt.legend()
plt.show()
# 0.5373234790872096 0.5122950156634629