摘要:是一個(gè)遺傳算法框架,這里是它的簡介。最小化問題使用負(fù)值的的最大化問題用正值。略種群種群橫線個(gè)體。這個(gè)種群是直接使用和函數(shù)來初始化的。個(gè)體之間分布在網(wǎng)格中每個(gè)格子包含一個(gè)個(gè)體。調(diào)用將會(huì)返回一個(gè)種群,個(gè)體是使用兩個(gè)索引可獲得的。
DEAP是一個(gè)python遺傳算法框架,這里是它的簡介。DEAP documentation
今天整理一下DEAP的概覽,大體了解一下它的流程。初學(xué),不嚴(yán)謹(jǐn),僅作為自己的備忘學(xué)習(xí)筆記。
This tutorial shows how types are created using the creator and initialized using the toolbox.
這個(gè)教程展示的是使用creator創(chuàng)建類型和使用toolbox初始化。
The provided Fitness class is an abstract class that needs a weights attribute in order to be functional. A minimizing fitness is built using negatives weights, while a maximizing fitness has positive weights. For example, the following line creates, in the creator, a ready to use single objective minimizing fitness named FitnessMin.
Fitness類提供了weight屬性。最小化問題使用負(fù)值的的weight,最大化問題用正值。例如下面的例子,利用creator,創(chuàng)建了一個(gè)單目標(biāo)最小問題,命名為:FitnessMin。
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
As specified in the Fitness documentation, the weights attribute must be a tuple so that multi-objective and single objective fitnesses can be treated the same way. A FitnessMulti would be created the same way but using:
正如在library中敘述,這個(gè)weight屬性必須是以tuple的形式給出,如果創(chuàng)建的是多目標(biāo)問題,可以參考下面例子:
creator.create("FitnessMulti", base.Fitness, weights=(-1.0, 1.0))
可見,是一個(gè)多目標(biāo),一個(gè)最小值,一個(gè)最大值。
An example of where the weights can be useful is in the crowding distance sort made in the NSGA-II selection algorithm.
weight屬性的使用可以參考使用NSGA-II選擇算法進(jìn)行擁擠距離排序的例子中。
The first individual created will be a simple list containing floats. In order to produce this kind of individual, we need to create an Individual class, using the creator, that will inherit from the standard list type and have a fitness attribute
第一個(gè)個(gè)體是個(gè)包含浮點(diǎn)數(shù)的簡單列表。為了創(chuàng)造這樣的個(gè)體,我們需要?jiǎng)?chuàng)建一個(gè)Individual類,使用creator,這個(gè)將會(huì)繼承標(biāo)準(zhǔn)list類型,并擁有一個(gè)fitness屬性。
import random from deap import base from deap import creator from deap import tools creator.create("FitnessMax", base.Fitness, weights=(1.0,)) creator.create("Individual", list, fitness=creator.FitnessMax) IND_SIZE=10 toolbox = base.Toolbox() toolbox.register("attr_float", random.random) toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_float, n=IND_SIZE)
The newly introduced register() method takes at least two arguments; an alias and a function assigned to this alias. Any subsequent argument is passed to the function when called (à la functools.partial()). Thus, the preceding code creates two aliases in the toolbox; attr_float and individual.
新引進(jìn)的register方法需要至少兩個(gè)參數(shù)。一個(gè)別名,一個(gè)賦予到這個(gè)別名的函數(shù)。當(dāng)被調(diào)用時(shí),隨后的參數(shù)都被傳進(jìn)給這個(gè)函數(shù)。因此,前面的代碼在toolbox中創(chuàng)建了兩個(gè)別名函數(shù)attr_float和individual。
The first one redirects to the random.random() function. The second one is a shortcut to the initRepeat() function, fixing its container argument to the creator.Individual class, its func argument to the toolbox.attr_float() function, and its number of repetitions argument to IND_SIZE.
第一個(gè)函數(shù)指向random.random函數(shù)。第二個(gè)指向initRepeat函數(shù),向creator固定了它的容器參數(shù)。Individual類的函數(shù)參數(shù)是attr_float函數(shù),和它的重復(fù)數(shù)參數(shù)IND_SIZE。
Now, calling toolbox.individual() will call initRepeat() with the fixed arguments and return a complete creator.Individual composed of IND_SIZE floating point numbers with a maximizing single objective fitness attribute.
現(xiàn)在調(diào)用toolbox.individual()函數(shù)將會(huì)使用固定參數(shù)調(diào)用initRepeat(),返回完整的creator.Individual(由IND_SIZE個(gè)浮點(diǎn)數(shù)組成,有一個(gè)最大化單目標(biāo)fitness attribute)。
略
Population(種群)Populations are much like individuals. Instead of being initialized with attributes, they are filled with individuals, strategies or particles.
種群橫線個(gè)體。它不像個(gè)體一樣,有很多attribute,種群是由很多個(gè)體、策略、粒子組成的。
A bag population is the most commonly used type. It has no particular ordering although it is generally implemented using a list. Since the bag has no particular attribute, it does not need any special class. The population is initialized using the toolbox and the initRepeat() function directly.
背包種群是最常使用的類型。它沒有特定的順序雖然通常使用列表來實(shí)現(xiàn)。因?yàn)楸嘲鼪]特定的屬性,它不需要任何特殊的類。這個(gè)種群是直接使用toolbox和initRepeat()函數(shù)來初始化的。
toolbox.register("population", tools.initRepeat, list, toolbox.individual)
Calling toolbox.population() will readily return a complete population in a list, providing a number of times the repeat helper must be repeated as an argument of the population function. The following example produces a population with 100 individuals.
調(diào)用toolbox.population()將會(huì)返回一個(gè)完整的列表形式的種群,提供重復(fù)次數(shù)是種群函數(shù)的參數(shù)。下面例子生產(chǎn)了100個(gè)個(gè)體:
toolbox.population(n=100)Grid(網(wǎng)格)
A grid population is a special case of structured population where neighbouring individuals have a direct effect on each other. The individuals are distributed in the grid where each cell contains a single individual. However, its implementation only differs from the list of the bag population, in that it is composed of lists of individuals.
網(wǎng)格種群是一個(gè)特殊結(jié)構(gòu)種群的例子,相鄰的個(gè)體對(duì)彼此有直接的影響。個(gè)體之間分布在網(wǎng)格中(每個(gè)格子包含一個(gè)個(gè)體)。然而,它的實(shí)現(xiàn)只和和背包種群的列表不同--它是由個(gè)體們的列表組成的。
toolbox.register("row", tools.initRepeat, list, toolbox.individual, n=N_COL) toolbox.register("population", tools.initRepeat, list, toolbox.row, n=N_ROW)
Calling toolbox.population() will readily return a complete population where the individuals are accessible using two indices, for example popr.
調(diào)用toolbox.population將會(huì)返回一個(gè)種群,個(gè)體是使用兩個(gè)索引可獲得的。例如:pop[r][c]。
略。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/37735.html
摘要:是一個(gè)遺傳算法框架,這里是它的簡介。就是這個(gè)評(píng)價(jià)功能函數(shù)得自己寫,其實(shí),也就是適應(yīng)度函數(shù)了就是注意評(píng)價(jià)函數(shù)返回值必須是可迭代的。完整性的目的我們將開發(fā)完整的分代算法。對(duì)于同一個(gè)種子值的輸入,之后產(chǎn)生的隨機(jī)數(shù)序列也一樣。 DEAP-Overview DEAP是一個(gè)python遺傳算法框架,這里是它的簡介。DEAP documentation今天整理一下DEAP的概覽,大體了解一下它的流程...
摘要:打印出個(gè)體檢查它的適應(yīng)度是否有效這個(gè)個(gè)體打印出來了。這個(gè)適應(yīng)度值是通過設(shè)置值和元祖關(guān)聯(lián)。適應(yīng)度值被刪除了,因?yàn)樗鼈儾辉俸瓦@個(gè)個(gè)體相關(guān)了因?yàn)樽儺惲寺铩H缟厦嫠?,這個(gè)變異算子只是變異并且只是變異一個(gè)個(gè)體,它也不對(duì)適應(yīng)度的無效負(fù)責(zé)或者其它。 Before starting with complex algorithms, we will see some basics of DEAP. F...
閱讀 2212·2021-10-18 13:28
閱讀 2528·2021-10-11 10:59
閱讀 2352·2019-08-29 15:06
閱讀 1142·2019-08-26 13:54
閱讀 821·2019-08-26 13:52
閱讀 3155·2019-08-26 12:02
閱讀 3009·2019-08-26 11:44
閱讀 2521·2019-08-26 10:56