affinity_search/ga_addrequests.py
def runGA(pop):
    '''run GA with early stopping if not improving'''    
    hof = tools.HallOfFame(10)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", np.mean)
    stats.register("std", np.std)
    stats.register("min", np.min)
    stats.register("max", np.max)
    best = 0
    pop = toolbox.clone(pop)
    for i in range(40):
        pop, log = algorithms.eaMuPlusLambda(pop, toolbox, mu=300, lambda_=300, cxpb=0.5, mutpb=0.2, ngen=25, 
                                       stats=stats, halloffame=hof, verbose=True)
        newmax = log[-1]['max']
        if best == newmax:
            break
        best = newmax
    return pop
run GA with early stopping if not improving
run GA with early stopping if not improving
run GA with early stopping if not improving
def runGA(pop):
    hof = tools.HallOfFame(10)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", np.mean)
    stats.register("std", np.std)
    stats.register("min", np.min)
    stats.register("max", np.max)
    best = 0
    pop = toolbox.clone(pop)
    for i in range(40):
        pop, log = algorithms.eaMuPlusLambda(pop, toolbox, mu=300, lambda_=300, cxpb=0.5, mutpb=0.2, ngen=25, 
                                       stats=stats, halloffame=hof, verbose=True)
        newmax = log[-1]['max']
        if best == newmax:
            break
        best = newmax
    return pop
def runGA ( pop ) : hof = tools . HallOfFame ( 10 ) stats = tools . Statistics ( lambda ind : ind . fitness . values ) stats . register ( "avg" , np . mean ) stats . register ( "std" , np . std ) stats . register ( "min" , np . min ) stats . register ( "max" , np . max ) best = 0 pop = toolbox . clone ( pop ) for i in range ( 40 ) : pop , log = algorithms . eaMuPlusLambda ( pop , toolbox , mu = 300 , lambda_ = 300 , cxpb = 0.5 , mutpb = 0.2 , ngen = 25 , stats = stats , halloffame = hof , verbose = True ) newmax = log [ - 1 ] [ 'max' ] if best == newmax : break best = newmax return pop
run GA with early stopping if not improving
run GA with early stopping if not improving
'''run GA with early stopping if not improving'''
pop