Particle Swarm
Particle Swarm
Particle Swarm
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)
𝐶𝑃 𝑡 + 1 = 𝐶𝑃 𝑡 + 𝑉 𝑡 + 1
Step9: Check for Stopping Criteria and proceed for next iteration.
2
Maximize : f(x) = 1-𝑥 +2𝑥
• Let our Control parameters 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))
• 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]
• 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
𝑉(2)3 = 0.8136
𝑉(2)4 = 0.2503
𝑉(2)5 = −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]
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)
GBP(2) =0.1522
Local Best Positions of each particle upto 2nd iteration
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]
-------------------------------------------------------------------------------------------------------------------------------------------------------
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
• 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