Plot best fitness

- Print epochs throughout run
- Introduce wait parameter
This commit is contained in:
George Lacey 2017-09-27 23:37:37 +01:00
parent ecd8e35888
commit 67a0a69350

View File

@ -1,13 +1,33 @@
import os
import argparse import argparse
from population import Population from population import Population
from time import sleep
import matplotlib.pyplot as plt
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
best_fit = list()
args = argparse.ArgumentParser() args = argparse.ArgumentParser()
args.add_argument("pop", help="Population size", type=int) args.add_argument("pop", help="Population size", type=int)
args.add_argument("iter", help="Iterations", type=int)
args.add_argument("-w", "--wait", help="Time in seconds to wait between iterations", type=int, default=0)
args = args.parse_args() args = args.parse_args()
pop = Population(args.pop) pop = Population(args.pop)
for i in range(0, 1000): for i in range(0, args.iter):
cls()
print("Epoch: %d " % i)
pop.advance_generation() pop.advance_generation()
best = pop.best_fitness() best = pop.best_fitness()
print(pop) best_fit.append(pop.best_fitness().fitness())
sleep(args.wait)
plt.plot(best_fit)
plt.xlabel("Epoch")
plt.ylabel("Fitness")
plt.show()