-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_fig05_barplot.py
148 lines (114 loc) · 5.09 KB
/
plot_fig05_barplot.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
########################################
# plot_fig05_barplot.py
#
# Description. Script used to actually plot Fig. 5 of the paper.
#
# Author. @victorcroisfelt
#
# Date. December 31, 2021
#
# This code is part of the code package used to generate the numeric results
# of the paper:
#
# Croisfelt, V., Abrão, T., and Marinello, J. C., “User-Centric Perspective in
# Random Access Cell-Free Aided by Spatial Separability”, arXiv e-prints, 2021.
#
# Available on:
#
# https://arxiv.org/abs/2107.10294
#
# Comment. Please, make sure that you have the required data files. They are
# obtained by running the scripts:
#
# - data_fig05_barplot_cellfree.py
# - data_fig05_barplot_cellular.py
#
########################################
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import cm
import warnings
########################################
# Preamble
########################################
# Comment the line below to see possible warnings related to python version
# issues
warnings.filterwarnings("ignore")
axis_font = {'size':'8'}
plt.rcParams.update({'font.size': 8})
matplotlib.rc('xtick', labelsize=8)
matplotlib.rc('ytick', labelsize=8)
matplotlib.rc('text', usetex=True)
matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
########################################
# Lookup table
########################################
# Load best pair look up table
load = np.load("lookup/lookup_fig05_best_pair_est1.npz", allow_pickle=True)
best_pair_lookup_est1 = load["best_pair"]
best_pair_lookup_est1 = best_pair_lookup_est1.item()
load = np.load("lookup/lookup_fig05_best_pair_est2.npz", allow_pickle=True)
best_pair_lookup_est2 = load["best_pair"]
best_pair_lookup_est2 = best_pair_lookup_est2.item()
load = np.load("lookup/lookup_fig05_best_pair_est3.npz", allow_pickle=True)
best_pair_lookup_est3 = load["best_pair"]
best_pair_lookup_est3 = best_pair_lookup_est3.item()
# Load possible values of delta for Estimator 3
load = np.load("lookup/lookup_fig05_06_delta.npz", allow_pickle=True)
delta_lookup = load["delta"]
delta_lookup = delta_lookup.item()
# Range of collision sizes
collisions = np.arange(1, 11)
best_delta = np.zeros((collisions.size))
# Go throguh all collisions
for cs, collisionSize in enumerate(collisions):
best_delta[cs] = delta_lookup[(collisionSize, 8, (best_pair_lookup_est3[(collisionSize, 8)])[1])]
########################################
# Loading data
########################################
print('--------------------------------------------------')
print('Fig 05: barplot')
print('--------------------------------------------------\n')
# Load data
data_cellular = np.load("data/fig05_barplot_cellular.npz")
data_cellfree_est1 = np.load("data/fig05_barplot_cellfree_est1.npz", allow_pickle=True)
data_cellfree_est2 = np.load("data/fig05_barplot_cellfree_est2.npz", allow_pickle=True)
data_cellfree_est3 = np.load("data/fig05_barplot_cellfree_est3.npz", allow_pickle=True)
# Print Table II
print("*** TABLE II ****")
print("\n")
print("Estimator 1: " + str(best_pair_lookup_est1.values()))
print("\n")
print("Estimator 2: " + str(best_pair_lookup_est2))
print("\n")
print("Estimator 3: " + str(best_pair_lookup_est3))
print(" " + str())
print("\n")
print("*****************\n")
print("wait for the plot...\n")
# Extract NMSEs
nmse_cellular = data_cellular["nmse"]
nmse_cellfree_est1 = data_cellfree_est1["nmse"]
nmse_cellfree_est2 = data_cellfree_est2["nmse"]
nmse_cellfree_est3 = data_cellfree_est3["nmse"]
########################################
# Plot
########################################
fig, ax = plt.subplots(figsize=(3.15, 1.5))
width = 0.2
error_kw = dict(lw=1, capsize=1, capthick=1)
dy_cellular = [-(nmse_cellular[0] - nmse_cellular[1]), nmse_cellular[-1] - nmse_cellular[1]]
dy_cellfree_est1 = [-(nmse_cellfree_est1[0] - nmse_cellfree_est1[1]), nmse_cellfree_est1[-1] - nmse_cellfree_est1[1]]
dy_cellfree_est2 = [-(nmse_cellfree_est2[0] - nmse_cellfree_est2[1]), nmse_cellfree_est2[-1] - nmse_cellfree_est2[1]]
dy_cellfree_est3 = [-(nmse_cellfree_est3[0] - nmse_cellfree_est3[1]), nmse_cellfree_est3[-1] - nmse_cellfree_est3[1]]
ax.bar(collisions - 3/2*width, nmse_cellular[1], yerr=dy_cellular, width=width, linewidth=2.0, color='black', label='Cellular', align='center', alpha=0.5, log=True, error_kw=error_kw)
ax.bar(collisions - 1/2*width, nmse_cellfree_est1[1], yerr=dy_cellfree_est1, width=width, linewidth=2.0, label='Cell-free: Est. 1, $N=8$', align='center', alpha=0.5, log=True, error_kw=error_kw)
ax.bar(collisions + 1/2*width, nmse_cellfree_est2[1], yerr=dy_cellfree_est2, width=width, linewidth=2.0, label='Cell-free: Est. 2, $N=8$', align='center', alpha=0.5, log=True, error_kw=error_kw)
ax.bar(collisions + 3/2*width, nmse_cellfree_est3[1], yerr=dy_cellfree_est3, width=width, linewidth=2.0, label='Cell-free: Est. 3, $N=8$', align='center', alpha=0.5, log=True, error_kw=error_kw)
ax.set_xlabel("collision size $|\mathcal{S}_t|$")
ax.set_ylabel("${\mathrm{NMSE}}$")
ax.set_xticks(collisions)
ax.legend(fontsize='xx-small')
plt.show()
print("------------------- all done :) ------------------")