X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hubacji1/iamcar.git/blobdiff_plain/4cd76d28e4706b809f8399f0335ecfd0bfb70b77..HEAD:/gplot.py diff --git a/gplot.py b/gplot.py index c5c4651..1e90051 100644 --- a/gplot.py +++ b/gplot.py @@ -5,12 +5,22 @@ 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 +# sh - reeds and shepp, same heading + +# ad - optimize with dijkstra, all nodes +# as - optimize with smart, all nodes +# ar - optimize with remove redundant points, all nodes +# cd - optimize with dijkstra, cusp nodes +# cs - optimize with smart, cusp nodes +# cr - optimize with remove redundant points, cusp nodes LOGF = "log_wo" LOG = [ - {"f": "rs", "c": "orange", "l": "Reeds and Shepp path length cost"}, - {"f": "sh", "c": "blue", "l": "Reeds and Shepp same heading cost"}, - {"f": "ed", "c": "red", "l": "Euclidean distance cost"}, + {"f": "T2", "c": "orange", "l": "T2"}, ] r = {} @@ -61,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. @@ -107,13 +133,27 @@ 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 = {} for a in r.keys(): v[a] = get_lasts_if_exist(r[a], "cost") - plt.rcParams["font.size"] = 24 fig = plt.figure() ax = fig.add_subplot(111) ax.set_title("Path cost histogram") @@ -145,13 +185,12 @@ def plot_maxtime(): for a in r.keys(): v[a] = get_lasts_if_exist(r[a], "secs") - plt.rcParams["font.size"] = 24 fig = plt.figure() ax = fig.add_subplot(111) - ax.set_title("Path found time histogram") + ax.set_title("Histogram of time to find the path") ax.set_ylabel("Number of paths found [-]") - ax.set_xlabel("Algorithm elapsed time [s]") + ax.set_xlabel("Algorithm computation time [s]") ax.set_yscale("log") for a in LOG: @@ -171,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={} @@ -197,4 +266,6 @@ if __name__ == "__main__": r = {} for sf in [i["f"] for i in LOG]: r[sf] = load_trajectories("{}/{}".format(LOGF, sf)) + print_successrate() plot_maxtime() + plot_costdist()