摘要:是一個遺傳算法框架,這里是它的簡介。最小化問題使用負值的的最大化問題用正值。略種群種群橫線個體。這個種群是直接使用和函數來初始化的。個體之間分布在網格中每個格子包含一個個體。調用將會返回一個種群,個體是使用兩個索引可獲得的。
DEAP是一個python遺傳算法框架,這里是它的簡介。DEAP documentation
今天整理一下DEAP的概覽,大體了解一下它的流程。初學,不嚴謹,僅作為自己的備忘學習筆記。
This tutorial shows how types are created using the creator and initialized using the toolbox.
這個教程展示的是使用creator創建類型和使用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屬性。最小化問題使用負值的的weight,最大化問題用正值。例如下面的例子,利用creator,創建了一個單目標最小問題,命名為: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中敘述,這個weight屬性必須是以tuple的形式給出,如果創建的是多目標問題,可以參考下面例子:
creator.create("FitnessMulti", base.Fitness, weights=(-1.0, 1.0))
可見,是一個多目標,一個最小值,一個最大值。
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選擇算法進行擁擠距離排序的例子中。
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
第一個個體是個包含浮點數的簡單列表。為了創造這樣的個體,我們需要創建一個Individual類,使用creator,這個將會繼承標準list類型,并擁有一個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.
新引進的register方法需要至少兩個參數。一個別名,一個賦予到這個別名的函數。當被調用時,隨后的參數都被傳進給這個函數。因此,前面的代碼在toolbox中創建了兩個別名函數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.
第一個函數指向random.random函數。第二個指向initRepeat函數,向creator固定了它的容器參數。Individual類的函數參數是attr_float函數,和它的重復數參數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.
現在調用toolbox.individual()函數將會使用固定參數調用initRepeat(),返回完整的creator.Individual(由IND_SIZE個浮點數組成,有一個最大化單目標fitness attribute)。
略
Population(種群)Populations are much like individuals. Instead of being initialized with attributes, they are filled with individuals, strategies or particles.
種群橫線個體。它不像個體一樣,有很多attribute,種群是由很多個體、策略、粒子組成的。
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.
背包種群是最常使用的類型。它沒有特定的順序雖然通常使用列表來實現。因為背包沒特定的屬性,它不需要任何特殊的類。這個種群是直接使用toolbox和initRepeat()函數來初始化的。
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.
調用toolbox.population()將會返回一個完整的列表形式的種群,提供重復次數是種群函數的參數。下面例子生產了100個個體:
toolbox.population(n=100)Grid(網格)
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.
網格種群是一個特殊結構種群的例子,相鄰的個體對彼此有直接的影響。個體之間分布在網格中(每個格子包含一個個體)。然而,它的實現只和和背包種群的列表不同--它是由個體們的列表組成的。
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.
調用toolbox.population將會返回一個種群,個體是使用兩個索引可獲得的。例如:pop[r][c]。
略。
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/37735.html
摘要:是一個遺傳算法框架,這里是它的簡介。就是這個評價功能函數得自己寫,其實,也就是適應度函數了就是注意評價函數返回值必須是可迭代的。完整性的目的我們將開發完整的分代算法。對于同一個種子值的輸入,之后產生的隨機數序列也一樣。 DEAP-Overview DEAP是一個python遺傳算法框架,這里是它的簡介。DEAP documentation今天整理一下DEAP的概覽,大體了解一下它的流程...
摘要:打印出個體檢查它的適應度是否有效這個個體打印出來了。這個適應度值是通過設置值和元祖關聯。適應度值被刪除了,因為它們不再和這個個體相關了因為變異了嘛。如上面所述,這個變異算子只是變異并且只是變異一個個體,它也不對適應度的無效負責或者其它。 Before starting with complex algorithms, we will see some basics of DEAP. F...
閱讀 2211·2021-10-18 13:28
閱讀 2523·2021-10-11 10:59
閱讀 2347·2019-08-29 15:06
閱讀 1140·2019-08-26 13:54
閱讀 817·2019-08-26 13:52
閱讀 3153·2019-08-26 12:02
閱讀 3008·2019-08-26 11:44
閱讀 2519·2019-08-26 10:56