Ejemplo n.º 1
0
def score_generation(gen):
    """score the generation over a period from start to end"""
    periods = [random.randint(61,550) for n in xrange(10)]
    scores = []
    for bot in gen:
        avg_score = 0.0
        for period in periods:
            score = simulator.simulate_bot(bot, period, period+5, simulator.data)
            avg_score += score
        avg_score = avg_score/float(len(periods))
        scores.append((avg_score, bot))
    scores.sort(key=lambda e:e[0])
    scores.reverse()
    return scores
Ejemplo n.º 2
0
def score_generation(gen):
    """score the generation over a period from start to end"""
    periods = [random.randint(61, 550) for n in xrange(10)]
    scores = []
    for bot in gen:
        avg_score = 0.0
        for period in periods:
            score = simulator.simulate_bot(bot, period, period + 5,
                                           simulator.data)
            avg_score += score
        avg_score = avg_score / float(len(periods))
        scores.append((avg_score, bot))
    scores.sort(key=lambda e: e[0])
    scores.reverse()
    return scores
Ejemplo n.º 3
0
def optimize(pop_size, num_gens, num_survivors, verbose = True):
    """Use an asexual genetic algo to optimize the bots."""
    standard_period = 40 #standardize one testing period, to track progress
    gen = initialize_population(pop_size)
    num_children = int(pop_size/num_survivors)-1
    for n in tqdm.tqdm(range(num_gens)):
        scores = score_generation(gen)
        survivors = [e[1] for e in scores[:num_survivors]]
        if verbose == True:
            score = scores[0][0]
            std_score = simulator.simulate_bot(scores[0][1], standard_period, standard_period+5, simulator.data)
            print "Generation {},\tScore:{}\tStd score:{}".format(n+1,score,std_score)
        #print survivors
        gen = make_generation(survivors,num_children)
    return scores
Ejemplo n.º 4
0
def optimize(pop_size, num_gens, num_survivors, verbose=True):
    """Use an asexual genetic algo to optimize the bots."""
    standard_period = 40  #standardize one testing period, to track progress
    gen = initialize_population(pop_size)
    num_children = int(pop_size / num_survivors) - 1
    for n in tqdm.tqdm(range(num_gens)):
        scores = score_generation(gen)
        survivors = [e[1] for e in scores[:num_survivors]]
        if verbose == True:
            score = scores[0][0]
            std_score = simulator.simulate_bot(scores[0][1], standard_period,
                                               standard_period + 5,
                                               simulator.data)
            print "Generation {},\tScore:{}\tStd score:{}".format(
                n + 1, score, std_score)
        #print survivors
        gen = make_generation(survivors, num_children)
    return scores