def printStatsPredators(self,pop,gen): fits = [ind.fitness.values[0] for ind in pop] mean = sum(fits) / len(pop) stats.add("predator_fitness.avg",mean) stats.add("predator_fitness.min",min(fits)) stats.add("predator_fitness.max",max(fits)) return ("(%3i): Max: %6.2f, Avg: %6.2f, Min: %5.2f" % (gen, max(fits), mean, min(fits)))
def printStatsPredators(self, pop, gen): fits = [ind.fitness.values[0] for ind in pop] mean = sum(fits) / len(pop) stats.add("predator_fitness.avg", mean) stats.add("predator_fitness.min", min(fits)) stats.add("predator_fitness.max", max(fits)) return ("(%3i): Max: %6.2f, Avg: %6.2f, Min: %5.2f" % (gen, max(fits), mean, min(fits)))
def _record_stats(self, world): stats.add(self._game_type(), int(world.time / 1000))
.format(e, EPISODES, agent.epsilon, quality, len(agent.memory), len(agent.memory_done), time_sum/100.0) print(msg_str) logger.info(msg_str) print("quality: {:0.2f}".format(quality)) if quality_max < quality: quality_max = quality # if quality_max > 15.0: # logger.info("Saving weights @ episode: {}/{}, quality: {:0.2f}".format(e, EPISODES, quality)) # agent.save("/tmp/" + thisName + ".h5") time_sum = 0.0 score_sum = 0.0 score_cnt = 0.0 time.sleep(2) break stats.add(e, game.moves, game.score, game.score / 100.0, agent.epsilon, len(agent.memory_done)) if int(e / 100) * 100 == e: stats.flush() steps_wo_r = 0 if len(agent.memory) > BATCH_SIZE: #print "agent.replay.." agent.replay(BATCH_SIZE) for elem in stats_arr: e = elem[0] v = elem[1] i = int(v) sys.stdout.write("# %-10i | %s (%0.2f)\n" % (e, '=' * i, v))
def printStatsCreatures(self, pop, gen, dba, dbb, dbp): fits = [ind.fitness.values[0] for ind in pop] mean = sum(fits) / len(pop) reds = [funcs.gene2color(genome[-1]) for genome in pop] greens = [funcs.gene2color(genome[-2]) for genome in pop] blues = [funcs.gene2color(genome[-3]) for genome in pop] stats.add("creature_fitness.avg", mean) stats.add("creature_fitness.min", min(fits)) stats.add("creature_fitness.max", max(fits)) stats.add("creature.death_by_bush_procent", dbb * 1.0 / (dbb + dba + dbp)) stats.add("creature.death_by_predator_procent", dbp * 1.0 / (dbb + dba + dbp)) stats.add("creature_color.red", sum(reds) / len(reds)) stats.add("creature_color.blue", sum(blues) / len(blues)) stats.add("creature_color.green", sum(greens) / len(greens)) return ("(%3i): Max: %6.2f, Avg: %6.2f, Min: %5.2f, DBBP: %.2f" % (gen, max(fits), mean, min(fits), dbb * 1.0 / (dbb + dbp + dba)))
def printStatsCreatures(self,pop,gen,dba,dbb,dbp): fits = [ind.fitness.values[0] for ind in pop] mean = sum(fits) / len(pop) reds = [funcs.gene2color(genome[-1]) for genome in pop] greens = [funcs.gene2color(genome[-2]) for genome in pop] blues = [funcs.gene2color(genome[-3]) for genome in pop] stats.add("creature_fitness.avg",mean) stats.add("creature_fitness.min",min(fits)) stats.add("creature_fitness.max",max(fits)) stats.add("creature.death_by_bush_procent",dbb*1.0/(dbb+dba+dbp)) stats.add("creature.death_by_predator_procent",dbp*1.0/(dbb+dba+dbp)) stats.add("creature_color.red", sum(reds)/len(reds)) stats.add("creature_color.blue", sum(blues)/len(blues)) stats.add("creature_color.green", sum(greens)/len(greens)) return ("(%3i): Max: %6.2f, Avg: %6.2f, Min: %5.2f, DBBP: %.2f" % (gen, max(fits), mean, min(fits),dbb*1.0/(dbb+dbp+dba)))