## Particle swarm optimization: the simplest what and how

11 Nov

While there exist many introductory materials on Particle Swarm Optimization (PSO), it is best to have an intuitive example, simple, understandable at first reading, and illustrative. I personally do not like those examples that try to bring all intricacies together. Here comes the simplest example I guess: to find a minimum for the function:

It is know that the optimal solution is found when x=-1, and the minimum is f(x)=0;

The below video demonstrate the results of finding this optimal solution using PSO based approach:

As you can see, after some initial random movements of the design variables, the design variable gradually converges to x=-1 (the black curve) and the optimal value reaches 0.

The basic procedures to implement this PSO based approach are as follows:

[1] Create a collection of particles, each particle represents an instance of the design variable. In this case, the design variable is a scalar-valued single parameter:

 %Initialize a particle swarm with nParticals for i=1:nParticals     x{i}=RandInRange(MinVars, MaxVars); end;

[2] For these particles, evaluate their performances:

 for i=1:length(x)         err{i}=obj_func(x{i}); end;

[3] Find the best of these particles, which generates the minimum errors

 ErrMat=cell2mat(err);   % Convert cell to array minErr=min(ErrMat);     % Find the minimum idx=find(ErrMat==minErr);   % Find which X is minimum

[4] The minimum value got so far is both the local best and the global best, keep them down for later use:

 lBestX=x{idx};          % Local best gBestX=x{idx};         % Global best gBestY=minErr; V=0;                             % Velocity of particles of initial movement

[5] For each particles, move them according to the formula:

 alpha1=2.0;     % Local best influence; alpha2=2.0;     % Global best influence; Fai=0.9;             % Inertia Weight;    VMax=0.5; VMin=-0.5;     Gamma1=rand();     Gamma2=rand();     for i=1:length(x)        V=Fai*V + alpha1 * Gamma1 * (lBestX-x{i}) + alpha2 * Gamma2 * (gBestX-x{i}) ;  % update V;       if(V>=VMax)         % To constrain the particles not to move too far…           V=VMax;       elseif(V<=VMin)           V=VMin;       end;                   x{i}= x{i} + V;     end;

For details of these parameters and their physical meanings, Google “Particle Swarm Optimization”, a quick view of the result goes here

[6] Terminate when the some conditions are met:

 while gBestY> 1e-6     x=RunMoveOnce(x,obj_func); end;

Here, RunMoveOnce() refers to the process described in [5].

v0.1  | v0.2  (Nov, 2010)

Posted by on November 11, 2010 in Maths, Programming

### 4 responses to “Particle swarm optimization: the simplest what and how”

1. September 16, 2011 at 1:02 pm

Thank You. It is the simplest explanation of PSO I have ever read.

2. November 1, 2012 at 3:35 pm

great work , i wish if you can help me and send me all the program my brother

3. January 16, 2016 at 9:26 pm