Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Python 上使用了 deap 库来处理遗传算法。例如:我有个人[0,1,1,1,1,0],我有3种突变方法,例如mutation1,mutation2,mutation3。使用deap库,我进行如下突变:
for mutate in [mutate1, mutate2, mutate3]: mutate(individual)
每种变异方法后如何保存人口数据?此外,我正在尝试使用deap.logbook它,但它不起作用。有人对此有什么建议吗?
deap.logbook
您可以打开 3 个文件,并在每种方法之后的每次迭代中将总体追加到正确的文件中。
files = ['path/to/method_1', 'path/to/method_2', 'path/to/method_3'] files_list = [open(i, 'a+') for i in files] for mutate in range(len([mutate1, mutate2, mutate3])): mutated = mutate[i](individual) files[i].write(mutated)