def xorevaluate(genome: Genome): genome.cleaner() table = [([0, 0], [0]), ([0, 1], [1]), ([1, 0], [1]), ([1, 1], [0])] score = 0.0 episodes = 20 for _ in range(episodes): shuffle(table) for experience in table: x, y = experience[0], experience[1] output = genome.forward(x) score += abs(output[0] - y[0]) return score
def experience1(): # Experience 1 genome = Genome(input_size=2, output_size=1) genome.nodes += [Node(), Node(), Node()] genome.connections += [ Connection(0, 3, 0.0), Connection(0, 4, 0.0), Connection(0, 5, 0.0), Connection(1, 3, 0.0), Connection(1, 4, 0.0), Connection(1, 5, 0.0), Connection(3, 2, 0.0), Connection(4, 2, 0.0), Connection(5, 2, 0.0) ] fitter = Fitter(genome=genome, evaluate=xorevaluate) genome = fitter.fit(episode=5000, timebreak=300, scorebreak=0.1) genome.cleaner() table = [([0, 0], [0]), ([0, 1], [1]), ([1, 0], [1]), ([1, 1], [0])] score = 0 for _ in range(20): shuffle(table) for experience in table: x, y = experience[0], experience[1] output = genome.forward(x) score += abs(output[0] - y[0]) print(x, ' : ', output) print('score : ', score) print(genome.print_graph()) criterions = ['scores', 'familysizes', 'episodetimes'] for crit in criterions: plt.plot(fitter.history[crit], label=crit) mean = [ np.mean(fitter.history[crit]) for _ in range(len(fitter.history[crit])) ] plt.plot(mean, label=crit + '_mean') plt.xlabel('episode') plt.ylabel(crit) plt.show()