国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Python遺傳算法框架DEAP-Creating Types

Channe / 1079人閱讀

摘要:是一個遺傳算法框架,這里是它的簡介。最小化問題使用負值的的最大化問題用正值。略種群種群橫線個體。這個種群是直接使用和函數(shù)來初始化的。個體之間分布在網(wǎng)格中每個格子包含一個個體。調(diào)用將會返回一個種群,個體是使用兩個索引可獲得的。

DEAP是一個python遺傳算法框架,這里是它的簡介。DEAP documentation
今天整理一下DEAP的概覽,大體了解一下它的流程。初學(xué),不嚴謹,僅作為自己的備忘學(xué)習(xí)筆記。

This tutorial shows how types are created using the creator and initialized using the toolbox.
這個教程展示的是使用creator創(chuàng)建類型和使用toolbox初始化。

Fitness(適應(yīng)度)

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,創(chuàng)建了一個單目標(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中敘述,這個weight屬性必須是以tuple的形式給出,如果創(chuàng)建的是多目標(biāo)問題,可以參考下面例子:

creator.create("FitnessMulti", base.Fitness, weights=(-1.0, 1.0))

可見,是一個多目標(biāo),一個最小值,一個最大值。
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選擇算法進行擁擠距離排序的例子中。

Individual(個體) List of Floats

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
第一個個體是個包含浮點數(shù)的簡單列表。為了創(chuàng)造這樣的個體,我們需要創(chuàng)建一個Individual類,使用creator,這個將會繼承標(biāo)準(zhǔn)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方法需要至少兩個參數(shù)。一個別名,一個賦予到這個別名的函數(shù)。當(dāng)被調(diào)用時,隨后的參數(shù)都被傳進給這個函數(shù)。因此,前面的代碼在toolbox中創(chuàng)建了兩個別名函數(shù)attr_floatindividual

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.
第一個函數(shù)指向random.random函數(shù)。第二個指向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ù)將會使用固定參數(shù)調(diào)用initRepeat(),返回完整的creator.Individual(由IND_SIZE個浮點數(shù)組成,有一個最大化單目標(biāo)fitness attribute)。

Population(種群)

Populations are much like individuals. Instead of being initialized with attributes, they are filled with individuals, strategies or particles.
種群橫線個體。它不像個體一樣,有很多attribute,種群是由很多個體、策略、粒子組成的。

Bag

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.
背包種群是最常使用的類型。它沒有特定的順序雖然通常使用列表來實現(xiàn)。因為背包沒特定的屬性,它不需要任何特殊的類。這個種群是直接使用toolboxinitRepeat()函數(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()將會返回一個完整的列表形式的種群,提供重復(fù)次數(shù)是種群函數(shù)的參數(shù)。下面例子生產(chǎn)了100個個體:

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)格種群是一個特殊結(jié)構(gòu)種群的例子,相鄰的個體對彼此有直接的影響。個體之間分布在網(wǎng)格中(每個格子包含一個個體)。然而,它的實現(xiàn)只和和背包種群的列表不同--它是由個體們的列表組成的。

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將會返回一個種群,個體是使用兩個索引可獲得的。例如:pop[r][c]

略。

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/37735.html

相關(guān)文章

  • python遺傳算法(GA)DEAP-Overview學(xué)習(xí)摘要

    摘要:是一個遺傳算法框架,這里是它的簡介。就是這個評價功能函數(shù)得自己寫,其實,也就是適應(yīng)度函數(shù)了就是注意評價函數(shù)返回值必須是可迭代的。完整性的目的我們將開發(fā)完整的分代算法。對于同一個種子值的輸入,之后產(chǎn)生的隨機數(shù)序列也一樣。 DEAP-Overview DEAP是一個python遺傳算法框架,這里是它的簡介。DEAP documentation今天整理一下DEAP的概覽,大體了解一下它的流程...

    draveness 評論0 收藏0
  • Python遺傳算法框架DEAP-Operators and Algorithms

    摘要:打印出個體檢查它的適應(yīng)度是否有效這個個體打印出來了。這個適應(yīng)度值是通過設(shè)置值和元祖關(guān)聯(lián)。適應(yīng)度值被刪除了,因為它們不再和這個個體相關(guān)了因為變異了嘛。如上面所述,這個變異算子只是變異并且只是變異一個個體,它也不對適應(yīng)度的無效負責(zé)或者其它。 Before starting with complex algorithms, we will see some basics of DEAP. F...

    fantix 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<