python DEAP学习4(遗传算法)函数使用

Evolutionary Tools

The tools module contains the operators for evolutionary algorithms. They are used to modify, select and move the individuals in their environment. The set of operators it contains are readily usable in the Toolbox. In addition to the basic operators this module also contains utility tools to enhance the basic algorithms with StatisticsHallOfFame, and History.

tools模块中toolbox里面包含遗传算法的操作算子,可以用来选择个体、使个体发生变异或者直接删除个体,另外还有一些基本操作在Statistics、HallOfFame和History里面。

Operators

The operator set does the minimum job for transforming or selecting individuals. This means, for example, that providing two individuals to the crossover will transform those individuals in-place. The responsibility of making offspring(s) independent of their parent(s) and invalidating the fitness is left to the user and is generally fulfilled in the algorithms by calling toolbox.clone() on an individual to duplicate it and del on the values attribute of the individual’s fitness to invalidate it.

Here is a list of the implemented operators in DEAP,

下面是DEAP里面内的操作算子,看起来很强大…怎么用还是慢慢摸索吧….

Initialization Crossover Mutation Selection Migration
initRepeat()cxOnePoint()mutGaussian()selTournament()migRing()
initIterate()cxTwoPoint()mutShuffleIndexes()selRoulette() 
initCycle()cxUniform()mutFlipBit()selNSGA2() 
 cxPartialyMatched()mutPolynomialBounded()selSPEA2() 
 cxUniformPartialyMatched()mutUniformInt()selRandom() 
 cxOrdered()mutESLogNormal()selBest() 
 cxBlend() selWorst() 
 cxESBlend() selTournamentDCD() 
 cxESTwoPoint() selDoubleTournament() 
 cxSimulatedBinary() selStochasticUniversalSampling() 
 cxSimulatedBinaryBounded() selLexicase() 
 cxMessyOnePoint() selEpsilonLexicase() 
   selAutomaticEpsilonLexicase()

and genetic programming specific operators.

Initialization Crossover Mutation Bloat control
genFull()cxOnePoint()mutShrink()staticLimit()
genGrow()cxOnePointLeafBiased()mutUniform()selDoubleTournament()
genHalfAndHalf() mutNodeReplacement() 
  mutEphemeral() 
  mutInsert()

Initialization

deap.tools.
initRepeat
(
container
func
n
)

Call the function container with a generator function corresponding to the calling n times the function func.

Parameters:
  • container – The type to put in the data from func.
  • func – The function that will be called n times to fill the container.
  • n – The number of times to repeat func.
Returns:

An instance of the container filled with data from func.

This helper function can can be used in conjunction with a Toolbox to register a generator of filled containers, as individuals or population.

初始化函数,包括三个参数:容器、函数、重复次数,如以下函数,容器是list,函数是random.random,重复两次

>>> initRepeat(list, random.random, 2) 
...                                    
[0.4761..., 0.6302...]

deap.tools.
initIterate
(
container
generator
)

Call the function container with an iterable as its only argument. The iterable must be returned by the method or the object generator.

Parameters:
  • container – The type to put in the data from func.
  • generator – A function returning an iterable (list, tuple, …), the content of this iterable will fill the container.
Returns:

An instance of the container filled with data from the generator.

This helper function can can be used in conjunction with a Toolbox to register a generator of filled containers, as individuals or population.

看一天累了….未完待续….

    原文作者:遗传算法
    原文地址: https://blog.csdn.net/forethougtht/article/details/72781880
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞