# Register the mutation operator
# Experiment with changing the strategy.
toolbox.register("mutate", deap.tools.mutPolynomialBounded, eta=ETA,low=LOWER, up=UPPER, indpb=0.1)
# Register the variate operator
toolbox.register("variate", deap.algorithms.varAnd)
#select the best
sel=toolbox.register("select", ind_selector, selector=tools.selBest)
# Generate the population object
pop = toolbox.population(n=MU)
hof = tools.HallOfFame(1)
stats = tools.Statistics(lambda ind: ind.fitness.values)
of=Objective_functions()
for gen in range(NGEN):
offspring = algorithms.varAnd(pop, toolbox, cxpb=CXPB, mutpb=1-CXPB)
fits = toolbox.map(toolbox.evaluate, offspring)
for fit, ind in zip(fits, offspring):
ind.fitness.values = fit
print ' generation # ', gen
print ' fitness, index ', fit, ind, offspring
pop = toolbox.select(offspring, k=len(pop))
top10 = tools.selBest(pop, k=10)
def tupleize(func):
"""A decorator that tuple-ize the result of a function. This is useful
when the evaluation function returns a single value.
"""
def wrapper(*args, **kargs):
return func(*args, **kargs),
return wrapper
def main(func, dim, maxfuncevals, ftarget=None):
toolbox = base.Toolbox()
toolbox.register("update", update)
toolbox.register("evaluate", func)
toolbox.decorate("evaluate", tupleize)
evaluate
method a flexible number of parameters. I changed the evaluate method signature to look like this now def evaluate(individual,IND_SIZE):
toolbox.register("evaluate", evaluate,IND_SIZE=IND_SIZE)
def evaluate(individual,param_dict,tve={},tvel=[]):
toolbox.register("evaluate", evaluate,param_dict=param_dict,tve=target_versus_error,tvel=target_versus_errorls)
fitnesses = toolbox.map(toolbox.evaluate, population)