我正在尝试使用 DEAP 来最大化函数。
我明白如何用基本示例来做到这一点:
toolbox.register("attr_bool", random.randint, 0, 1)
toolbox.register("individual", tools.initRepeat, creator.Individual,
toolbox.attr_bool, 100)
它创建 100 个随机值或 0 或 1。然后你继续创建一个群体并变异......
当你有两个参数时,如何建立一个群体:
parameter 1 integer with range [0,1]
parameter 2 float with range [0,2]
然后结合两个随机采样的参数创建一个个体?或者对于具有任意步长值的参数 2 样本,例如 0.25。
您可以简单地执行以下操作来创建多种类型的染色体:
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)
然后创建一个大小为 100 的总体:
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
population = toolbox.population(n=100)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)