-
Notifications
You must be signed in to change notification settings - Fork 4
/
plot_data.py
217 lines (196 loc) · 8.96 KB
/
plot_data.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
import numpy as np
from scipy.interpolate import interp1d
from numpy import polyfit, poly1d
import matplotlib.pyplot as plt
import os
"""
Patrick Phillips summer 2019
email: pphill10@u.rochester.edu
website: https://github.com/peweetheman
"""
interp = False # true plots interpolation, false doesn't
poly_fit = True # true plots polynomial fit of data, false doesn't
pathlength = "40.0"
runtime = "0.25"
PI, RRT, PRM, RRT_star, PRM_star = True, True, True, True, True
data_PI, data_PRM, data_PRM_star, data_RRT, data_RRT_star = None, None, None, None, None
if PI:
PI_filename = os.path.join('data', 'PI_runtime' + '0.25' + '_pathlength' + pathlength + '_' + '0' + '.npy')
data_PI = np.load(PI_filename)
data_PI = np.delete(data_PI, 0, 1)
if PRM_star:
PRM_star_filename = os.path.join('data', 'PRM_star_runtime' + runtime + '_pathlength' + pathlength + '_' + '0' + '.npy')
data_PRM_star = np.load(PRM_star_filename)
data_PRM_star = np.delete(data_PRM_star, 0, 1)
if RRT_star:
RRT_star_filename = os.path.join('data', 'RRT_star_runtime' + runtime + '_pathlength' + pathlength + '_' + '0' + '.npy')
data_RRT_star = np.load(RRT_star_filename)
data_RRT_star = np.delete(data_RRT_star, 0, 1)
if PRM:
PRM_filename = os.path.join('data', 'PRM_runtime' + runtime + '_pathlength' + pathlength + '_' + '0' + '.npy')
data_PRM = np.load(PRM_filename)
data_PRM = np.delete(data_PRM, 0, 1)
if RRT:
RRT_filename = os.path.join('data', 'RRT_runtime' + runtime + '_pathlength' + pathlength + '_' + '0' + '.npy')
data_RRT = np.load(RRT_filename)
data_RRT = np.delete(data_RRT, 0, 1)
for i in range(1, 66):
if PI:
PI_filename = os.path.join('data', 'PI_runtime' + '0.25' + '_pathlength' + pathlength + '_' + str(i) + '.npy')
new_data_PI = np.load(PI_filename)
new_data_PI = np.delete(new_data_PI, 0, 1)
data_PI = np.concatenate((data_PI, new_data_PI), axis=1)
if PRM_star:
PRM_star_filename = os.path.join('data', 'PRM_star_runtime' + runtime + '_pathlength' + pathlength + '_' + str(i) + '.npy')
new_data_PRM_star = np.load(PRM_star_filename)
new_data_PRM_star = np.delete(new_data_PRM_star, 0, 1)
data_PRM_star = np.concatenate((data_PRM_star, new_data_PRM_star), axis=1)
if RRT_star:
RRT_star_filename = os.path.join('data', 'RRT_star_runtime' + runtime + '_pathlength' + pathlength + '_' + str(i) + '.npy')
new_data_RRT_star = np.load(RRT_star_filename)
new_data_RRT_star = np.delete(new_data_RRT_star, 0, 1)
data_RRT_star = np.concatenate((data_RRT_star, new_data_RRT_star), axis=1)
if PRM:
PRM_filename = os.path.join('data', 'PRM_runtime' + runtime + '_pathlength' + pathlength + '_' + str(i) + '.npy')
new_data_PRM = np.load(PRM_filename)
new_data_PRM = np.delete(new_data_PRM, 0, 1)
data_PRM = np.concatenate((data_PRM, new_data_PRM), axis=1)
if RRT:
RRT_filename = os.path.join('data', 'RRT_runtime' + runtime + '_pathlength' + pathlength + '_' + str(i) + '.npy')
new_data_RRT = np.load(RRT_filename)
new_data_RRT = np.delete(new_data_RRT, 0, 1)
data_RRT = np.concatenate((data_RRT, new_data_RRT), axis=1)
if PI:
data_PI = data_PI[:, data_PI[0].argsort()]
if PRM_star:
data_PRM_star = data_PRM_star[:, data_PRM_star[0].argsort()]
if RRT_star:
data_RRT_star = data_RRT_star[:, data_RRT_star[0].argsort()]
if PRM:
data_PRM = data_PRM[:, data_PRM[0].argsort()]
if RRT:
data_RRT = data_RRT[:, data_RRT[0].argsort()]
fig1 = plt.figure(figsize=(9, 4))
xnew = np.linspace(1.1, float(pathlength)-1.5, num=100, endpoint=True)
#### FIRST PLOT OF TOTAL VARIANCE (INCLUDES VARIANCE OF COEFFICIENTS IN GMRF MEAN FUNCTION APPROX)
ax0 = fig1.add_subplot(221)
ax0.set_title('Path length vs. Total Variance (averaged over 100 trials on randomized fields)')
plt.xlabel('Path Length (m)')
plt.ylabel('Total Variance')
if interp:
if PI:
f_PI = interp1d(data_PI[0, :], data_PI[1, :])
plt.plot(xnew, f_PI(xnew), '-', label='PI interpolation')
if PRM_star:
f_PRM_star = interp1d(data_PRM_star[0, :], data_PRM_star[1, :])
plt.plot(xnew, f_PRM_star(xnew), '-', label='PRM* interpolation')
if RRT_star:
f_RRT_star = interp1d(data_RRT_star[0, :], data_RRT_star[1, :])
plt.plot(xnew, f_RRT_star(xnew), '-', label='RRT* interpolation')
if PRM:
f_PRM = interp1d(data_PRM[0, :], data_PRM[1, :])
plt.plot(xnew, f_PRM(xnew), '-', label='PRM interpolation')
if RRT:
f_RRT = interp1d(data_RRT[0, :], data_RRT[1, :])
plt.plot(xnew, f_RRT(xnew), '-', label='RRT interpolation')
if poly_fit:
if PI:
p_PI = np.poly1d(np.polyfit(data_PI[0, :], data_PI[1, :], 10))
plt.plot(xnew, p_PI(xnew), '--', label='PI polynomial fit')
if PRM_star:
p_PRM_star = np.poly1d(np.polyfit(data_PRM_star[0, :], data_PRM_star[1, :], 10))
plt.plot(xnew, p_PRM_star(xnew), '--', label='PRM* polynomial fit')
if RRT_star:
p_RRT_star = np.poly1d(np.polyfit(data_RRT_star[0, :], data_RRT_star[1, :], 10))
plt.plot(xnew, p_RRT_star(xnew), '--', label='RRT* polynomial fit')
if PRM:
p_PRM = np.poly1d(np.polyfit(data_PRM[0, :], data_PRM[1, :], 10))
plt.plot(xnew, p_PRM(xnew), '--', label='PRM polynomial fit')
if RRT:
p_RRT = np.poly1d(np.polyfit(data_RRT[0, :], data_RRT[1, :], 10))
plt.plot(xnew, p_RRT(xnew), '--', label='RRT polynomial fit')
handles, labels = ax0.get_legend_handles_labels()
ax0.legend(handles[::-1], labels[::-1])
#### SECOND PLOT OF JUST THE FIELD VARIANCE
ax1 = fig1.add_subplot(222)
ax1.set_title('Path length vs. Field Variance (averaged over 100 trials on randomized fields)')
plt.xlabel('Path Length (m)')
plt.ylabel('Field Variance')
# plt.scatter(data_PI[0, :], data_PI[2, :], color='blue', label='PI data')
# plt.scatter(data_PRM_star[0, :], data_PRM_star[2, :], color='yellow', label='PRM_star data')
if interp:
if PI:
f_PI = interp1d(data_PI[0, :], data_PI[2, :])
plt.plot(xnew, f_PI(xnew), '-', label='PI interpolation')
if PRM_star:
f_PRM_star = interp1d(data_PRM_star[0, :], data_PRM_star[2, :])
plt.plot(xnew, f_PRM_star(xnew), '-', label='PRM* interpolation')
if RRT_star:
f_RRT_star = interp1d(data_RRT_star[0, :], data_RRT_star[2, :])
plt.plot(xnew, f_RRT_star(xnew), '-', label='RRT* interpolation')
if PRM:
f_PRM = interp1d(data_PRM[0, :], data_PRM[2, :])
plt.plot(xnew, f_PRM(xnew), '-', label='PRM interpolation')
if RRT:
f_RRT = interp1d(data_RRT[0, :], data_RRT[2, :])
plt.plot(xnew, f_RRT(xnew), '-', label='RRT interpolation')
if poly_fit:
if PI:
p_PI = np.poly1d(np.polyfit(data_PI[0, :], data_PI[2, :], 10))
plt.plot(xnew, p_PI(xnew), '--', label='PI polynomial fit')
if PRM_star:
p_PRM_star = np.poly1d(np.polyfit(data_PRM_star[0, :], data_PRM_star[2, :], 10))
plt.plot(xnew, p_PRM_star(xnew), '--', label='PRM* polynomial fit')
if RRT_star:
p_RRT_star = np.poly1d(np.polyfit(data_RRT_star[0, :], data_RRT_star[2, :], 10))
plt.plot(xnew, p_RRT_star(xnew), '--', label='RRT* polynomial fit')
if PRM:
p_PRM = np.poly1d(np.polyfit(data_PRM[0, :], data_PRM[2, :], 10))
plt.plot(xnew, p_PRM(xnew), '--', label='PRM polynomial fit')
if RRT:
p_RRT = np.poly1d(np.polyfit(data_RRT[0, :], data_RRT[2, :], 10))
plt.plot(xnew, p_RRT(xnew), '--', label='RRT polynomial fit')
handles, labels = ax1.get_legend_handles_labels()
ax1.legend(handles[::-1], labels[::-1])
#### THIRD PLOT OF ROOT MEAN SQUARED ERROR BETWEEN GMRF APPROXIMATION AND TRUE FIELD
ax2 = fig1.add_subplot(223)
ax2.set_title('Path length vs. RMSE (averaged over 100 trials on randomized fields)')
plt.xlabel('Path Length (m)')
plt.ylabel('RMSE')
# plt.scatter(data_PI[0, :], data_PI[3, :], color='blue', label='PI data')
# plt.scatter(data_PRM_star[0, :], data_PRM_star[3, :], color='yellow', label='PRM_star data')
if interp:
if PI:
f_PI = interp1d(data_PI[0, :], data_PI[3, :])
plt.plot(xnew, f_PI(xnew), '-', label='PI interpolation')
if PRM_star:
f_PRM_star = interp1d(data_PRM_star[0, :], data_PRM_star[3, :])
plt.plot(xnew, f_PRM_star(xnew), '-', label='PRM* interpolation')
if RRT_star:
f_RRT_star = interp1d(data_RRT_star[0, :], data_RRT_star[3, :])
plt.plot(xnew, f_RRT_star(xnew), '-', label='RRT* interpolation')
if PRM:
f_PRM = interp1d(data_PRM[0, :], data_PRM[3, :])
plt.plot(xnew, f_PRM(xnew), '-', label='PRM interpolation')
if RRT:
f_RRT = interp1d(data_RRT[0, :], data_RRT[3, :])
plt.plot(xnew, f_RRT(xnew), '-', label='RRT interpolation')
if poly_fit:
if PI:
p_PI = np.poly1d(np.polyfit(data_PI[0, :], data_PI[3, :], 10))
plt.plot(xnew, p_PI(xnew), '--', label='PI polynomial fit')
if PRM_star:
p_PRM_star = np.poly1d(np.polyfit(data_PRM_star[0, :], data_PRM_star[3, :], 10))
plt.plot(xnew, p_PRM_star(xnew), '--', label='PRM* polynomial fit')
if RRT_star:
p_RRT_star = np.poly1d(np.polyfit(data_RRT_star[0, :], data_RRT_star[3, :], 10))
plt.plot(xnew, p_RRT_star(xnew), '--', label='RRT* polynomial fit')
if PRM:
p_PRM = np.poly1d(np.polyfit(data_PRM[0, :], data_PRM[3, :], 10))
plt.plot(xnew, p_PRM(xnew), '--', label='PRM polynomial fit')
if RRT:
p_RRT = np.poly1d(np.polyfit(data_RRT[0, :], data_RRT[3, :], 10))
plt.plot(xnew, p_RRT(xnew), '--', label='RRT polynomial fit')
handles, labels = ax2.get_legend_handles_labels()
ax2.legend(handles[::-1], labels[::-1])
plt.show()