1 """Procedures for printing scenario results."""
3 import matplotlib.pyplot as plt
5 import scipy.stats as ss
11 def mean_conf_int(data, conf=0.95):
12 """Return (mean, lower, uppper) of data.
14 see https://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data
17 data -- A list of data.
18 conf -- Confidence interval.
24 h = se * ss.t.ppf((1 + conf) / 2, n - 1)
25 return (m, m - h, m + h)
27 def infoprint(w={}, t=""):
28 """Print statistic information about scenario results.
35 print("\\begin{table*}[h]")
39 print("\\begin{tabular}{", end="")
41 for k, v in w.items():
48 print("{:<14}".format("Scenarios:"), end="")
50 print("{:<12}".format("Scenarios:"), end="")
51 for k, v in w.items():
53 "{} {:<8}".format(" &" if LATEX else "", k),
56 print("\\\\" if LATEX else "")
59 print("{:<12}".format("Mean:"), end="")
60 for k, v in w.items():
62 "{} {:<8.2f}".format(" &" if LATEX else "", np.mean(v)),
65 print("\\\\" if LATEX else "")
66 print("{:<12}".format("0.95 low:"), end="")
67 for k, v in w.items():
69 "{} {:<8.2f}".format(" &" if LATEX else "", mean_conf_int(v)[1]),
72 print("\\\\" if LATEX else "")
73 print("{:<12}".format("0.95 high:"), end="")
74 for k, v in w.items():
76 "{} {:<8.2f}".format(" &" if LATEX else "", mean_conf_int(v)[2]),
79 print("\\\\" if LATEX else "")
80 print("{:<12}".format("Median:"), end="")
81 for k, v in w.items():
83 "{} {:<8.2f}".format(" &" if LATEX else "", np.median(v)),
86 print("\\\\" if LATEX else "")
87 print("{:<12}".format("0.95 perc.:"), end="")
88 for k, v in w.items():
91 " &" if LATEX else "",
92 np.percentile(v, [95])[0],
96 print("\\\\" if LATEX else "")
97 print("{:<12}".format("Minimum:"), end="")
98 for k, v in w.items():
100 "{} {:<8.2f}".format(" &" if LATEX else "", np.min(v)),
103 print("\\\\" if LATEX else "")
104 print("{:<12}".format("Maximum:"), end="")
105 for k, v in w.items():
107 "{} {:<8.2f}".format(" &" if LATEX else "", np.max(v)),
110 print("\\\\" if LATEX else "")
114 print("\\end{tabular}")
115 print("\\caption{", end="")
116 print("{}".format(t), end="")
118 print("\\end{table*}")
120 def error_infoprint(w={}, t=""):
121 """Print error information about scenario results.
129 print("{:<12}".format("Scenarios:"), end="")
130 for k, v in w.items():
131 print(" {:<8}".format(k), end="")
133 print("{:<12}".format("Rate:"), end="")
134 for k, v in w.items():
135 print(" {:<8.2f}".format(v), end="")
138 if __name__ == "__main__":
139 if len(sys.argv) > 1:
143 if len(sys.argv) > 2:
144 scenario.DNAME = sys.argv[2]
146 plt.rcParams["font.size"] = 22
147 plt.rcParams["font.family"] = "sans-serif"
148 plt.rcParams["figure.figsize"] = [12, 4]
151 infoprint(scenario.time(), "Elapsed time")
153 infoprint(scenario.cost(), "Final path cost")
154 elif w == "orig_cost":
155 infoprint(scenario.orig_cost(), "Original path cost")
157 infoprint(scenario.cusp(), "Changes in direction")
158 elif w == "orig_cusp":
159 infoprint(scenario.orig_cusp(), "Changes in direction")
161 error_infoprint(scenario.error_rate(), "Error rate")
165 "Number of iterations",
168 print("""The following arguments are allowed:
170 time, cost, orig_cost, cusp, orig_cusp, error, iter