]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Fix error rate in plot costs
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 7 Dec 2020 16:37:32 +0000 (17:37 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 7 Dec 2020 16:39:03 +0000 (17:39 +0100)
scripts/plot.py
scripts/scenario.py

index f748e79cd437efe63ea6acdb78e778598b582984..64a65501ae6886aa7c5c8175e08c61050e61a269 100644 (file)
@@ -61,13 +61,13 @@ def boxplots(w2=[]):
     ax.set_xlabel("Elapsed time [s]")
     ax.set_ylabel("Cost [m]")
 
-    err_hist = [0 for i in range(19)]
-    val_list = [[] for i in range(19)]
-    m = len(w[key][0])
+    M = len(w[key][0])
+    err_hist = [0 for i in range(M)]
+    val_list = [[] for i in range(M)]
     mi = 999999999999
     ma = -1
     for i in range(len(w[key])):
-        for j in range(m):
+        for j in range(M):
             if w[key][i][j] == 0:
                 err_hist[j] += 1
             else:
@@ -77,22 +77,23 @@ def boxplots(w2=[]):
                 if v > ma: ma = v
     print("min: {}, max: {}".format(mi, ma))
 
-    maxes = [max(val_list[i]) for i in range(19)]
-    mins = [min(val_list[i]) for i in range(19)]
-    average = [np.average(val_list[i]) for i in range(19)]
+    maxes = [max(val_list[i]) for i in range(M)]
+    MAX = max(maxes)
+    mins = [min(val_list[i]) for i in range(M)]
+    average = [np.average(val_list[i]) for i in range(M)]
     # 95 and 5 are not used
-    perct_95 = [np.percentile(val_list[i], [95])[0] for i in range(19)]
-    perct_5 = [np.percentile(val_list[i], [5])[0] for i in range(19)]
+    perct_95 = [np.percentile(val_list[i], [95])[0] for i in range(M)]
+    perct_5 = [np.percentile(val_list[i], [5])[0] for i in range(M)]
     # percentiles by 10 %
-    perct_10 = [np.percentile(val_list[i], [10])[0] for i in range(19)]
-    perct_20 = [np.percentile(val_list[i], [20])[0] for i in range(19)]
-    perct_30 = [np.percentile(val_list[i], [30])[0] for i in range(19)]
-    perct_40 = [np.percentile(val_list[i], [40])[0] for i in range(19)]
-    perct_50 = [np.percentile(val_list[i], [50])[0] for i in range(19)]
-    perct_60 = [np.percentile(val_list[i], [60])[0] for i in range(19)]
-    perct_70 = [np.percentile(val_list[i], [70])[0] for i in range(19)]
-    perct_80 = [np.percentile(val_list[i], [80])[0] for i in range(19)]
-    perct_90 = [np.percentile(val_list[i], [90])[0] for i in range(19)]
+    perct_10 = [np.percentile(val_list[i], [10])[0] for i in range(M)]
+    perct_20 = [np.percentile(val_list[i], [20])[0] for i in range(M)]
+    perct_30 = [np.percentile(val_list[i], [30])[0] for i in range(M)]
+    perct_40 = [np.percentile(val_list[i], [40])[0] for i in range(M)]
+    perct_50 = [np.percentile(val_list[i], [50])[0] for i in range(M)]
+    perct_60 = [np.percentile(val_list[i], [60])[0] for i in range(M)]
+    perct_70 = [np.percentile(val_list[i], [70])[0] for i in range(M)]
+    perct_80 = [np.percentile(val_list[i], [80])[0] for i in range(M)]
+    perct_90 = [np.percentile(val_list[i], [90])[0] for i in range(M)]
 
     # find index of the closest to average path
     average_i = [
@@ -107,7 +108,7 @@ def boxplots(w2=[]):
 
     # plot percentiles
     ax.fill_between(
-        range(1, 20),
+        range(1, M+1),
         mins,
         maxes,
         color="tab:orange",
@@ -115,7 +116,7 @@ def boxplots(w2=[]):
         label="Minimum and maximum, optimized",
     )
     ax.fill_between(
-        range(1, 20),
+        range(1, M+1),
         perct_10,
         perct_90,
         color="tab:orange",
@@ -123,7 +124,7 @@ def boxplots(w2=[]):
         label="10 % and 90 % percentile, optimized",
     )
     ax.fill_between(
-        range(1, 20),
+        range(1, M+1),
         perct_20,
         perct_80,
         color="tab:orange",
@@ -131,7 +132,7 @@ def boxplots(w2=[]):
         label="20 % and 80 % percentile, optimized",
     )
     ax.fill_between(
-        range(1, 20),
+        range(1, M+1),
         perct_30,
         perct_70,
         color="tab:orange",
@@ -139,7 +140,7 @@ def boxplots(w2=[]):
         label="30 % and 70 % percentile, optimized",
     )
     ax.fill_between(
-        range(1, 20),
+        range(1, M+1),
         perct_40,
         perct_60,
         color="tab:orange",
@@ -148,14 +149,14 @@ def boxplots(w2=[]):
     )
     # plot median and average
     ax.plot(
-        range(1, 20),
+        range(1, M+1),
         perct_50,
         color="tab:orange",
         alpha=1,
         label="50 % percentile (median), optimized",
     )
     ax.plot(
-        range(1, 20),
+        range(1, M+1),
         average,
         color="tab:red",
         alpha=1,
@@ -163,14 +164,14 @@ def boxplots(w2=[]):
     )
     # plot average before path optimization
     ax.plot(
-        range(1, 20),
-        [np.average([i for i in no_opt[key].values()]) for i in range(1, 20)],
+        range(1, M+1),
+        [np.average([i for i in no_opt[key].values()]) for i in range(1, M+1)],
         label="Average cost before optimization",
         color="tab:blue",
         linestyle="--",
     )
 
-    plt.xticks(range(1, 20), ["{:.2f}".format(0.1 * (k+1)) for k in range(m)])
+    plt.xticks(range(1, M+1), ["{:.2f}".format(0.1 * (k+1)) for k in range(M)])
     ax.minorticks_on()
 
     plt.rcParams["font.size"] = 21
index 3654626399f5fd6d58dbb6f8c670f1b72e25ce5f..5400ad2bb3ce8927b464d0ef8ed7b1e642fa7632 100644 (file)
@@ -166,10 +166,21 @@ def costs():
     """Return the dictionary of ``fname``'s and corresponding costs."""
     r = greps("log_path_cost")
     r2 = {}
-    i = 1
+    M = 0
+    MV = 0
+    it = {}
     for k, v in r.items():
-        r2[PNAME[i]] = v
-        i += 1
+        for k2, v2 in v.items():
+            M = max(M, len(v2))
+    for k, v in r.items():
+        for k2, v2 in v.items():
+            if len(v2) == M:
+                it[k2] = v2
+            else:
+                MV = max(MV, M - len(v2))
+                it[k2] = [0 for i in range(M - len(v2))]
+                it[k2].extend(v2)
+    r2[PNAME[1]] = it
     r = greps("path_cost_before_opt")
     r3 = {}
     i = 1