-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhow_many_embedded.py
63 lines (52 loc) · 2.16 KB
/
how_many_embedded.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
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
names = [str(i) for i in range(1, 8)]
embedded = []
average_generations = []
# --- Prepare data
for name in names:
filename = f'./data_after_bug_fix/k8_popsize/howManyGenerations_5x5_10_600gen_k8popsize{name}.txt'
with open(filename, 'r') as f:
data = f.read().splitlines()
data = [int(value) for value in data]
# unique, counts = np.unique(data, return_counts=True)
embedded.append(100 - data.count(-1))
data_embedded = [value for value in data if value != -1]
average_generations.append(np.average(data_embedded))
# --- Plot setup
plt.rcParams.update({
"text.usetex": True,
"font.family": "Helvetica"
})
# https://stackoverflow.com/a/39566040/9655481
MEDIUM_SIZE = 8
MEDIUM_SIZE = 14
BIGGER_SIZE = 16
plt.rc('font', size=MEDIUM_SIZE) # controls default text sizes
plt.rc('axes', titlesize=MEDIUM_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=MEDIUM_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
# --- Plot
color = '#E53054'
fig, ax = plt.subplots(figsize=(10, 6))
ax.set_ylabel('Occurrences of valid embeddings')
ax.set_xlabel('Probability of using the "extend to free neighbor" mutation')
ax.set_ylim(0, 100)
# ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
# ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))
ax.plot(names, embedded, color, marker='o')
# Write average number of generations needed next to data point
# https://queirozf.com/entries/add-labels-and-text-to-matplotlib-plots-annotation-examples
for i, v in enumerate(average_generations):
ax.annotate(str(round(v, 0)),
(i, embedded[i]),
textcoords='offset points',
xytext=(0, -22),
horizontalalignment='center')
# ax.set_title('Generations needed for the crossed house puzzle')
plt.tight_layout()
plt.show()