2 """Procedures for printing scenario results."""
4 import matplotlib.pyplot as plt
6 import scipy.stats as ss
12 def mean_conf_int(data, conf=0.95):
13 """Return (mean, lower, uppper) of data.
15 see https://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data
18 data -- A list of data.
19 conf -- Confidence interval.
25 h = se * ss.t.ppf((1 + conf) / 2, n - 1)
26 return (m, m - h, m + h)
28 def infoprint(w={}, t=""):
29 """Print statistic information about scenario results.
36 print("\\begin{table*}[h]")
40 print("\\begin{tabular}{", end="")
42 for k, v in w.items():
49 print("{:<14}".format("Scenarios:"), end="")
51 print("{:<12}".format("Scenarios:"), end="")
52 for k, v in w.items():
54 "{} {:<6}".format(" &" if LATEX else "", k.replace("test", "")),
57 print("\\\\" if LATEX else "")
60 print("{:<12}".format("Mean:"), end="")
61 for k, v in w.items():
62 w[k] = [i*1000.0 for i in v]
63 for k, v in w.items():
65 "{} {:<6.2f}".format(" &" if LATEX else "", np.mean(v)),
68 print("\\\\" if LATEX else "")
69 print("{:<12}".format("0.95 low:"), end="")
70 for k, v in w.items():
72 "{} {:<6.2f}".format(" &" if LATEX else "", mean_conf_int(v)[1]),
75 print("\\\\" if LATEX else "")
76 print("{:<12}".format("0.95 high:"), end="")
77 for k, v in w.items():
79 "{} {:<6.2f}".format(" &" if LATEX else "", mean_conf_int(v)[2]),
82 print("\\\\" if LATEX else "")
83 print("{:<12}".format("Median:"), end="")
84 for k, v in w.items():
86 "{} {:<6.2f}".format(" &" if LATEX else "", np.median(v)),
89 print("\\\\" if LATEX else "")
90 print("{:<12}".format("0.95 perc.:"), end="")
91 for k, v in w.items():
94 " &" if LATEX else "",
95 np.percentile(v, [95])[0],
99 print("\\\\" if LATEX else "")
100 print("{:<12}".format("Minimum:"), end="")
101 for k, v in w.items():
103 "{} {:<6.2f}".format(" &" if LATEX else "", np.min(v)),
106 print("\\\\" if LATEX else "")
107 print("{:<12}".format("Maximum:"), end="")
108 for k, v in w.items():
110 "{} {:<6.2f}".format(" &" if LATEX else "", np.max(v)),
113 print("\\\\" if LATEX else "")
117 print("\\end{tabular}")
118 print("\\caption{", end="")
119 print("{}".format(t), end="")
121 print("\\end{table*}")
123 def error_infoprint(w={}, t=""):
124 """Print error information about scenario results.
132 print("{:<12}".format("Scenarios:"), end="")
133 for k, v in w.items():
134 print(" {:<8}".format(k), end="")
136 print("{:<12}".format("Rate:"), end="")
137 for k, v in w.items():
138 print(" {:<8.2f}".format(v), end="")
141 if __name__ == "__main__":
142 if len(sys.argv) > 1:
146 if len(sys.argv) > 2:
147 scenario.DNAME = sys.argv[2]
149 plt.rcParams["font.size"] = 22
150 plt.rcParams["font.family"] = "sans-serif"
151 plt.rcParams["figure.figsize"] = [12, 4]
154 infoprint(scenario.time(), "Elapsed time")
156 infoprint(scenario.otime(), "Elapsed time")
158 infoprint(scenario.cost(), "Final path cost")
159 elif w == "orig_cost":
160 infoprint(scenario.orig_cost(), "Original path cost")
162 infoprint(scenario.cusp(), "Changes in direction")
163 elif w == "orig_cusp":
164 infoprint(scenario.orig_cusp(), "Changes in direction")
166 error_infoprint(scenario.error_rate(), "Error rate")
170 "Number of iterations",
173 print("""The following arguments are allowed:
175 time, cost, orig_cost, cusp, orig_cusp, error, iter