遗传算法图解_遗传算法图解指南
遺傳算法圖解
In the previous post, We discussed what Artificial Intelligence (AI) in general. It would be less informative if we only know the information from the outside. So in this post, I will go into a little more detail into one of the methods that exist in the AI ??field.
在上一篇文章中,我們討論了什么是人工智能 (AI)。 如果我們僅從外部知道信息,則信息量會減少。 所以在這篇文章中,我將更詳細地介紹AI領域中存在的一種方法。
On this occasion, I will discuss an algorithm that is included in the AI ??field, namely Genetic Algorithms. The genetic algorithm is a part of Evolutionary Computation (EC) which is inspired by the process of evolution and natural selection of living things.
在這種情況下,我將討論AI領域中包含的一種算法,即遺傳算法 。 遺傳算法是進化計算 (EC)的一部分,它受到進化過程和生物自然選擇的啟發。
Genetic algorithms are generally used to overcome optimization and search problems. This algorithm is a general algorithm so that it can be easily implemented in various problems and can provide better results for each iteration of the search solution. Genetic algorithms can find the best solutions from candidate sets that are broad and have many optimum points and also the results tend to go to the global optimum compared to similar methods such as hill-climbing, depth-first search, etc.
遺傳算法通常用于克服優化和搜索問題。 該算法是一種通用算法,因此可以輕松地在各種問題中實現,并且可以為搜索解決方案的每次迭代提供更好的結果。 遺傳算法可以從廣泛且具有許多最佳點的候選集中找到最佳解決方案,并且與類似的方法(例如爬山 , 深度優先搜索等)相比,結果傾向于趨于全局最優。
Genetic algorithms can be used to solve a number of cases due to the following advantages.
由于以下優點,遺傳算法可用于解決許多情況。
- Consists of many prospective solutions that are raised at once 由一次提出的許多預期解決方案組成
- Each iteration provides a candidate for a better solution 每次迭代都為更好的解決方案提供了候選者
- Large solution space is not a problem 解決方案空間大不是問題
- A fast and efficient algorithm 快速高效的算法
遺傳算法中的術語 (Terms in Genetic Algorithms)
Before we go any further, we must know first about the terms that are commonly used in Genetic Algorithms.
在繼續進行之前,我們必須首先了解遺傳算法中常用的術語。
Population, chromosome, genotype, and phenotype群體,染色體,基因型和表型- Population, collection of possible solutions. 人口,可能的解決方案的集合。
- Chromosome, one possible solution 染色體,一種可能的解決方案
- Genotype, elements contained in chromosomes 基因型,染色體中包含的元素
- Phenotype, value of genotype 表型,基因型值
In addition, there are also other terms that are often used in this algorithm.
另外,在此算法中還經常使用其他術語。
- Fitness function, function that determines the weight of each chromosome 適應度函數,決定每個染色體重量的函數
- Fitness Value, value obtained from the results of the fitness function 適應度值,從適應度函數的結果中獲得的值
- Decoding and Encoding, in some cases, the phenotype can be changed to other forms. For example binary, real, permutation, and integer. Decoding and encoding is the process of changing it from one form to another. 解碼和編碼,在某些情況下,表型可以更改為其他形式。 例如二進制,實數,置換和整數。 解碼和編碼是將其從一種形式更改為另一種形式的過程。
- Generation, number of iterations in the genetic algorithm process. 生成,遺傳算法過程中的迭代次數。
For more details and examples of its use, I will explain in the next section.
有關更多詳細信息及其使用示例,我將在下一部分中進行解釋。
遺傳算法的各個階段 (Stages in Genetic Algorithms)
After we learned about the advantages and terms in the Genetic Algorithm, now we will describe the stages carried out by the genetic algorithm to produce a solution.
在了解了遺傳算法的優點和術語之后,現在我們將描述遺傳算法執行以產生解決方案的各個階段。
Here, I will explain these stages in general terms. For specific cases, maybe I’ll explain in the next article. In general, genetic algorithms consist of the following steps.
在這里,我將大致解釋這些階段。 對于特定情況,也許我將在下一篇文章中進行解釋。 通常,遺傳算法包括以下步驟。
初始化人口 (Initialize Population)
The initial stage in genetic algorithms is to initialize populations. At this stage, we must determine the population and length of the chromosomes to be used. For determining the number of the population itself there is no provision for the amount. The greater the number of population will produce more variety of solutions, thus increasing the possibility of achieving the best solution.
遺傳算法的初始階段是初始化種群。 在這個階段,我們必須確定要使用的染色體的數量和長度。 為了確定人口本身的數量,沒有規定數量。 人口數量越大,產生的解決方案種類就越多,從而增加了獲得最佳解決方案的可能性。
The determination of the length of the chromosome is usually adjusted to the case being handled. For example, if in the case of the maximization of the function f(x,y) = 5 * x — 10 * y, then the length of the chromosome is two because there are two variables namely x and y which we will look for. Another example is if the case is the Traveling Salesman Problem (TSP) then the length of the chromosome is adjusted to the number of places to be visited.
染色體長度的確定通常根據要處理的情況進行調整。 例如,如果在函數f(x,y) = 5 * x — 10 * y最大化的情況下,那么染色體的長度為2,因為我們將尋找兩個變量,即x和y 。 另一個示例是,如果情況是旅行商問題(TSP) ,則將染色體的長度調整為要訪問的地點數。
In addition, we also have to determine the representation of the chromosomes to be used. There are some commonly used representations such as binary, integer, float, and permutation representations. The determination of representation is adjusted to the case to be resolved.
此外,我們還必須確定要使用的染色體的表示形式。 有一些常用的表示形式,例如二進制,整數,浮點和置換表示形式。 代表的確定會根據要解決的情況進行調整。
Representation表示We also have to determine when this genetic algorithm process stops. There are 2 commonly used methods, the first is to determine the threshold on the fitness value, the second is to determine the number of generations.
我們還必須確定該遺傳算法過程何時停止。 共有2種常用方法,第一種是確定適應度值的閾值,第二種是確定世代數。
In addition, we must also determine the value of the crossover probability and the mutation probability. For this reason, it will be explained further along with the process.
另外,還必須確定交叉概率和突變概率的值。 因此,將與過程一起進行進一步說明。
適應度計算 (Fitness calculation)
After we initialize the population, the next step is to calculate the fitness value for each chromosome. Fitness functions can vary, depending on the problem to be solved. For example, if we want to find the maximal value of the function f(x,y) = 5 * x — 10 * y, then the way to calculate it is to include the x and y values ??in the function.
初始化種群后,下一步是計算每個染色體的適應度值。 健身功能會有所不同,具體取決于要解決的問題。 例如,如果我們要查找函數f(x,y) = 5 * x — 10 * y的最大值,則計算該函數的方法是在函數中包含x和y值。
選拔 (Selection)
After all fitness values ??are obtained, then parents are chosen. Determine the number of parent pairs you want to choose then make the selection in the following way. There are several ways to choose parent chromosomes.
獲得所有適合度值后,再選擇父母。 確定要選擇的父對的數量,然后按以下方式進行選擇。 有幾種選擇親本染色體的方法。
交叉 (Crossover)
After selecting parents, the next step we will do is to do a crossover. Crossover is a process for producing new chromosomes. Crossover is done between two chromosomes, and the result of the crossover is two chromosomes.
選擇了父母之后,我們下一步要做的是交叉。 交叉是產生新染色體的過程。 在兩個染色體之間進行交換,并且交換的結果是兩個染色體。
There are two types of approaches for determining new chromosomes, namely generational and steady-state.
確定新染色體的方法有兩種,即世代和穩態。
If you still remember, during the initialization process we must determine the probability of the crossover. Here is the function of the probability. The probability is used to determine whether a crossover occurs or not. In general, the crossover probability used is 0.8, but you are free to determine the probability because there is no certainty of the best probability.
如果您還記得,在初始化過程中,我們必須確定交叉的可能性。 這是概率的函數。 該概率用于確定是否發生交叉。 通常,使用的交叉概率為0.8,但是您可以自由確定概率,因為無法確定最佳概率。
We must generate random values ??from 0 to 1, if the random value is smaller or equal to probabilities then a crossover is performed. The types of crossovers that can be done are as follows.
我們必須生成從0到1的隨機值,如果隨機值小于或等于概率,則將執行交叉運算。 可以進行的交叉類型如下。
- One point crossover. This crossover exchanges genes from one chromosome to another to produce new chromosomes through one intersection point. 一分頻。 這種交叉將基因從一個染色體交換到另一個染色體,以通過一個交叉點產生新的染色體。
- Multi-point crossover. This crossover exchanges genes from one chromosome to another to produce new chromosomes through several intersection points. 多點交叉。 這種交叉將基因從一個染色體交換到另一個染色體,以通過幾個交叉點產生新的染色體。
- Uniform crossover. This crossover exchanges genes from one chromosome to another through each index based on probability. Each gene has a probability like a coin, for example, if the head appears then it is exchanged and if a tail appears, the position of the gene remains. 均勻的交叉。 這種交叉基于概率通過每個索引將基因從一個染色體交換到另一個染色體。 每個基因都有一個像硬幣一樣的概率,例如,如果出現頭部,則將其交換,如果出現尾部,則該基因的位置仍然存在。
All the cut points are obtained randomly.
所有切割點都是隨機獲得的。
突變 (Mutation)
Almost the same as a crossover, mutations are not always done due to the probability of mutations. The probability of mutation common being used is 0.1. As with crossover probabilities, there are no definite provisions regarding the value of mutation probabilities.
幾乎與交叉相同,由于突變的可能性,并非總是進行突變。 共同使用突變的概率為0.1。 與交叉概率一樣,對于突變概率的值也沒有明確的規定。
In the process, mutations change the phenotype of genes (change the value of genes). mutations can be done with one point or can also be with many points, can also be swapped points.
在此過程中,突變會改變基因的表型(改變基因的值)。 突變可以用一個點完成,也可以用很多點進行,也可以交換點。
- One point mutation 一分突變
- Multi-point mutation 多點突變
- Swap mutation 交換突變
幸存者選擇 (Survivor selection)
Next is to get another population for the next iteration. Some chromosomes that are not important will be discarded and replaced with new chromosomes that have gone through a process of crossover and mutation.
接下來是為下一次迭代獲取另一個種群。 一些不重要的染色體將被丟棄,并被經歷了交叉和突變過程的新染色體取代。
In the application of genetic algorithms, it is better to use the principle of elitism, which always stores the best chromosomes during the process so that there will always be chromosomes with the highest fitness. If a newer chromosome combination appears better, then one chromosome stored previously is exchanged with the new chromosome.
在遺傳算法的應用中,最好使用精英原則,該原則在此過程中始終存儲最佳染色體,從而始終存在適應性最高的染色體。 如果較新的染色體組合看起來更好,則將先前存儲的一個染色體與新染色體交換。
After determining the new population, the next process is to calculate the fitness value of the new population. This will continue to be repeated until the termination conditions are met. As explained earlier, the termination condition that is commonly used is to use a threshold fitness value or determine the maximum number of generations.
確定新人口后,下一步是計算新人口的適應度值。 這將繼續重復直到滿足終止條件。 如前所述,通常使用的終止條件是使用閾值適合度值或確定最大世代數。
If the process has stopped, then the solution of this genetic algorithm is the chromosome with the greatest fitness value.
如果該過程已停止,則此遺傳算法的解決方案是適應性值最大的染色體。
翻譯自: https://towardsdatascience.com/an-illustrated-guide-to-genetic-algorithm-ec5615c9ebe
遺傳算法圖解
總結
以上是生活随笔為你收集整理的遗传算法图解_遗传算法图解指南的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python在eclipse下中文乱码问
- 下一篇: 从网络字节流中提出整数