Particle Swarm

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Particle Swarm Optimization

Hand Calculation for a simple example


Steps we do:

Step1: Initialize Control parameters and,initial velocity and Current position →W,C1,C2,n,E ; r1,r2 ; CP(0),V(0) .
While (stopping criteria is not met)
• Compute updated values of Current position and Velocity, for current iteration →CP(t),V(t)

Step2: Compute current Fitness for Current position (from iteration 1 onwards) →CF(t)

Step3: Compute Local Best fitness from Current fitness calculated in step2 →LBF(t)

Step4 :Compute Local Best Positions based on Local Best Fitness in step3 →LBP(t)

Step5:Compute Global Best fitness based on Local best fitness got in step3 →GBF(t)

Step6: Compute Global Best Position based on GBF(t)in Step5. →GBP(t)


Steps for updating velocity and Position
Step7 : With the values that we computed for CP(t),V(t) ,LBP(t) and GBP(t) and the values we
assumed for control parameters like W,C1,C2,r1 and r2 ,
use this formula to update velocity →V(t+1)
𝑉 𝑡 + 1 = 𝑊 ∗ 𝑉 𝑡 + 𝐶1 ∗ (𝑟1 ∗ 𝐿𝐵𝑃 𝑡 − 𝐶𝑃 𝑡 ) + 𝐶2 ∗ (𝑟2 ∗ 𝐺𝐵𝑃 𝑡 − 𝐶𝑃 𝑡 )

Step8 : For Updating Current position for next iteration

𝐶𝑃 𝑡 + 1 = 𝐶𝑃 𝑡 + 𝑉 𝑡 + 1

Step9: Check for Stopping Criteria and proceed for next iteration.
2
Maximize : f(x) = 1-𝑥 +2𝑥
• Let our Control parameters be

W =0.70 ; C1 =0.20 ; C2 =0.60 ; n=5 → 5 Swarm Particles.


E=4 iterations (just for simplicity)
• Let the Random numbers used for updating Velocity of particles be

r1 =[ 0.4657,0.8956,0.3877,0.4902,0.5039]

r2 =[0.5319,0.8185,0.8331,0.7677,0.1708]

• Note: For our simplicity ,we fix these random numbers through out our calculations, infact they
need not be fixed.
Initialization of Swarm Particles
• We initialize fitness of all the particles as Zeros
• Current Position of all the 5 particles as
CP(0) =10 * [r1 -0.5]
CP(0) = 10 *{[ 0.4657,0.8956,0.3877,0.4902,0.5039] -0.5}
So, CP(0) =[-0.3425,3.9558,-1.1228,-0.0981,0.0385]

• Note :here 10 is multiplied randomly to initialize at least some of the particles greater than 1 and
0.5 is subtracted from random numbers just to avoid biasness in generating only positive swarm
particles initially.Now both negative and positive numbers are generated
Initialization of Velocity
• V(0) = r2-0.5 , r2 we already defined initially.

V(0) ={[0.5319,0.8185,0.8331,0.7677,0.1708]-0.5}

we get
V(0) =[0.0319,0.3185,0.3331,0.2677,-0.3292]
Iteration-1:
• As it is the first iteration ,Current position of each particle is what we have initialized.

CP(1) =CP(0)
CP(1) =[-0.3425,3.9558,-1.1228,-0.0981,0.0385]
Similarly Velocity ,
V(1) = V(0)
V(1)=[0.0319,0.3185,0.3331,0.2677,-0.3292]
• Current Fitness of Iteration-1 = f(CP(1))

CF(1) = f(CP(1)) = 1- (𝐶𝑃(1)2 ) + 2𝐶𝑃 1

• So,
CF(1) =[0.1976,-6.7368,-2.5061,0.7942,1.0755]
Note: 𝐶𝑃(1)2 is got by just squaring the each individual element of CP(1) ,not matrix
multiplication.
• Note that Local Best position of each particle up to first iteration is just its current position only.

So LBP(1) =CP(1)
LBP(1) =[-0.3425,3.9558,-1.1228,-0.0981,0.0385]

• Local Best Fitness of each particle up to iteration 1 =Current Fitness of Iteration -1,
LBF(1) = CF(1)
so LBF(1) =[0.1976,-6.7368,-2.5061,0.7942,1.0755]

• Global Best Fitness of iter1 =Max(LBF(1)),


GBF(1) = 1.075 → for 5th particle
• Global Best Position of iter1 = 0.0385 →corresponding current position of 5th particle in CP(1).
Updating Velocity and Current Position:
Velocity for next iteration:
• 𝑉 𝑡 + 1 = 𝑊 ∗ 𝑉 𝑡 + 𝐶1 ∗ (𝑟1 ∗ 𝐿𝐵𝑃 𝑡 − 𝐶𝑃 𝑡 ) + 𝐶2 ∗ (𝑟2 ∗ 𝐺𝐵𝑃 𝑡 − 𝐶𝑃 𝑡 )

Current Position for next iteration:


• 𝐶𝑃 𝑡 + 1 = 𝐶𝑃 𝑡 + 𝑉 𝑡 + 1

• So for iteration 2
𝑉 2 = 0.7 ∗ 𝑉 1 + 0.2 ∗ 𝑟1 ∗ 𝐿𝐵𝑃 1 − 𝐶𝑃 1 + 0.6 ∗ 𝑟2 ∗ 𝐺𝐵𝑃 1 − 𝐶𝑃 1
Calculations:
for example, for particle1
𝑉(1)1 = 0.0319,r11 =0.4657 ,LBP(1)1 = -0.3425 ,CP(1)1 = -0.3425, r21 =0.5319,GBP(1) =0.0385
Putting these into V(2), we get 𝑉(2)1 = 0.144 → updated velocity of 1st particle,
For 2nd particle
𝑉(1)2 =0.3185,r12 =0.8956 ,LBP(1)2 =3.9558 ,CP(1)2 = 3.9558 , r22 =0.8185,GBP(1) =0.0385
so again put these values into
𝑉(2)2 = 0.7 ∗ 𝑉(1)2 + 0.2 ∗ r12 ∗ ,LBP(1)2 − CP(1)2 + 0.6 ∗ r22 ∗ 𝐺𝐵𝑃 1 − CP(1)2
𝑉(2)2 =-1.7008

Similarly we do the same thing for remaining particles


We get

𝑉(2)3 = 0.8136
𝑉(2)4 = 0.2503
𝑉(2)5 = −0.2304

So, V(2) =[0.1439,-1.7008,0.8136,0.2503,-0.2304]


Updating Current Position:
CP(t+1) =CP(t) +V(t+1)
So for iteration2, CP(2)=CP(1)+V(2)
We have
CP(1) =[-0.3425,3.9558,-1.1228,-0.0981,0.0385] , V(2) =[0.1439,-1.7008,0.8136,0.2503,-0.2304]

So CP(2) = [-0.1986,2.2550,-0.3092,0.1522,-0.1919]
-----------------------------------------------------------------------------------------------------------
Iteration 2 :
CP(2) = [-0.1986,2.2550,-0.3092,0.1522,-0.1919]
V(2) = [0.1439,-1.7008,0.8136,0.2503,-0.2304]
• Current Fitness for Iteration = f(CP(2))
CF(2) = 1- (𝐶𝑃(2)2 ) + 2𝐶𝑃 2
• So, we get CF(2) = [0.5634,0.4250,0.2860,1.2812,0.5794]
• Local Best fitness for each particle upto 2nd Iteration :
LBF(2) = Max [ CF(2) ,LBF(1)]
for example take 1st particle
We have LBF(1) =[0.1976,-6.7368,-2.5061,0.7942,1.0755]

𝐿𝐵𝐹(2)1 = 𝑀𝑎𝑥( 0.5634, 0.1976) =0.5634


𝐿𝐵𝐹(2)2 = 𝑀𝑎𝑥( 0.4250, -6.7368) =0.4250
𝐿𝐵𝐹(2)3 = 𝑀𝑎𝑥( 0.2860, -2.5016) =0.2860
𝐿𝐵𝐹(2)4 = 𝑀𝑎𝑥( 1.2812, 0.7942) =1.2812
𝐿𝐵𝐹(2)5 = 𝑀𝑎𝑥( 0.5794, 1.0755) =1.0755 ← please note here

LBF(2) =[0.5634,0.4250,0.2860,1.2812,1.0755]
Global Best Fitness upto 2nd iteration = Max(LBF(2))
GBF(2) =1.2812 → corresponds to 4th particle in LBF(2)

So Global best Position upto 2nd iteration

GBP(2) =0.1522
Local Best Positions of each particle upto 2nd iteration

LBP(2) = corresponding positions of that particle with respect to LBF(2)

for example particle 1 ,𝐿𝐵𝑃(2)1 = corresponding position of particle 1 for which we got 𝐿𝐵𝐹(2)1=0.5634
i.e ., CP(2)1 = −0.1986 ,so 𝐿𝐵𝑃(2)1 = −0.1986,
Similarly for particle2, 𝐿𝐵𝑃(2)2 = corresponding position of particle2 for which we got 𝐿𝐵𝐹(2)2 =0.4250 is
ie. , LBP(2)2 = 2.2550
Similarly for remaining particles we get ,
𝐿𝐵𝑃(2)3 = -0.3092 ; 𝐿𝐵𝑃(2)4 = 0.1522 ; 𝐿𝐵𝑃(2)5 =0.0385
• But Look into LBP(2)5 =0.0385 → corresponding position of 5th particle for which we got LBF(2) =1.0755 is
LBP(1)5 not CP(2)5 ,make a note of this.
So our LBP(2) =[-0.1986,2.2550,-0.3092,0.1522,0.0385]

Now Updating Velocity and Current position for iteration-3 as in the way we did before,
For iteration 3
𝑉 3 = 0.7 ∗ 𝑉 2 + 0.2 ∗ 𝑟1 ∗ 𝐿𝐵𝑃 2 − 𝐶𝑃 2 + 0.6 ∗ 𝑟2 ∗ 𝐺𝐵𝑃 2 − 𝐶𝑃 2

Substituting the values of V(2),LBP(2),CP(2),GBP(2),CP(2) which we got in the 2nd iteration, in the above
equation we get

V(3) = [0.2127,-2.2232,0.8001,0.1752,-0.1260]
• Now we update Current position for iteration-3
we have CP(3) =CP(2)+V(3)
So please look into the previous slides for CP(2) and V(3)
We get CP(3) =[0.0141,0.0318,0.4909,0.3274,-0.2944]
-------------------------------------------------------------------------------------------------------------------------------------------------------

Iteration-3 : So we have CP(3)=[0.0141,0.0318,0.4909,0.3274,-0.2944]


Current fitness for iteration3 = f(CP(3))
CF(3) = 1- (𝐶𝑃(3)2 ) + 2𝐶𝑃 3
We get
CF(3) =[1.0279 , 1.0625 ,1.7410 , 1.5464 , 0.3246]
We have got LBF(2) =[0.5634,0.4250,0.2860,1.2812,1.0755]
• Local Best fitness for each particle upto 3rd Iteration :
LBF(3) = Max [ CF(3) ,LBF(2)]

We get LBF(3) =[1.0279 1.0625 1.7410 1.5464 1.0765],


LBP(3) =[0.0141 0.0318 0.4909 0.3274 0.0385]
please look into how we got LBF(2),in the same way we get this,it is clearly explained over there.
LBP(3) is the position of corresponding particle,for which we got the corresponding values in the above LBF(3)
• We have got LBF(3) =[1.0279 1.0625 1.7410 1.5464 1.0765],
Global Best Fitness upto 3rd iteration = Max(LBF(3))
GBF(3) =1.7410 → corresponds to 3rd particle in LBF(3)

So Global best Position upto 3rd iteration ,look for CP(3)3

GBP(3) =0.4909
Now Updating Velocity and Current position for iteration-4 as in the way we did before,
For iteration4
𝑉 4 = 0.7 ∗ 𝑉 3 + 0.2 ∗ 𝑟1 ∗ 𝐿𝐵𝑃 3 − 𝐶𝑃 3 + 0.6 ∗ 𝑟2 ∗ 𝐺𝐵𝑃 3 − 𝐶𝑃 3

Substituting the values of V(3),LBP(3),CP(3),GBP(3),CP(3) which we got in the 3rd iteration, in the above
equation we get

• V(4) = [0.3011 ,-1.3308,0.5601,0.1980,0.0420]


• Now we update Current position for iteration-4
we have CP(4) =CP(3)+V(4)
So please look into the previous slides for CP(3) and V(4)
• We get CP(4) =[0.3152,-1.2990,1.0510,0.5254,-0.2523]
--------------------------------------------------------------------------------------------------------------------------------
• Iteration-4 : So we have CP(4) =[0.3152,-1.2990,1.0510,0.5254,-0.2523]
Current fitness for iteration3 = f(CP(4))
CF(4) = 1- (𝐶𝑃(4)2 ) + 2𝐶𝑃 4
We get
CF(4)= [1.5312 -3.2861 1.9974 1.7740 0.4317]
We have got LBF(3) =[1.0279 1.0625 1.7410 1.5464 1.0765],
Local Best fitness for each particle upto 4th Iteration :
LBF(4) = Max [ CF(4) ,LBF(3)]

We get LBF(4) =[1.5312,1.0625,1.9974,1.7740,1.0765],


please look into how we got LBF(2),in the same way we get this,it is clearly explained over there.
Local Best Position of each particle,for which we got the corresponding values in the above LBF(4) is
LBP(4) =[0.3152,0.0318,1.0512,0.5254,0.0385]
• We have got
LBF(4) =[1.5312,1.0625,1.9974,1.7740,1.0765],

Global Best Fitness upto 4th iteration = Max(LBF(4))


GBF(4) =1.9974 → corresponds to 3rd particle in LBF(4)

So Global best Position upto 4th iteration ,look for CP(4)3

GBP(4) =1.0512 → Solution =1.0512 at the end of 4 iterations

• Again we update Velocity for next iteration and carry on till we reach our stopping criteria.
But we stop here as we have considered E = 4 iterations only.
Graph of Original function : 𝑓 𝑥 = 1 − 𝑥 2 + 2𝑥 ,Maxima at 𝑥 = 1 𝑎𝑛𝑑 𝑓 1 = 2

Observation and Coclusion:


• We see that, we got Global Best Fitness equal to 1.9974 for x=1.0512 with in 4 iterations,which is very
close to the original best fitness value equal to 2.0 for x=1.
If we want more accuracy, increase number of generations or chose the control parameters
appropriately to achieve it.
----END----

You might also like