# Q3 · Two-particle PSO through iteration 2 [3]

Subject: Intelligent Systems II

Exam: M2

Reader: https://deep-learning-study-room.vercel.app/is2/#m2/mocks/m2-paper-v2-3/q3

Canonical: https://deep-learning-study-room.vercel.app/read/is2/m2/mocks/m2-paper-v2-3--q3/

Q1(a)+Q1(b) compulsory; any two of Q2–Q4. Answers immediately below each question.

**Confirmed M2 pattern:** Q1(a) [2] and Q1(b) [2] are compulsory. Attempt any two of Q2, Q3 and Q4, each worth 3 marks. The paper offers 13 marks; you attempt 10. These are newly written practice questions, not claims about the exact upcoming paper. Solutions are directly below each question; the teaching working is deliberately longer than a concise exam answer.

**Q3. Minimise 

$$
f(x)=x^2
$$

 using 2 particles. Use the initial data below and perform exactly two PSO iterations, reporting position, velocity, pbest and gbest after each iteration.** [3 marks · Practice; expanded teaching solution]

#### Given

| Particle | Initial position x⁰ | Initial velocity v⁰ |
| --- | --- | --- |
| A | (1) | (2) |
| B | (4) | (-1) |

w=0.5, c₁=1, c₂=1, r₁=0.5, r₂=0.5. Initialise each pbest at its initial position. Use these random coefficients unchanged in both iterations. No bounds or velocity clamp are imposed in this example. Updates are synchronous: every particle uses the same previous-iteration gbest.

#### To find

The complete swarm state after iterations 1 and 2, and the best location found.

#### Formula and why it applies

PSO combines inertia, personal memory and shared memory. Subtract positions coordinate by coordinate. Evaluate the objective only after moving. For minimisation, replace a best only when its score decreases.



$$
v^{t+1}=wv^t+c_1r_1(pbest^t-x^t)+c_2r_2(gbest^t-x^t)
$$





$$
x^{t+1}=x^t+v^{t+1}
$$



#### Solution

##### Step 1. Evaluate every initial position

**Particle A**



$$
f(1)=1^2=1=1
$$



**Particle B**



$$
f(4)=4^2=16=16
$$



##### Step 2. Initialise the memories

pbest is each initial position because there is no earlier history. The smallest objective decides gbest.



$$
gbest^0=(1)
$$



Its score is 1. Store the position, not only the score.

##### Step 3. Iteration 1: freeze the previous memories

All particles in this iteration use gbest = (1). pbest values are A: (1), B: (4).

##### Step 4. Iteration 1: update particle A

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times2=1
$$



Personal pull: first subtract the current coordinate from the personal-best coordinate.



$$
d_p=1-(1)=0
$$



Multiply the two personal coefficients, then multiply by the difference.



$$
c_1r_1=1\times0.5=0.5
$$





$$
C=0.5\times(0)=0
$$



Social pull: subtract the current coordinate from the frozen global-best coordinate.



$$
d_g=1-(1)=0
$$



Multiply the social coefficients, then multiply by that difference.



$$
c_2r_2=1\times0.5=0.5
$$





$$
S=0.5\times(0)=0
$$



Add the three velocity contributions.



$$
v^{(1)}=1+0+0=1
$$



Add the new velocity to the old position. The parenthesised upper label is the iteration number.



$$
x^{(1)}=1+1=2
$$



##### Step 5. Iteration 1: update particle B

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times(-1)=-0.5
$$



Personal pull: first subtract the current coordinate from the personal-best coordinate.



$$
d_p=4-(4)=0
$$



Multiply the two personal coefficients, then multiply by the difference.



$$
c_1r_1=1\times0.5=0.5
$$





$$
C=0.5\times(0)=0
$$



Social pull: subtract the current coordinate from the frozen global-best coordinate.



$$
d_g=1-(4)=-3
$$



Multiply the social coefficients, then multiply by that difference.



$$
c_2r_2=1\times0.5=0.5
$$





$$
S=0.5\times(-3)=-1.5
$$



Add the three velocity contributions.



$$
v^{(1)}=(-0.5)+0+(-1.5)=-2
$$



Add the new velocity to the old position. The parenthesised upper label is the iteration number.



$$
x^{(1)}=4+(-2)=2
$$



##### Step 6. Iteration 1: evaluate the new positions

**Particle A**



$$
f(2)=2^2=4=4
$$



**Particle B**



$$
f(2)=2^2=4=4
$$



##### Step 7. Iteration 1: update pbest, then gbest

| Particle | Old pbest score | New score | Decision | pbest position |
| --- | --- | --- | --- | --- |
| A | 1 | 4 | Keep old: new score is worse | (1) |
| B | 16 | 4 | Replace: new score is lower | (2) |

Compare the retained pbest scores. gbest = **(1)**, with objective **1**.

##### Step 8. Iteration 1: record the complete state

| Particle | Position | Velocity | pbest |
| --- | --- | --- | --- |
| A | (2) | (1) | (1) |
| B | (2) | (-2) | (2) |

##### Step 9. Iteration 2: freeze the previous memories

All particles in this iteration use gbest = (1). pbest values are A: (1), B: (2).

##### Step 10. Iteration 2: update particle A

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times1=0.5
$$



Personal pull: first subtract the current coordinate from the personal-best coordinate.



$$
d_p=1-(2)=-1
$$



Multiply the two personal coefficients, then multiply by the difference.



$$
c_1r_1=1\times0.5=0.5
$$





$$
C=0.5\times(-1)=-0.5
$$



Social pull: subtract the current coordinate from the frozen global-best coordinate.



$$
d_g=1-(2)=-1
$$



Multiply the social coefficients, then multiply by that difference.



$$
c_2r_2=1\times0.5=0.5
$$





$$
S=0.5\times(-1)=-0.5
$$



Add the three velocity contributions.



$$
v^{(2)}=0.5+(-0.5)+(-0.5)=-0.5
$$



Add the new velocity to the old position. The parenthesised upper label is the iteration number.



$$
x^{(2)}=2+(-0.5)=1.5
$$



##### Step 11. Iteration 2: update particle B

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times(-2)=-1
$$



Personal pull: first subtract the current coordinate from the personal-best coordinate.



$$
d_p=2-(2)=0
$$



Multiply the two personal coefficients, then multiply by the difference.



$$
c_1r_1=1\times0.5=0.5
$$





$$
C=0.5\times(0)=0
$$



Social pull: subtract the current coordinate from the frozen global-best coordinate.



$$
d_g=1-(2)=-1
$$



Multiply the social coefficients, then multiply by that difference.



$$
c_2r_2=1\times0.5=0.5
$$





$$
S=0.5\times(-1)=-0.5
$$



Add the three velocity contributions.



$$
v^{(2)}=(-1)+0+(-0.5)=-1.5
$$



Add the new velocity to the old position. The parenthesised upper label is the iteration number.



$$
x^{(2)}=2+(-1.5)=0.5
$$



##### Step 12. Iteration 2: evaluate the new positions

**Particle A**



$$
f(1.5)=1.5^2=2.25=2.25
$$



**Particle B**



$$
f(0.5)=0.5^2=0.25=0.25
$$



##### Step 13. Iteration 2: update pbest, then gbest

| Particle | Old pbest score | New score | Decision | pbest position |
| --- | --- | --- | --- | --- |
| A | 1 | 2.25 | Keep old: new score is worse | (1) |
| B | 4 | 0.25 | Replace: new score is lower | (0.5) |

Compare the retained pbest scores. gbest = **(0.5)**, with objective **0.25**.

##### Step 14. Iteration 2: record the complete state

| Particle | Position | Velocity | pbest |
| --- | --- | --- | --- |
| A | (1.5) | (-0.5) | (1) |
| B | (0.5) | (-1.5) | (0.5) |

**Final answer.** After iteration 2, gbest = (0.5), objective = 0.25. This is the best found in these two iterations, not a claim that PSO has proved the global optimum.
