DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.69k stars 1.11k forks source link

How to create an "individual" consisting of integers, floats and trees and mutate it #543

Open e-milio-it opened 3 years ago

e-milio-it commented 3 years ago

I need to find the best fitness for a population made up of integers, floats and trees. I use integers and floats to validate indicators (true and false Booleans) and the tree to best combine the Boolean indicators. I need to change both the integers and the floats and the tree at the same time. How can I do? Sorry but I'm new to DEAP and genetic programming at 60. Thanks to those who will help me showing the way.

creator.create("FitnessMulti", base.Fitness, weights=(1.0, -1.0, 1.0, 1.0)) creator.create("Individual", list, fitness=creator.FitnessMulti)

pset = gp.PrimitiveSetTyped("mainingresso", [bool, bool, bool], bool) pset.addPrimitive(operator.xor, [bool, bool], bool) pset.addPrimitive(operator.and, [bool, bool], bool) pset.addPrimitive(operator.or_, [bool, bool], bool)

toolbox.register("rulein_1", random.randint, 1, 13) toolbox.register("rulein_1_v1", random.uniform, 0, 1000) toolbox.register("rulein_1_v2", random.uniform, 0, 1000) toolbox.register("rulein_1_v3", random.uniform, 0, 1000) toolbox.register("rulein_2", random.randint, 1, 13) toolbox.register("rulein_2_v1", random.uniform, 0, 1000) toolbox.register("rulein_2_v2", random.uniform, 0, 1000) toolbox.register("rulein_2_v3", random.uniform, 0, 1000) toolbox.register("rulein_3", random.randint, 1, 13) toolbox.register("rulein_3_v1", random.uniform, 0, 1000) toolbox.register("rulein_3_v2", random.uniform, 0, 1000) toolbox.register("rulein_3_v3", random.uniform, 0, 1000) toolbox.register("rulein_rel", random.randint, 1, 4) toolbox.register("ruleout_1", random.randint, 1, 3) toolbox.register("ruleout_1_v1", random.uniform, 0, 1000) toolbox.register("ruleout_1_v2", random.uniform, 0, 1000) toolbox.register("ruleout_1_v3", random.uniform, 0, 1000) toolbox.register("rel_rulesin", gp.genHalfAndHalf, pset=pset, min=1, max_=5)

toolbox.register("individual", tools.initCycle, creator.Individual, (toolbox.rulein_1, toolbox.rulein_1_v1, toolbox.rulein_1_v2, toolbox.rulein_1_v3, toolbox.rulein_2, toolbox.rulein_2_v1, toolbox.rulein_2_v2, toolbox.rulein_2_v3, toolbox.rulein_3, toolbox.rulein_3_v1, toolbox.rulein_3_v2, toolbox.rulein_3_v3, toolbox.rulein_rel, toolbox.ruleout_1, toolbox.ruleout_1_v1, toolbox.ruleout_1_v2, toolbox.ruleout_1_v3, toolbox.rel_rules_in), n=1)

toolbox.register("population", tools.initRepeat, list, toolbox.individual)

toolbox.register("evaluate", evalTS)

toolbox.register("mate", tools.cxTwoPoint)

toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)

toolbox.register("select", tools.selNSGA2)

fmder commented 2 years ago

Best fitness for NSGA-II does not exists. You'll have a handfull of non-dominated solutions which are all tradeoffs of your multiple objectives. You'll have to hand pick the one that you prefer or implement a way to aggregate the objectives into one via a weighted sum.