-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplot-tests.py
59 lines (43 loc) · 1.37 KB
/
plot-tests.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
from sklearn.externals import joblib
from matplotlib import pyplot as plt
import argparse
def configure_axis(ax):
ax.set_xlabel('Generations')
ax.set_ylabel('Fitness')
ax.grid()
def plot_max(ax, gen, fit_max, color, label):
ax.plot(gen, fit_max, color, label=label)
ax.legend()
def plot_std(ax, gen, fit_std, color, label):
ax.plot(gen, fit_std, color, label=label)
ax.legend(loc='upper right')
def plot_avg(ax, gen, fit_avg, color, label):
ax.plot(gen, fit_avg, color, label=label)
ax.legend()
ap = argparse.ArgumentParser()
ap.add_argument('-t', '--tests', required=True, nargs=3)
args = vars(ap.parse_args())
colors = ['b-', 'g-', 'r-']
labels = ['Baboon', 'Jet', 'Pepper']
gen = list()
fit_max = list()
fit_std = list()
fit_avg = list()
for t in args['tests']:
pkl = joblib.load(t)
lb = pkl['logbook']
gen.append(lb.select('gen'))
fit_max.append(lb.select('max'))
fit_std.append(lb.select('std'))
fit_avg.append(lb.select('avg'))
(figure, axes) = plt.subplots(1, 3)
axes[0].set_title('Max individuals')
axes[1].set_title('Avg individuals')
axes[2].set_title('Std individuals')
for ax in axes:
configure_axis(ax)
for (c, l, g, fmax, fstd, favg) in zip(colors, labels, gen, fit_max, fit_std, fit_avg):
plot_max(axes[0], g, fmax, c, l)
plot_avg(axes[1], g, favg, c, l)
plot_std(axes[2], g, fstd, c, l)
plt.show()