-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot_statistics.py
executable file
·65 lines (53 loc) · 1.93 KB
/
plot_statistics.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
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
import json
import sys
import os
if __name__ == '__main__':
if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
filename = sys.argv[1]
f = open(filename, 'r')
data = json.loads(f.read())
f.close()
species = data['species']
n_species = len(species)
n_generations = 1
for i in range(n_species):
s = np.array(species[i])
n_generations = int(max(n_generations, np.max(s[:,0])+1))
min_max_gen = np.zeros([n_species,2])
sizes = np.zeros([n_generations,n_species])
fitness = np.zeros([n_generations,n_species])
for i in range(n_species):
s = np.array(species[i])
#print(s)
min_gen = int(s[0,0])
max_gen = int(s[-1,0])
min_max_gen[i,:] = np.array([min_gen, max_gen])
sizes[min_gen:max_gen+1,i] = s[:,1]
plt.figure()
xmin = np.min(min_max_gen)
xmax = np.max(min_max_gen)
plt.subplot(3, 1, 1)
plt.barh(np.arange(n_species), min_max_gen[:,1]-min_max_gen[:,0], left=min_max_gen[:,0], alpha=0.8, height=1.0, facecolor='b', edgecolor='k')
plt.grid(True)
plt.xlim(xmin, xmax)
plt.ylabel('Species')
plt.subplot(3, 1, 2)
for i in range(n_species):
s = np.array(species[i])
plt.plot(s[:,0],s[:,2])
plt.grid(True)
plt.xlim(xmin, xmax)
plt.ylabel('Fitness')
plt.subplot(3, 1, 3)
plt.stackplot(np.arange(n_generations),sizes.T, alpha=0.4)
plt.xlim(xmin, xmax)
plt.ylabel('Population/Species Size')
plt.xlabel('Generation')
plt.show()
else:
print('nothing found')
# ./run_xor.py && ./plot_statistics.py ./results/XorTask/statistics.json
# ./plot_statistics.py results/XorTask_4/statistics.json