deap.algorithms模块库官方文档库翻译

Algorithms

算法模块旨在包含一些特定的算法,以便执行非常常见的进化算法。这里使用的方法更多是为了方便而非参考,因为每个进化算法的实现可能会无限变化。本模块中的大多数算法使用工具箱中注册的运算符。通常,用于交叉的关键字是mate(),用于突变的关键字是mutate(),选择的关键字是select(),求值的关键字是evaluate()。

鼓励编写自己的算法。

Complete Algorithms

这些是完全的装箱算法,在某种程度上局限于非常基本的进化计算概念。所有算法除了参数之外,还接受一个初始化的Statistics对象来维护进化的统计数据,一个初始化HallOfFame来保存种群中出现的最佳个体,以及一个布尔verbose来指定是否记录进化过程中发生的事情。

deap.algorithms。eaSimple(population,toolbox,cxpb,mutpb,ngen[,stats,halloffame,verbose])

Parameters:

  • population – A list of individuals.

  • toolbox – A Toolbox that contains the evolutionoperators.

  • cxpb – The probability of mating two individuals.

  • mutpb – The probability of mutating an individual.

  • ngen – The number of generation.

  • stats – A Statistics object that is updatedinplace, optional.在适当位置更新的Statistics对象,可选。

  • halloffame – A HallOfFame object that willcontain the best individuals, optional.

  • verbose – Whether or not to log the statistics.

Returns:

The final population

Returns:

A class:~deap.tools.Logbook with the statistics of theevolution

该算法接受一个群体,并使用varAnd()方法将其进化到位。它返回优化的种群和包含进化统计信息的日志。日志将包含生成编号、每一代的评估数量以及统计数据(如果提供统计数据作为参数)。cxpb和mutpb参数传递给varAnd()函数。伪代码如下所示

evaluate(population)
for g in range(ngen):
    population = select(population, len(population))
    offspring = varAnd(population, toolbox, cxpb, mutpb)
    evaluate(offspring)
    population = offspring

如上面的伪代码所述。首先,它评估具有无效适应度的个体。第二,它进入了迭代循环,在这个循环中,选择程序被用来完全取代父代。该算法的1:1替换比例要求选择过程是随机的,并且需要多次选择同一个个体,例如,selTournament()和selRoulette()。第三,它应用varAnd()函数生成下一代种群。第四,它评估新的个体,并计算该群体的统计数据。最后,当ngen生成完成后,算法返回一个包含最终种群和进化日志的元组。

此函数要求在工具箱中注册toolbox.mate()、toolbox.amute()、toolbox.select()和toolbox.avalate()别名。

deap.algorithms.eaMuPlusLambda

(population, toolbox, mu, lambda_, cxpb, mutpb, ngen[, stats, halloffame, verbose])

这是(μ+λ)进化算法。

Parameters:

  • population – A list of individuals.

  • toolbox – A Toolbox that contains the evolutionoperators.

  • mu – The number of individuals to select for the next generation.

  • lambda_ – The number of children to produce at each generation.

  • cxpb – The probability that an offspring is produced by crossover.

  • mutpb – The probability that an offspring is produced by mutation.

  • ngen – The number of generation.

  • stats – A Statistics object that is updatedinplace, optional.

  • halloffame – A HallOfFame object that willcontain the best individuals, optional.

  • verbose – Whether or not to log the statistics.

Returns:

The final population

Returns:

A class:~deap.tools.Logbook with the statistics of theevolution.

该算法接受一个群体,并使用varOr()函数将其进化到位。它返回优化的种群和包含进化统计信息的日志。日志将包含生成编号、每一代的评估数量以及统计数据(如果提供统计数据作为参数)。cxpb和mutpb参数传递给varOr()函数。伪代码如下所示

evaluate(population)
for g in range(ngen):
    offspring = varOr(population, toolbox, lambda_, cxpb, mutpb)
    evaluate(offspring)
    population = select(population + offspring, mu)

首先,对具有无效适应度的个体进行评估。第二,进化循环开始于从种群中产生lambda_后代,后代由varOr()函数生成。然后对后代进行评估,并从后代和种群中选择下一代种群。最后,当ngen生成完成后,算法返回一个包含最终种群和进化日志的元组。

此函数要求在工具箱中注册toolbox.mate()、toolbox.amute()、toolbox.select()和toolbox.avaluate()别名。此算法使用varOr()变量。

deap.algorithms.eaMuCommaLambda(population, toolbox, mu, lambda_, cxpb, mutpb, ngen[, stats, halloffame, verbose])

这是(μ,λ)进化算法。

Parameters:

  • population – A list of individuals.

  • toolbox – A Toolbox that contains the evolutionoperators.

  • mu – The number of individuals to select for the next generation.

  • lambda_ – The number of children to produce at each generation.

  • cxpb – The probability that an offspring is produced by crossover.

  • mutpb – The probability that an offspring is produced by mutation.

  • ngen – The number of generation.

  • stats – A Statistics object that is updatedinplace, optional.

  • halloffame – A HallOfFame object that willcontain the best individuals, optional.

  • verbose – Whether or not to log the statistics.

Returns:

The final population

Returns:

A class:~deap.tools.Logbook with the statistics of theevolution

该算法接受一个群体,并使用varOr()函数将其进化到位。它返回优化的种群和包含进化统计信息的日志。日志将包含生成编号、每一代的评估数量以及统计数据(如果提供统计数据作为参数)。cxpb和mutpb参数传递给varOr()函数。伪代码如下所示

evaluate(population)
for g in range(ngen):
    offspring = varOr(population, toolbox, lambda_, cxpb, mutpb)
    evaluate(offspring)
    population = select(offspring, mu)

deap.algorithms.eaGenerateUpdate(toolbox, ngen[, stats, halloffame, verbose])

This is algorithm implements the ask-tell model proposed in[Colette2010], where ask is called generate and tell is called update.

Parameters:

  • toolbox – A Toolbox that contains the evolutionoperators.

  • ngen – The number of generation.

  • stats – A Statistics object that is updatedinplace, optional.

  • halloffame – A HallOfFame object that willcontain the best individuals, optional.

  • verbose – Whether or not to log the statistics.

Returns:

The final population

Returns:

A class:~deap.tools.Logbook with the statistics of theevolution

该算法使用toolbox.generate()函数生成个体,并使用toolbox.update()函数更新生成方法。它返回优化的种群和包含进化统计信息的日志。日志将包含生成编号、每一代的评估数量以及统计数据(如果提供统计数据作为参数)。伪代码如下所示

for g in range(ngen):
    population = toolbox.generate()
    evaluate(population)
    toolbox.update(population)

Variations

变体是算法的较小部分,可以单独用于构建更复杂的算法。

deap.algorithms.varAnd(population, toolbox, cxpb, mutpb)

进化算法的一部分,仅应用变异部分(交叉和变异)。修改后的个体的适应度无效。个体被克隆,因此返回的种群独立于输入种群。

Parameters:

  • population – A list of individuals to vary.

  • toolbox – A Toolbox that contains the evolutionoperators.

  • cxpb – The probability of mating two individuals.

  • mutpb – The probability of mutating an individual.

Returns:

A list of varied individuals that are independent of theirparents.

变化如下。首先,使用toolbox.clone()方法复制亲代群体Pp,并将结果放入后代群体Po中。在Po上执行第一个循环以配对成对的连续个体。根据交叉概率cxpb,使用toolbox.mate()方法对个体xi和xi+1进行交配。由此产生的后代yi和yi+1取代了他们各自在Po的父母。在生成的Po上执行第二个循环,以概率mutpb对每个个体进行变异。当一个个体发生突变时,它会替换Po中未发生突变的版本。生成的Po返回。

这种变异被命名为And,因为它倾向于在个体身上同时应用交叉和突变。注意,这两种算子都没有系统地应用,生成的个体可以根据给定的概率从仅交叉、仅突变、交叉和突变以及繁殖中生成。两种概率都应在[0,1]内

deap.algorithms.varOr(population, toolbox, lambda_, cxpb, mutpb)

进化算法的一部分,只应用变异部分(交叉、变异或繁殖)。修改后的个体的适应度无效。个体被克隆,因此返回的种群独立于输入种群。

Parameters:

  • population – A list of individuals to vary.

  • toolbox – A Toolbox that contains the evolutionoperators.

  • lambda_ – The number of children to produce

  • cxpb – The probability of mating two individuals.

  • mutpb – The probability of mutating an individual.

Returns:

The final population.

变化如下。在每个lambda迭代中,它选择三个操作中的一个;交叉、突变或繁殖。在交叉的情况下,从父母群体Pp中随机选择两个个体,使用toolbox.clone()方法克隆这些个体,然后使用toolbox.mate()方法交配。只有第一个孩子被附加到后代群体Po,第二个孩子被丢弃。在突变的情况下,从Pp中随机选择一个个体,克隆该个体,然后使用toolbox.amutate()方法进行突变。产生的突变体被附加到Po上。在复制的情况下,从Pp中随机选择一个个体,克隆并附加到Po

.

这种变异被命名为“Or”,因为杂交和突变两种操作都不会产生后代。两种概率之和应为[0,1]

,繁殖概率为1-cxpb-mutpb。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值