From 67a0a69350bd6e3ad9384680fe7a6dc9f9876683 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Wed, 27 Sep 2017 23:37:37 +0100 Subject: [PATCH] Plot best fitness - Print epochs throughout run - Introduce wait parameter --- src/main.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 84f3fb5..5869027 100644 --- a/src/main.py +++ b/src/main.py @@ -1,13 +1,33 @@ +import os import argparse 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.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() 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() 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()