-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.py
286 lines (231 loc) · 10.9 KB
/
draw.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import parameters
import numpy as np
import scienceplots
import os
import matplotlib.pyplot as plt
import matplotlib
# v1.1.0, Avoid Type 3 fonts
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
DELTA_T = parameters.DELTA_T
NUM_ROBOTS = parameters.NUM_ROBOTS
# blue, orange, green, red, purple, brown, pink, gray, yellow, cyan
# ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']
EACH_COLOR = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#e377c2',
'#7f7f7f', '#bcbd22', '#17becf', '#1f77b4', 'k']
MARKER_STYLE = ['o', '^', 'o', '*', 'o', 'o', '*', '^', 's', '*', '*']
LABELS = [
'BDA[8]', '1', 'BDA-CU[2]', '1', '1', '1', 'DMV[1]', '1', '1', '1',
'1', '1', 'CI+CU[13]', '1', '1', '1', '1', '1', '1', '1',
'1', '1', '1', '1', '1', '1', '1', '1', 'Ours', '1',
'CCL', 'DR']
MEAN_LABELS = [r'$\Delta x$', r'$\Delta y$']
TEXT_BBOX = dict(boxstyle='round,pad=0.2', facecolor='white',
edgecolor='white', alpha=0.7)
def each_mean_(numbers, _list, tag='R'):
'''
output RMSE of each robot over time
:param: numbers: int, the number of simulation time
:param: _list: dict, the dict of RMSE of each robot
:param: tag: str, the tag of metric, 'R' for RMSE, 'A' for ANEES
'''
t = np.arange(numbers)
fig, ax = plt.subplots(NUM_ROBOTS, 1)
path = './data/relative-pose/'
if not os.path.exists(path):
os.makedirs(path)
file_path = path + tag + '_each_' + str(parameters.comm_fail_prob) + '.csv'
with open(file_path, 'w') as f:
for type in _list.keys():
f.write(str(type) + ',')
f.write('\n')
for count in range(numbers):
for type, List in _list.items():
np.savetxt(f, List[:, count], fmt='%.4f', newline=',')
f.write(',')
f.write('\n')
def total_mean_(numbers, Lists, tag):
'''
output RMSE of each algorithm(mission 1)
:param: numbers: int, the number of simulation time
:param: _list: dict, the dict of RMSE of each robot
:param: tag: str, the tag of metric, 'R' for RMSE, 'A' for ANEES
'''
plt.style.use(['science', 'ieee', 'no-latex'])
path = './data/relative-pose/'
if not os.path.exists(path):
os.makedirs(path)
file_path = path + tag + str(parameters.comm_fail_prob) + '.csv'
with open(file_path, 'w') as f:
for type in Lists.keys():
f.write(str(type) + ',')
f.write('\n')
for type, List in Lists.items():
# v1.0.0, original division, calculate mean value of each part for TABLE II
# Mean = [np.mean(List[:int(numbers/2)]),
# np.mean(List[int(numbers/2):])]
# v1.1.0, divides 3 parts, ...
Mean = [np.mean(List[:int(np.ceil(numbers/3))]), np.mean(List[int(np.ceil(numbers/3)):int(np.ceil(2*numbers/3))]), np.mean(List[int(np.ceil(2*numbers/3)):])]
np.savetxt(f, Mean, fmt='%.4f', newline=',')
f.write('\n')
t = np.arange(numbers)*DELTA_T
fig3, ax3 = plt.subplots(1, 1)
count = 0
for type, List in Lists.items():
# , marker = MARKER_STYLE[count]
ax3.plot(t, List, '-', label=LABELS[type],
c=EACH_COLOR[count], linewidth=2)
count = count + 1
ax3.set_xlabel('simulation time [s]')
ax3.set_xlim(left=0, right=(t[-1]+1e-1))
path_fig = './figures/relative-pose/'
if not os.path.exists(path_fig):
os.makedirs(path_fig)
if tag == 'R':
ax3.legend(loc="upper left")
ax3.set_ylabel('ARMSE [m]')
# v1.0.0, original division, black line
# ax3.plot([t[int(numbers/2)], t[int(numbers/2)]],
# [0, 6], 'k', linewidth=2) # tau=0 vs 0.5
# v1.1.0, divides 3 parts, ...
ax3.plot([t[int(np.ceil(numbers/3))], t[int(np.ceil(numbers/3))]],
[0, 1.25], 'k-', linewidth=2)
ax3.plot([t[int(np.ceil(numbers/3))],
t[int(np.ceil(numbers/3))]], [1.6, 6], 'k-', linewidth=2)
ax3.plot([t[int(np.ceil(2*numbers/3))],
t[int(2*np.ceil(numbers/3))]], [0, 6], 'k-', linewidth=2)
ax3.set_ylim(bottom=0, top=2)
# v1.0.0, original division, some texts
# ax3.text(50, 1.9, r'$\rho = %.1f$' % parameters.comm_fail_prob,
# color='k', ha='center', va='center', bbox=TEXT_BBOX)
# ax3.text(43, 1.7, r'$\tau = 0$', color='k', ha='center',
# va='center', fontsize=6, bbox=TEXT_BBOX)
# ax3.text(57, 1.7, r'$\tau = 0.5$', color='k', ha='center',
# va='center', fontsize=6, bbox=TEXT_BBOX)
# v1.1.0, divides 3 parts, ...
ax3.text(41, 1.7, r'$\rho = %.1f$' % parameters.comm_fail_prob,
color='k', ha='center', va='center', bbox=TEXT_BBOX)
ax3.text(8, 1.93, r'$\tau = 0$', color='k', ha='center',
va='center', fontsize=6, bbox=TEXT_BBOX)
ax3.text(41, 1.93, r'$\tau = 0.5$', color='k', ha='center',
va='center', fontsize=6, bbox=TEXT_BBOX)
ax3.text(74, 1.93, r'$\tau = 0$', color='k', ha='center',
va='center', fontsize=6, bbox=TEXT_BBOX)
plt.savefig(path_fig + 'RMSE_time_avg_' +
str(parameters.comm_fail_prob) + '.pdf', dpi=600, bbox_inches='tight')
elif tag == 'A':
ax3.legend(loc="upper right")
ax3.set_ylabel('ANEES')
ax3.plot([t[int(numbers/2)], t[int(numbers/2)]],
[0, 30], 'k', linewidth=2)
ax3.plot([0, t[-1]], [2, 2], 'k--')
ax3.set_ylim(bottom=0, top=30)
plt.savefig(path_fig + 'ANEES_time_avg_' +
str(parameters.comm_fail_prob) + '.pdf', dpi=600, bbox_inches='tight')
def total_mean_M(numbers, Dicts):
'''
draw average weight of M-estimation(mission 2)
:param: numbers: int, the number of simulation time
:param: Dicts: dict, the dictionary of average weight of M-estimation
'''
plt.style.use(['science', 'ieee', 'no-latex'])
t = np.arange(numbers)*DELTA_T
for rho in (0.1, 0.5, 0.9):
fig3, ax3 = plt.subplots(1, 1)
# v1.0.0, original division, black line
# ax3.plot([t[int(numbers/2)], t[int(numbers/2)]],
# [0, 1.2], 'k', linewidth=2)
# v1.1.0, divides 3 parts, ...
ax3.plot([t[int(np.ceil(numbers/3))],
t[int(np.ceil(numbers/3))]], [0, 1.2], 'k-', linewidth=2)
ax3.plot([t[int(np.ceil(2*numbers/3))],
t[int(np.ceil(2*numbers/3))]], [0, 1.2], 'k-', linewidth=2)
count = 0
for type, List in Dicts.items():
for dim in range(2):
# , marker = MARKER_STYLE[count]
ax3.plot(t, List[rho][:, dim], '-', label=MEAN_LABELS[dim],
c=EACH_COLOR[count], linewidth=1.5)
count = count + 1
ax3.set_xlabel('simulation time [s]')
ax3.set_xlim(left=0, right=(t[-1]+1e-1))
ax3.legend(loc="lower left")
ax3.set_ylabel('average weight')
ax3.set_ylim(bottom=0, top=1.2)
# v1.0.0, original division, some texts
# ax3.text(50, 1.1, r'$\rho = %.1f$' % rho, color='k',
# ha='center', va='center', bbox=TEXT_BBOX)
# ax3.text(40, 0.1, r'$\tau = 0$', color='k',
# ha='center', va='center', bbox=TEXT_BBOX)
# ax3.text(60, 0.1, r'$\tau = 0.5$', color='k',
# ha='center', va='center', bbox=TEXT_BBOX)
# v1.1.0, divides 3 parts, ...
ax3.text(50, 1, r'$\rho = %.1f$' % rho, color='k',
ha='center', va='center', bbox=TEXT_BBOX)
ax3.text(16, 1.1, r'$\tau = 0$', color='k', ha='center',
va='center', fontsize=6, bbox=TEXT_BBOX)
ax3.text(50, 1.1, r'$\tau = 0.5$', color='k', ha='center',
va='center', fontsize=6, bbox=TEXT_BBOX)
ax3.text(82, 1.1, r'$\tau = 0$', color='k', ha='center',
va='center', fontsize=6, bbox=TEXT_BBOX)
path_fig = './figures/relative-pose/'
if not os.path.exists(path_fig):
os.makedirs(path_fig)
plt.savefig(path_fig + 'weight_time_avg_' + str(rho) +
'.pdf', dpi=600, bbox_inches='tight')
plt.clf()
def each_meas_mean_(_list, tag):
'''
output RMSE of each robot over tau
:param: _list: dict, the dict of RMSE of each robot
:param: tag: str, the tag of metric, 'R' for RMSE, 'A' for ANEES
'''
path_fig = './figures/relative-pose/'
if not os.path.exists(path_fig):
os.makedirs(path_fig)
with open(path_fig + tag + '_each_' + str(parameters.comm_fail_prob) + '.csv', 'w') as f:
for type, List in _list.items():
f.write(str(type) + '\n')
np.savetxt(f, List, fmt='%.4f', newline=',')
f.write('\n')
def bias_mean_(numbers, Lists, std, tag):
'''
draw ARMSE of all algorithms over tau
:param: numbers: int, the number of simulation time
:param: Lists: dict, the dict of ARMSE-mean of each robot
:param: std: dict, the dict of ARMSE-std of each robot
:param: tag: str, the tag of metric, 'R' for RMSE, 'A' for ANEES
'''
plt.style.use(['science', 'ieee', 'muted', 'no-latex'])
path = './data/relative-pose/'
if not os.path.exists(path):
os.makedirs(path)
prob = np.arange(numbers)/20
fig3, ax3 = plt.subplots(1, 1)
count = 0
with open(path + tag + '__' + str(parameters.comm_fail_prob) + '.txt', 'w') as f:
for type, List in Lists.items():
line, = ax3.plot(
prob, List, label=LABELS[type], marker=MARKER_STYLE[count], markersize=3, c=EACH_COLOR[count], linewidth=2)
f.write(str(type) + '\t')
np.savetxt(f, List, fmt='%.4f', newline=' ')
f.write('\n')
count = count + 1
ax3.text(0.25, 3.0, r'$\rho = %.1f$' %
parameters.comm_fail_prob, color='k', ha='center', va='center')
ax3.set_xlabel(r'occurrence probability of biased measurements $\tau$')
ax3.legend(loc="upper left")
path_fig = './figures/relative-pose/'
if not os.path.exists(path_fig):
os.makedirs(path_fig)
if tag == 'R':
ax3.set_ylabel('ARMSE [m]')
ax3.set_ylim(bottom=0, top=3.2)
plt.savefig(path_fig + 'RMSE__' + str(parameters.comm_fail_prob) +
'.pdf', dpi=600, bbox_inches='tight')
elif tag == 'A':
ax3.set_ylabel('ANEES')
ax3.plot([0, prob[-1]], [2, 2], 'k--')
ax3.set_ylim(bottom=0, top=15)
plt.savefig(path_fig + 'ANEES__' + str(parameters.comm_fail_prob) +
'.pdf', dpi=600, bbox_inches='tight')