-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_noise.py
178 lines (159 loc) · 5.85 KB
/
plot_noise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import json
from os import listdir
from os.path import isfile, join
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.lines import Line2D
plt.rc('font', **{'family': 'sans-serif', 'size': 7.5})
plt.rc('text', usetex=True)
plt.rc('axes', edgecolor='black', linewidth=0.4, axisbelow=True)
plt.rc('xtick', **{'direction': 'out', 'major.width': 0.4})
plt.rc('ytick', **{'direction': 'in', 'major.width': 0.4})
def load_file(path):
f = open(path)
data = json.load(f)
f.close()
return data
def read_files(mypath):
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
if "noise_level_dist.pdf" in onlyfiles:
onlyfiles.remove("noise_level_dist.pdf")
return onlyfiles
def plot_noise(dataset):
data = []
names = []
for i, (name, values, percentages) in enumerate(dataset):
x = []
y = []
cutoffrate = 0
for i in range(len(values)):
if percentages[i] > cutoffrate:
x.append(values[i])
y.append(percentages[i])
data.append(x)
names.append(name)
cm = 1/2.54
plt.figure(figsize=(18.5*cm, 4*cm), dpi=300)
# print(str(len(y))+" kernels used from "+str(len(values)))
ylabel = plt.ylabel("Noise $n$ [$\%$]\nRange of relative deviation")
x, y = ylabel.get_position()
ylabel.set_position((x, y-0.05))
# plt.ylabel("percentage of total runtime of the kernel")
arrowstyle = {'arrowstyle': '-',
'relpos': (0, 0.5), 'shrinkA': 0, 'shrinkB': 5, 'linewidth': 0.4}
violins = plt.violinplot(data, [1, 2, 3, 4, 5, 6])
for b in violins['bodies']:
b.set_facecolor((0, 0, 255 / 255, 1))
b.set_alpha(0.2)
for l in [violins['cbars'], violins['cmins'], violins['cmaxes']]:
l.set_color((0.3, 0.3, 255 / 255, 1))
l.set_linewidth(0.8)
for x, y in zip([1, 2, 3, 4, 5, 6], [np.max(d) for d in data]):
xy = (x + 0.15, y)
va = 'center'
if x == 1:
xy = (x + 0.15, 62)
if x == 3:
xy = (x + 0.15, 62)
if x == 4:
xy = (x + 0.15, 62)
if x == 5:
xy = (x + 0.15, 62)
if x == 6:
xy = (x + 0.15, 62)
plt.annotate(r"$n_{\mathrm{max}}="+f"{y: .2f}$", (x, y), xytext=xy,
arrowprops=arrowstyle if x != 2 else None, va=va)
mean_hndl = plt.plot([1, 2, 3, 4, 5, 6], [np.mean(d)
for d in data], 'x', color=(1, 0.1, 0.1, 1))
for x, y in zip([1, 2, 3, 4, 5, 6], [np.mean(d) for d in data]):
xy = (x + 0.15, y)
if x == 1:
xy = (x + 0.15, 42)
if x == 2:
xy = (x + 0.15, 42)
if x == 3:
xy = (x + 0.15, 42)
if x == 4:
xy = (x + 0.15, 42)
if x == 5:
xy = (x + 0.15, 42)
if x == 6:
xy = (x + 0.15, 42)
plt.annotate(fr"$\bar{{n}}={y:.2f}$", (x, y), xytext=xy,
arrowprops=arrowstyle, va='center')
median_hndl = plt.plot([1, 2, 3, 4, 5, 6], [np.median(d)
for d in data], '_', color=(1, 0.55, 0.1, 1))
for x, y in zip([1, 2, 3, 4, 5, 6], [np.median(d) for d in data]):
xy = (x + 0.15, y)
if x == 1:
xy = (x + 0.15, 22)
if x == 2:
xy = (x + 0.15, 22)
if x == 3:
xy = (x + 0.15, 22)
if x == 4:
xy = (x + 0.15, 22)
if x == 5:
xy = (x + 0.15, 22)
if x == 6:
xy = (x + 0.15, 22)
plt.annotate(fr"$\tilde{{n}}={y:.2f}$", (x, y), xytext=xy,
arrowprops=arrowstyle, va='center')
for x, y in zip([1, 2, 3, 4, 5, 6], [np.min(d) for d in data]):
#xy = (x + 0.15, y)
#if x != 2:
xy = (x + 0.15, 7)
plt.annotate(r"$n_{\mathrm{min}}="+f"{y:.2f}$", (x, y), xytext=xy,
va='center')
plt.xticks([1, 2, 3, 4, 5, 6], names)
plt.yticks([0, 25, 50, 75, 100, 125, 150])
plt.xlim(0.7, 6.75)
plt.ylim(-5, 165)
plt.tight_layout(pad=0)
max_hndl = Line2D([0, 1], [0, 1], marker=3, color=(
0.3, 0.3, 255 / 255, 1), linewidth=0.8)
min_hndl = Line2D([0, 1], [0, 1], marker=2, color=(
0.3, 0.3, 255 / 255, 1), linewidth=0.8)
leg = plt.legend([max_hndl, mean_hndl[0], median_hndl[0], min_hndl],
[r'maximum $n_{\mathrm{max}}$', r'mean $\bar{n}$',
r'median $\tilde{n}$', r'minimum $n_{\mathrm{min}}$'],
loc='upper left', bbox_to_anchor=(0.02, 0.98), markerscale=0.6, handlelength=1.2, handletextpad=0.4, labelspacing=0.2, fancybox=False, borderpad=0.2)
leg.get_frame().set_linewidth(0.4)
plt.grid(axis='y', linewidth=0.4, color=(0.8, 0.8, 0.8, 1))
plt.savefig("noise_level_dist.pdf")
plt.show()
plt.close()
def main():
files = read_files(".")
dataset = []
for f in files:
x_label = ""
if "minife" in f:
x_label = "MiniFE\n(Lichtenberg)"
elif "lulesh" in f:
x_label = "LULESH\n(Lichtenberg)"
elif "kripke" in f:
x_label = "Kripke\n(Vulcan)"
elif "relearn" in f:
x_label = "RELeARN\n(Lichtenberg)"
elif "quicksilver" in f:
x_label = "Quicksilver\n(Lichtenberg)"
elif "fastest" in f:
x_label = "FASTEST\n(SuperMUC)"
x = (
x_label,
load_file(f)["noise"],
load_file(f)["probability"]
)
dataset.append(x)
new_dataset = []
new_dataset.append(dataset[3])
new_dataset.append(dataset[0])
new_dataset.append(dataset[1])
new_dataset.append(dataset[2])
new_dataset.append(dataset[4])
new_dataset.append(dataset[5])
plot_noise(new_dataset)
if __name__ == "__main__":
main()