Genetic algorithm, real-coded cross-operation SBX (analog binary crossover)

Source: Internet
Author: User

This paper mainly introduces the sbx of the crossover operation of the genetic algorithm (real coding), and simulates the binary crossover.

First of all, give the personal code implemented by python2.7, the specific module has been uploaded to:

Https://github.com/guojun007/sbx_cross

1 #!/usr/bin/env python2 #Encoding:utf-83 ImportNumPy as NP4 ImportRandom5 6 """7 SBX analog binary crossover8 9 Input:Ten Population population Matrix One Alfa Crossover Probability A numrangelist The upper limit of the decision variable (the lower limit defaults to 0) - The distribution index of the Mu Sbx method, recommended for 1 - """ the defCross (population, Alfa, Numrangelist, mu=1): -n=Population.shape[0] -V=population.shape[1] -populationlist=Range (N) +  -      for_inchxrange (N): +R=random.random () A          at         ifr<Alfa: -P1, P2=random.sample (populationlist, 2)             -Bq=np.array ([0]*V) -randlist=np.random.random (V) -             #Judging the selection of different probability functions based on probability vectors -Ortf= (randlist<=0.5) in  -             #calculating coefficients of different probability choices for different decision variables to              forJinchxrange (V): +                 ifortf[j]==True: -Bq[j]= (2.0*randlist[j]) * * (1.0/(mu+1)) the                 Else: *Bq[j]= (1.0/(2.0* (1-RANDLIST[J))) * * (1.0/(mu+1)) $ Panax Notoginseng             #Remove the selected two individuals -old_p1=Population[p1,] theOld_p2=Population[p2,] +             #calculate the two new individuals after crossing Anew_p1=0.5* (1+BQ) *old_p1+ (1-BQ) *old_p2) thenew_p2=0.5* (1-BQ) *old_p1+ (1+BQ) *old_p2) +  -             #Upper and lower limits to prevent cross-border $New_p1=np.max (Np.vstack (NEW_P1, Np.array ([0]*V))) , 0) $new_p1=np.min (Np.vstack (NEW_P1, numrangelist)), 0) -  -New_p2=np.max (Np.vstack (NEW_P2, Np.array ([0]*V))) , 0) theNew_p2=np.min (Np.vstack (NEW_P2, numrangelist)), 0) - Wuyi             #Update the cross-over individuals back to the population thePOPULATION[P1,]=NEW_P1 -POPULATION[P1,]=NEW_P2 Wu  -  About ## #以下是测试用例 $ if __name__=="__main__": - random.seed (0) - np.random.seed (0) -Xn=20 AYn=3 +alfa=0.9 thePopulation=np.random.rand (Xn*yn). Reshape (XN, YN) *1.0 -  $     ## #运行函数 the     Printpopulation the     Print '-'*50 theCross (population, Alfa, Np.array ([1]*3)) the     Print '-'*50 -     PrintPopulation

The following leads to:

http://blog.csdn.net/silence1214/article/details/48802317

Recently in doing homework encountered a DeJong ' s fifth function of multi modal problem, with the traditional GA method tried many times, indeed no way to fix, random many times also not necessarily in global optimum place to get a solution. A few days ago to tutor home on the way to talk about this thing, the tutor said generally now use SBX and polynomial mutation. So came back to find the relevant papers, found SBX the earliest paper, oddly, in the paper did not give a pseudo-code, just explain his motivation. The approximate motivation is this:
1:SBX is mainly used for the coding problem of real number, but it is borrowed from the idea of binary coding. In binary, assume that 2 of the parent areP1 AndP2 , the descendants wereC1 AndC2 。 So this is a property of:(P1+ P2) /2= Span id= "mathjax-span-32" class= "Mi" >c1 +c 2) /2 。 And define a thing called spread factor.Beta=| (c 2? C1) / (p2< Span id= "mathjax-span-62" class= "Mo"? p1 ) |

2: The first attribute should be satisfied in the SBX, and as far as possibleBetaAlso the probability distributions in binary are consistent. This is a solution:
C1=(P2+p1)? 0.5? Beta(P2? ) P1)
c2 = ( P2+ p1 ) + 0.5? Β (p 2? P1)
You can calculate for yourself, is to meet the above 2 things.

3: So the next thing is to askBeta, because it's about getting the real problem.BetaThe distribution of the binary is as close as possible to the binary, then it is necessary to first know the distribution. The distributions in binary are as follows:
c(β)=0.5(n+1)betan,β≤1 andC(Beta)=0.5(n+1)1betan+2,beta>1
Other words Beta has 2 distributions, how exactly do you do it? I saw someone come to the realization.

3.1: Random a number in[0,1< Span id= "mathjax-span-179" class= "Mo" > If the number is less than or equal to 0 .5 Follow the first request, otherwise follow the second one. The solution is in accordance with the The probability distribution of the β is equal to this random number to calculate. This is just a matter of asking for points, which can be deduced by hand.

Finally I use this method to add tournament selection and polynomial mutation method, in solving the above said multi modal problem, unexpectedly many times have been solved!

Genetic algorithm, real-coded cross-operation SBX (analog binary crossover)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.