遗传算法原理简介

遗传算法原理简介,第1张

遗传算法(Genetic Algorithm, GA)是一种进化计算(Evolutionary Computing)算法,属于人工智能技术的一部分。遗传算法最早是由John Holland和他的学生发明并改进的,源于对达芬奇物种进化理论的模仿。在物种进化过程中,为了适应环境,好的基因得到保留,不好的基因被淘汰,这样经过很多代基因的变化,物种的基因就是当前自然环境下适应度最好的基因。该算法被广泛应用于优化和搜索中,用于寻求最优解(或最优解的近似),其最主要的步骤包括交叉(crossover)和突变(mutation)。

所有的生物体都由细胞组成,每个细胞中都包含了同样的染色体(chromosome)。染色体由一串DNA组成,我们可以简单地把一个生物个体表示为一条染色体。每条染色体上都包含着基因,而基因又是由多个DNA组成的。每个基因都控制着个体某个性状的表达,例如眼睛的颜色、眼皮的单双等。在物种繁衍的过程中,首先发生交叉,来自于父母的染色体经过分裂和重组,形成后代的染色体。之后,后代有一定概率发生基因突变,即染色体上某个位置处的基因以一定概率发生变化。之后,对每一代都重复进行交叉和突变两个步骤。对于每一个后代,我们可以通过一定的方式测量其适应度。适应度越好的个体,在下一次交叉中被选中的概率越大,它的基因越容易传给下一代。这样,后代的适应度就会越来越好,直到收敛到一个稳定值。

在优化问题中,可行解总是有很多个,我们希望寻找一个最优解,它相对于其他可行解来说具有更好的适应度(即目标函数值更大或更小)。每个可行解就是一个“生物个体”,可以表示为状态空间中的一个点和适应度。每个解都是一个经过编码的序列,已二进制编码为例,每个解都是一个二进制序列。这样每个染色体就是一个二进制序列。遗传算法从从一组可行解开始,称为population,从population中随机选择染色体进行交叉产生下一代。这一做法的基于下一代的适应度会好于上一代。遗传算法的过程如下:

终止条件可以是达到了最大迭代次数,或者是前后连续几代的最优染色体的适应度差值小于一个阈值。以上算法描述也许还不够直观,我们举例说明。假设解可以用二进制编码表示,则每个染色体都是一个二进制序列。假设序列长度为16,则每个染色体都是一个16位的二进制序列:

首先,我们随机生成一个population,假设population size为20,则有20个长度为16的二进制序列。计算每个染色体的适应度,然后选取两个染色体进行交叉,如下图所示。下图在第6为上将染色体断开再重组,断开的位置是可以随机选择的。当然,断裂位置也可以不止一个。可以根据具体问题选择具体的交叉方式来提升算法性能。

之后,随机选取后代染色体上某个基因发生基因突变,突变的位置是随机选取的。并且,基因突变并不是在每个后代上都会发生,只是有一定的概率。对于二进制编码,基因突变的方式是按位取反:

上述例子是关于二进制编码的,像求解一元函数在某个区间内的最大最小值就可以使用二进制编码。例如,求解函数f(x)=x+sin(3x)+cos(3x)在区间[0,6]内的最小值。假设我们需要最小值点x保留4位小数,那么求解区间被离散成60000个数。因为2 {15}<60000<2 {16},所以,需要16位二进制数来表示这60000个可能的解。其中0x0000表示0,0x0001表示0.0001,以此类推。针对这个例子,文末给出了demo code.

然而,在排序问题中无法使用二进制编码,应该采用排列编码(permutation encoding)。例如有下面两个染色体:

交叉:随机选取一个交叉点,从该出将两个染色体断开。染色体A的前部分组成后代1的前部分,然后扫描染色体B,如果出现了后代1中不包含的基因,则将其顺序加入后代1中。同理,染色体B的前部分组成了后代2的前部分,扫描染色体A获得后代2的后部分。注意,交叉的方式多种多样,此处只是举出其中一种方式。

( 1 5 3 2 6 | 4 7 9 8) + ( 8 5 6 7 2 | 3 1 4 9) =>( 1 5 3 2 6 8 7 4 9) + ( 8 5 6 7 2 1 3 4 9)

突变:对于一个染色体,随机选中两个基因互换位置。例如第3个基因和倒数第2个基因互换:

(1 5 3 2 6 8 7 4 9) =>(1 5 4 2 6 8 7 3 9)

此外还有值编码(value encoding)和树编码(tree encoding)等,具体例子可以参考这个链接: http://obitko.com/tutorials/genetic-algorithms/encoding.php

在实际的遗传算法中,往往会保留上一代中的少数几个精英(elite),即将上一代population中适应度最好的几个染色体加入到后代的poulation中,同时去除后代population中适应度最差的几个染色体。通过这个策略,如果在某次迭代中产生了最优解,则最优解能够一直保留到迭代结束。

用GA求函数最小值的demo code: https://github.com/JiaxYau/GA_test

参考资料

[1] Introduction to Genetic Algorithm, http://obitko.com/tutorials/genetic-algorithms/index.php

[2] Holland J H. Adaption in natural and artificial systems

function preprocess(password,verifycode) {

var B = ""

B += verifycode

B = B.toUpperCase()

return md5(md5_3(password) + B)

}

function md5_3(B) {

var A = new Array

A = core_md5(str2binl(B), B.length * chrsz)

A = core_md5(A, 16 * chrsz)

A = core_md5(A, 16 * chrsz)

return binl2hex(A)

}

According to the original data samples contain pattern categories of information, the feature selection process can be divided into supervised feature selection and unsupervised feature selection. Supervised feature selection is to point to in under the premise of the given pattern categories, using the characteristics and the relationship between the characteristics and categories to select feature set process. Unsupervised feature selection is to point to in the original data set, the relationship between the characteristics of their own through data set for feature selection. In this paper the characteristics of the user selection process, we adopt unsupervised feature selection method, based on experience judgement criterion, choose a suitable user data feature subset to best cover the natural classification of data. At present commonly used algorithm with feature selection method based on genetic algorithm [5], feature selection method based on pattern similarity judgment [6] and information gain method of feature selection [7], this algorithm did not consider the correlation between features and feature attributes affect classification. This article attributes to the terminal according to the customer preference influence on the result of the classification and correlation analysis between customer attributes two aspects, this paper proposes a k-means clustering are based on genetic algorithm and the customer property feature selection method, the method is based on unsupervised learning feature selection algorithm. The basic idea is to use genetic algorithm to choose the initial feature subsets, for each feature subset k-means clustering algorithm are used to determine the optimal class number, and then to the DB Index set a judgment function is used for feature selection criterion, finally from the selected feature subset deleted correlation characteristics, reduce redundancy.


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7333534.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存