Deap python package: create individuals with different ranges and mix of integers and floats

十年热恋 提交于 2019-12-03 16:18:13

You can simply do as follows to create chromosomes of multiple types:

toolbox.register("attr_int", random.randint, 0, 1)
toolbox.register("attr_flt", random.uniform, 0, 2)
toolbox.register("individual", tools.initCycle, creator.Individual,
             (toolbox.attr_int, toolbox.attr_flt),
             n=1)

and then create a population of size 100:

toolbox.register("population", tools.initRepeat, list, toolbox.individual)
population = toolbox.population(n=100)
Sebastian

So, I have created the chromosomes which are a mix of integer and float. Now, after a generation is evaluated, you have the mutate and mate operators, which create new chromosomes. However, I do not know how to create these operators such that they are also a mix of integers and floats. This is the function to create chromosomes.

def uniform(float_min, float_max, int_max, N_inputs):
    """ function to create individual """
    integers  = list(numpy.random.randint(0, int_max, N_inputs))    
    floats = list(numpy.random.uniform(float_min, float_max, N_inputs))

    return integers+ floats

I need not to register mutate and mate:

toolbox.register("mate", deap.tools.???)
toolbox.register("mutate", deap.tools.???)

Hope you can help me. Cheers Sebastian

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!