Plot best fitness
- Print epochs throughout run - Introduce wait parameter
This commit is contained in:
parent
ecd8e35888
commit
67a0a69350
24
src/main.py
24
src/main.py
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user