-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdisplay.py
69 lines (51 loc) · 1.67 KB
/
display.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
from matplotlib import pyplot as plt
import numpy as np
def histogram(generations: list, **kwargs):
"""
Display GA Histogram of single run.
Args:
generations (list): GA run generation's fittest fitnesses.
**kwargs (kwargs): Single argument woc is accepted.
"""
figure = plt.figure()
ax = figure.add_subplot(1, 1, 1)
# Generations
x = list(range(len(generations)))
y = generations
ax.plot(x, y, color='black')
if 'woc' in kwargs:
ax.plot([0, len(generations)], [kwargs['woc'], kwargs['woc']], color='blue')
plt.xlim([0, len(generations)])
ymin = round(min(generations), 1)
plt.ylim([ymin, 1])
plt.yticks(np.arange(round(min(y), 1), 1 + 0.01, 0.01))
# Labels
plt.xlabel('generation')
plt.ylabel('fitness')
plt.title('GA Fittest Histogram')
def histograms(*args, **kwargs):
"""
Display GA Histogram of multiple runs.
Args:
*args (args): Arguments should be lists containing generations fittest fitnesses.
**kwargs (kwargs): Single argument woc is accepted.
"""
figure = plt.figure()
ax = figure.add_subplot(1, 1, 1)
for generations in args:
# Generations
x = list(range(len(generations)))
y = generations
ax.plot(x, y, color='black')
if 'woc' in kwargs:
ax.plot([0, len(args[0])], [kwargs['woc'], kwargs['woc']], color='blue')
plt.xlim([0, len(args[0])])
ymin = round(min(g[0] for g in args), 1)
plt.ylim([ymin, 1])
plt.yticks(np.arange(ymin, 1 + 0.01, 0.01))
# Labels
plt.xlabel('generation')
plt.ylabel('fitness')
plt.title('GA Fittests Histogram')
def show():
plt.show()