Particle swarm optimization Algorithm (PSO) for optimal solution

Source: Internet
Author: User

Explanation of particle swarm optimization algorithm (PSO): http://blog.csdn.net/myarrow/article/details/51507671 (various references on the Internet)

Using PSO to find the function extremum.

function [f]= Fun (x, y)%UNTITLED2 shows a    Summary of this function here = (x-a) ^2 + (y-b) ^2; end

Constructs a two-tuple function, obviously with a minimum, in (50, 50).

Use five of particles to find it. The function output value corresponding to each point is considered a particle's fitness.

1 clear All;2 CLC;3%Initialize4n =5;5P = rand (5,2) * -;6p = cell (5,1);7  fori =1: N8P (I,1) = {[P (I,1), P (I,2)]};9 EndTenv = rand (5,2) *0.5; OneVmax =0.5; APbest =p; -Gbest = cell (1); -Fit_v = Zeros (5,1); theKey =1; -  fori =1: N -Fit_v (I,1) = Fun (P{i} (1), P{i} (2)); -     if(Fit_v (I,1) < Fit_v (Key,1) ) +Key =i; - End + End AGbest (1) = Pbest (Key,1); at%Loop -t =1; -  while(T < -) -      fori =1: N -          forj =1:2 -V (i, j) = V (i, J) +2*rand () * (Pbest{i, T} (j)-p{i} (j)) +2*rand () * (Gbest{t} (J)-P{i} (j)); in             if(ABS (V (i, j)) >Vmax) -V (i, j) = ABS (V (i, J))/V (i, j) *Vmax; to End +P{i} (j) = P{i} (j) +V (i, j); - End theFit_v_temp = Fun (P{i} (1), P{i} (2)); *         if(Fit_v_temp <fit_v (i, T)) $Fit_v (i, t+1) =fit_v_temp;Panax NotoginsengPbest (i, t+1) =p (i); -         Else theFit_v (i, t+1) =fit_v (i, t); +Pbest (i, t+1) =pbest (i, t); A End the End +t = t +1; -Key =1; $      fori =1: N $         if(Fit_v (i, T) <fit_v (key, T)) -Key =i; - End the End -Gbest (t) =pbest (key, t);WuyiEnd

Operation result: [50.0030796073836,50.0004541255463]

Figure 1 gbest trajectory (red dot indicates last convergent position)

Fig. 2 The fitness curve of each particle

Can be found in 100 times around the basic convergence.

Particle swarm optimization Algorithm (PSO) for optimal solution

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.