forked from winstxnhdw/KinematicBicycleModel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
85 lines (59 loc) · 2.6 KB
/
main.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
from vehicle_simulation import VehicleSimulation
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
def calculate_errors(dataList: list, models: list, vmax_range: list, constant_vel: bool = False) -> list:
all_errors_mean = {}
all_errors_std = {}
for model in models:
all_errors_mean[model] = {}
all_errors_std[model] = {}
for data in dataList:
all_errors_mean[model][data] = {}
all_errors_std[model][data] = {}
for vmax in vmax_range:
simulation = VehicleSimulation(data, model, vmax, constant_vel)
errors = simulation.calculate_error()
errors = [abs(i) for i in errors]
all_errors_mean[model][data][vmax] = np.mean(errors)
all_errors_std[model][data][vmax] = np.std(errors)
print(model + " done!")
return all_errors_mean, all_errors_std
def box_plot(data: dict, title: str):
index = 0
labels = []
boxes = []
info = []
_, ax = plt.subplots()
for outer_key in data.keys():
colour = (float(np.random.rand(1)), float(np.random.rand(1)), float(np.random.rand(1)))
info.append((outer_key, colour))
for inner_key in data[outer_key].keys():
box = ax.boxplot(data[outer_key][inner_key].values(), positions = [index], patch_artist=True)
boxes.append((box, colour))
index += 1
labels.append(inner_key)
ax.set_xticklabels(labels, rotation = 15)
for box, colour in boxes:
for patch in box['boxes']:
patch.set_facecolor(colour)
legend = []
for name, colour in info:
legend.append(mpatches.Patch(color = colour, label = name))
ax.set_ylabel("[m]")
ax.legend(handles = legend, loc = "upper left")
ax.set_title(title)
if __name__ == '__main__':
data = ["data1.csv", "data3.csv", "data5.csv"]
models = ["BicycleModel", "DubinsCar"]
vmax_range = np.linspace(3, 4, 8).tolist()
mean_values, std_values = calculate_errors(data, models, vmax_range, True)
box_plot(mean_values, "Mean values, with acceleration")
box_plot(std_values, "Standard deviations, with acceleration")
mean_values, std_values = calculate_errors(data, models, vmax_range, False)
box_plot(mean_values, "Mean values, constant velocity")
box_plot(std_values, "Standard deviations, constant velocity")
plt.show()
# For showing an animation of a simulation
# sim = VehicleSimulation("data5.csv", "DubinsCar", 3.75, True)
# sim.show_animation()