Particle swarm optimization

Source: Internet
Author: User

The metaphor of one image

The particle swarm algorithm can use random foraging of birds in a space, for example, all birds don't know where the food is, but they know how far it is, the simplest and most effective way is to search the surrounding area of the bird that is currently closest to the food.

Therefore, the PSO algorithm is to see the birds as a particle, and they have the position and speed of the two properties, and then according to their own found from the nearest to the food and reference the entire cluster to find the nearest solution to change their flight direction, and finally we will find that the whole cluster to the same place in general aggregation. And this place is the area closest to the food, if the conditions are good, you will find food. This is the particle swarm algorithm, very well understood.

Second, the algorithm history

Particle swarm optimization (PSO) is an evolutionary computing technology (evolutionary Computation), proposed by Dr. Eberhart and Dr Kennedy in 1995, which originated from the study of predation behavior of bird populations. The algorithm was initially inspired by the regularity of bird swarm activity, and then a simplified model was established by using swarm intelligence. Based on the observation of the activity behavior of the animal cluster, the particle swarm optimization algorithm uses the individual information sharing in the group to make the whole group movement in the problem solving space from disorder to orderly evolution process, thus obtaining the optimal solution.

Third, the algorithm flow

For each particle Initialize particleenddo for each particle Calculate fitness value If The fitness value is Bett Er than the best fitness value (Pbest) in history set current value as the new pbest End Choose the particle with T He best fitness value of the particles as the gbest for each particle Calculate particle velocity according equati On (a) Update particle position according equation (b) endwhile maximum iterations or minimum error criteria was not at tained Flowchart:

Four, the algorithm a simple code

[Java] View Plaincopyprint?<span style= "Font-family:microsoft Yahei" >/*** * Calculate the maximum value of y=-x (x-1) * value range x--[-2,2] *@authorBreezedust **/   Public classPsotest {intn=2;//The number of particles, here to facilitate demonstration, we only take two, to observe its direction of movement    Double[] y; Double[] x; Double[] v; Doublec1=2; Doublec2=2; Doublepbest[]; Doublegbest; Doublevmax=0.1;  Public voidFitnessfunction () {//Adaptive Functions         for(inti=0;i<n;i++) {Y[i]=-1*x[i]* (x[i]-2); }      }       Public voidInit () {//Initializex=New Double[n]; V=New Double[n]; Y=New Double[n]; Pbest=New Double[n]; /*** * Should have been randomly generated, in order to facilitate the demonstration, I here manually randomly drop two points, respectively, fall on the maximum value of both sides*/x[0]=-0.5; x[1]=2.6; v[0]=0.01; v[1]=0.02;          Fitnessfunction (); //initializes the current individual extremum and finds the group Extremum         for(inti=0;i<n;i++) {Pbest[i]=Y[i]; if(y[i]>gbest) gbest=Y[i]; } System.out.println ("Start gbest:" +gbest); }       Public DoubleGetmax (DoubleADoubleb) {          returnA>b?a:b; }      //Particle swarm optimization     Public voidPSO (intmax) {           for(inti=0;i<max;i++){              Doublew=0.4;  for(intj=0;j<n;j++){                  //update location and speedV[j]=w*v[j]+c1*math.random () * (Pbest[j]-x[j]) +c2*math.random () * (gbest-X[j]); if(V[j]>vmax) v[j]=Vmax; X[J]+=V[j]; //Cross Judgment                if(X[J]&GT;2) x[j]=2; if(x[j]<-2) x[j]=-2;              } fitnessfunction (); //Updating individual extremum and group Extremum             for(intj=0;j<n;j++) {Pbest[j]=Getmax (Y[j],pbest[j]); if(pbest[j]>gbest) gbest=Pbest[j]; System.out.println (X[j]+"  "+V[j]); } System.out.println ("======" + (i+1) + "======gbest:" +gbest); }                          }       Public Static voidMain (string[] args) {psotest ts=Newpsotest ();          Ts.init (); Ts. PSO (100); }            }</span>

Particle swarm optimization

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.