Search Term:

Friday, September 18, 2015

PSO Pseudo Code

The pseudo code of the procedure is as follows



For each particle 
    Initialize particle
END

Do
    For each particle 
        Calculate fitness value
        If the fitness value is better than the best fitness value (pBest) in history
            set current value as the new pBest
    End

    Choose the particle with the best fitness value of all the particles as the gBest
    For each particle 
        Calculate particle velocity according equation (a)
        Update particle position according equation (b)
    End 


While maximum iterations or minimum error criteria is not attained

Particles' velocities on each dimension are clamped to a maximum velocity Vmax. If the sum of accelerations would cause the velocity on that dimension to exceed Vmax, which is a parameter specified by the user. Then the velocity on that dimension is limited to Vmax.


source: http://www.swarmintelligence.org/tutorials.php

Mathematical Proof for PSO Algorithm Calculation

Problem:
In a search space there are 5 particles with the position coordinates x1=2,x2=3,x3=-4,x4=1,x5=5 . State Pbest and Gbest after first iteration for objective function
f(x)= -x2 + 5
Solution
Let the give position of particle i.e Xi
x1=2
x2=3
x3=-4
x4= 1
x5=5
by using following equation
vi = ω+ c1*r1()*(Pbest-xi t)+ c2*r2()*(Gbest-xi t);
xi = xi+ vit+1;
Let’s assume c1=c2=1 (c1=c2 are Constant coefficients)
Random function is R1=.213
                              R2=.876
f(xi)=  -x2 + 5 putting the values of X1 to X5

f(x1) =f(2) = (2)2+5=9
          f(3) = 14
          f(-4)= 21
          f(1) = 16
          f(5) = 30 as  f(5) have highest fitness value based on which
Gbest = min (Pbest)
Therefore Gbest = 5

Initially all particle have 0 velocity and positions as mentioned above
Initially all particles holds Pbest value

Velocity Updation for each particle is calculated as
vi = ω+ c1*r1()*(Pbest-xi t)+ c2*r2()*(Gbest-xi t);

V1 = 0 + 0.213 (2-2) + 0.876(5-2) =2.68
Similarly
V2 = 1.75
V3 = 7.884
V4 = -0.87
V5 = 0

New Position Updation based on velocity
xi = xi+ vit+1;


x1= 2+2.68 =4.68
x2=  4.752
x3= 3.884                                  New Pbest
x4= 0.124
x5=  5


Calculating Again Objective function value
f(x1) =f(4.68) = (4.68)2+5=26.9
            f(4.752) = 27.56
            f(3.884)= 19.44
            f(0.124) = 5.015
            f(5) = 30
f(5) have highest fitness value based on which Gbest = min (Pbest)
Therefore Gbest = 5

vi = ω+ c1*r1()*(Pbest-xi t)+ c2*r2()*(Gbest-xi t);

xi = xi+ vit+1