pset = gp.PrimitiveSet("MAIN", arity=n, prefix='x') pset.addPrimitive(operators.addition, 2) pset.addPrimitive(operators.subtract, 2) pset.addPrimitive(operators.multiply, 2) # and many more... # One optimization objective. creator.create("FitnessMin", base.Fitness, weights=(-1.0,)) # Arithmetic expression. creator.create("Tree", gp.PrimitiveTree, pset=pset) # Individual is a list consisting of n_components trees. creator.create("Individual", list, fitness=creator.FitnessMin) toolbox = base.Toolbox() toolbox.register("expr", gp.genHalfAndHalf, pset=pset, min_=MIN_TREE_HEIGHT, max_=MAX_TREE_HEIGHT) toolbox.register("tree", tools.initIterate, creator.Tree, toolbox.expr) toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.tree, n=pop_size) # Population. toolbox.register("population", tools.initRepeat, list, toolbox.individual)
7.0 is necessary? @fmder . If I don't insert 7 it gives me an error
def feasible(individual): """Feasability function for the individual. Returns True if feasible False otherwise.""" if int(individual) < int(individual): return True return False toolbox.register("evaluate", evalOneMax) toolbox.decorate("evaluate", tools.DeltaPenality(feasible,7.0))
Diversity strongly depends on your response domain. If your population converges too fast you can try to play with crossover and mutation parameters. Moreover having selection with randomness (like tournament with a low number of participant) may help.
Hi everyOne, I am new to DEAP library. I am trying to make an independent evolutionary core that works with the external app. This is a process I want to have:
1.Population variables and their fitness values production in an external app
2.passing the Population and fitness to the DEAP core to do the selection, mutation, and mating process and making a new offspring.
3.passing the offsprings to the external app and, as a response getting the fitness value.
And doing this process in a loop to reach the final goal. The problem that I have is that I don't, know how can I create a population from defined individual values. In all examples, POPULATIONS are created from random functions. Is there any way to generate a population from a defined set of variables and defining the fitness attribute for them?