]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/blobdiff - gplot.py
Merge branch 'release/0.7.0'
[hubacji1/iamcar.git] / gplot.py
index 69c1e902c8d5715a0bccec603f16996098d55d79..1e9005163fd5603cd68578bfa81a3745b8f56d71 100644 (file)
--- a/gplot.py
+++ b/gplot.py
@@ -5,6 +5,7 @@ from matplotlib import pyplot as plt
 from os import listdir
 from sys import argv, exit
 import numpy as np
+import scipy.stats as ss
 
 # ed - euclidean distance
 # rs - reeds and shepp path length
@@ -19,13 +20,7 @@ import numpy as np
 
 LOGF = "log_wo"
 LOG = [
-    {"f": "rs", "c": "orange", "l": "Reeds and Shepp path length"},
-    {"f": "sh", "c": "blue", "l": "Reeds and Shepp same heading"},
-    {"f": "ed", "c": "red", "l": "Euclidean distance"},
-#    {"f": "ed", "c": "orange", "l": "No optimization"},
-#    {"f": "ar", "c": "green", "l": "Remove redundant points"},
-#    {"f": "as", "c": "blue", "l": "Smart"},
-#    {"f": "cd", "c": "red", "l": "Dijkstra on cusp nodes"},
+    {"f": "T2", "c": "orange", "l": "T2"},
 ]
 
 r = {}
@@ -76,6 +71,22 @@ def gplot():
     plt.show()
     #plt.savefig("WHATEVER")
 
+def mean_conf_int(data, conf=0.95):
+    """Return (mean, lower, uppper) of data.
+
+    see https://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data
+
+    Keyword arguments:
+    data -- A list of data.
+    conf -- Confidence interval.
+    """
+    a = np.array(data)
+    n = len(a)
+    m = np.mean(a)
+    se = ss.sem(a)
+    h = se * ss.t.ppf((1 + conf) / 2, n - 1)
+    return (m, m - h, m + h)
+
 def count_if_exist(trajectories, what):
     """From multiple trajectories compute the number of occurences.
 
@@ -122,6 +133,21 @@ def get_maxs_if_exist(trajectories, what):
             pass
     return val
 
+def get_val_if_exist(trajectories, what):
+    """From m ultiple trajectories get value.
+
+    Keyword arguments:
+    trajectories -- The list of trajectories.
+    what -- What to take.
+    """
+    val = []
+    for t in trajectories:
+        try:
+            val.append(t[what])
+        except:
+            pass
+    return val
+
 def plot_costdist():
     """Plot distribution of last costs across measured tests."""
     v = {}
@@ -184,6 +210,36 @@ def plot_maxtime():
     plt.legend()
     plt.show()
 
+def plot_nothingdone():
+    """Plot *nothing done* time of ``overlaptrees`` procedure."""
+    v = {}
+    for a in r.keys():
+        v[a] = get_lasts_if_exist(r[a], "nodo")
+
+    fig = plt.figure()
+    ax = fig.add_subplot(111)
+    ax.set_title("Histogram of nothing-done-time")
+
+    ax.set_ylabel("Occurences [-]")
+    ax.set_xlabel("Nothing-done-time percentage [-]")
+
+    for a in LOG:
+        plt.hist(
+                v[a["f"]],
+                alpha = 0.5,
+                label = a["l"],
+                bins = np.arange(0, 1, 0.1),
+                histtype = "step",
+                color = a["c"])
+        try:
+                X_WHERE = np.percentile(v[a["f"]], [95])
+                plt.axvline(X_WHERE, lw=1, color=a["c"], linestyle="--")
+        except:
+                pass
+
+    plt.legend()
+    plt.show()
+
 def print_nofnodes():
     """Print average number of nodes."""
     v={}
@@ -207,7 +263,6 @@ def print_successrate():
         print("{}: {}".format(a["f"], v[a["f"]]))
 
 if __name__ == "__main__":
-    plt.rcParams["font.size"] = 29
     r = {}
     for sf in [i["f"] for i in LOG]:
         r[sf] = load_trajectories("{}/{}".format(LOGF, sf))