forked from alexanderbodard/P-O3-NILM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
28 lines (24 loc) · 1.02 KB
/
demo.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
import pickle
import matplotlib.pyplot as plt
import os
from metalearning import Population, Rectangles, NeuralNetwork
def plot_best_evolution(meta_folder="Rectangles/Rectangles", n=10):
n_generations = len([name for name in os.listdir(meta_folder) if os.path.isfile(os.path.join(meta_folder, name))])
average = []
for gen in range(n_generations):
with open(meta_folder + f"/generation_{gen}.pickle", "rb") as file:
p = pickle.load(file)
a= []
for i in enumerate(p.fits):
a.append(i)
a = sorted(a, key=lambda x: x[1])
b = sum(list(map(lambda x: x[1], a[:n])))/n*10
average.append(b)
plt.scatter(list(range(1, n_generations+1)), average)
plt.plot(list(range(1, n_generations+1)), average)
plt.hlines(1.56235, xmin=0, xmax=n_generations+1)
plt.xlim(left=0)
plt.xlim(right=n_generations+1)
plt.ylim(bottom = min(average) * 0.9)
plt.ylim(top= max(average) * 1.1)
plt.show()