PSO: Using PSO algorithm to optimize two-element function to find optimal individual fitness-jason NIU

Source: Internet
Author: User
Tags cos vmin

Figure[x,y] = Meshgrid ( -5:0.1:5,-5:0.1:5), z = x.^2 + y.^2-10*cos (2*pi*x)-10*cos (2*pi*y) + 20;mesh (x, y, z) hold onc1 =   1.49445;C2 = 1.49445;maxgen = 1000;  Sizepop = 100; Vmax = 1;     Vmin = -1;popmax = 5;     Popmin = -5;for i = 1:sizepop pop (i,:) = 5*rands);        V (i,:) = Rands);   Fitness (i) = Fun (Pop (i,:));   end[bestfitness Bestindex] = max (fitness); zbest = Pop (bestindex,:);    Gbest = Pop;   Fitnessgbest = fitness;   Fitnesszbest = bestfitness; For i = 1:maxgen for j = 1:sizepop V (j,:) = V (j,:) + c1*rand* (gbest (J,:)-pop (J,:)) + c2*rand* (zbest-p        OP (J,:));        V (J,find (V (j,:) >vmax) = Vmax;                V (J,find (V (j,:) <vmin)) = Vmin;        Pop (j,:) = Pop (j,:) + V (j,:);        Pop (J,find (pop (J,:) >popmax)) = Popmax;                Pop (J,find (pop (J,:) <popmin)) = Popmin;     Fitness (j) = Fun (Pop (j,:));            End for j = 1:sizepop If Fitness (j) > Fitnessgbest (J) Gbest (j,:) = Pop (j,:); FitnEssgbest (j) = Fitness (j);            End If Fitness (j) > Fitnesszbest zbest = Pop (j,:);        Fitnesszbest = Fitness (j);            End End YY (i) = fitnesszbest; End[fitnesszbest, Zbest]plot3 (zbest (1), Zbest (2), fitnesszbest, ' ro ', ' linewidth ', 1.5) title (' Particle swarm algorithm: A three-dimensional grid diagram of the target function drawn, Red circle for the most advantage-jason niu ') figureplot (yy) title (' PSO: Using particle swarm optimization algorithm to find the optimal individual fitness for the target function-jason niu ', ' fontsize ', ' xlabel ', ' the ' Evolutionary algebra ', ' FontSize ', Ylabel (' Fitness ', ' fontsize ', 12);

PSO: Using PSO algorithm to optimize two-element function to find optimal individual fitness-jason NIU

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.