Commit a27f5f98 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Fix stats

parent c34bd89d
......@@ -83,18 +83,22 @@ pset.addPrimitive(, [int, int], bool, name='lt')
pset.addPrimitive(, [int, int], bool, name='gt')
def evaluateIndividual(individual):
fn = gp.compile(individual, pset)
player = GPPlayer(fn)
game = Game()
scores = [game.play_game(player) for i in range(GAMES_PER_INDIVIDUAL)]
scores = np.array([game.play_game(player) for i in range(GAMES_PER_INDIVIDUAL)]).transpose()
return tuple(map(np.median, list(zip(*scores))))
ret_val = (np.median(scores[0]), # total sum of tiles
np.max(scores[1]), # max tile
np.median(scores[2])) # fitness calc result
return ret_val
creator.create("FitnessMax", base.Fitness, weights=(0.1, 1.0, 0.5))
creator.create("FitnessMax", base.Fitness, weights=(0.2, 1.0, 0.2))
creator.create("Individual", gp.PrimitiveTree, fitness=creator.FitnessMax)
toolbox = base.Toolbox()
......@@ -149,7 +153,7 @@ def main():
stats.register("std", stats_std)
stats.register("avg", stats_avg)
algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=40, stats=stats, halloffame=hof)
algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=400, stats=stats, halloffame=hof)
return pop, hof, stats
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment