# 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-2/q3

Canonical: https://deep-learning-study-room.vercel.app/read/is2/m2/mocks/m2-paper-v2-2--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 | (2) | (0) |
| B | (5) | (0) |

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(2)=2^2=4=4
$$



**Particle B**



$$
f(5)=5^2=25=25
$$



##### Step 2. Initialise the memories

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



$$
gbest^0=(2)
$$



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

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

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

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

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times0=0
$$



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=2-(2)=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)}=0+0+0=0
$$



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



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



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

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times0=0
$$



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



$$
d_p=5-(5)=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=2-(5)=-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+0+(-1.5)=-1.5
$$



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



$$
x^{(1)}=5+(-1.5)=3.5
$$



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

**Particle A**



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



**Particle B**



$$
f(3.5)=3.5^2=12.25=12.25
$$



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

| Particle | Old pbest score | New score | Decision | pbest position |
| --- | --- | --- | --- | --- |
| A | 4 | 4 | Keep old: tie | (2) |
| B | 25 | 12.25 | Replace: new score is lower | (3.5) |

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

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

| Particle | Position | Velocity | pbest |
| --- | --- | --- | --- |
| A | (2) | (0) | (2) |
| B | (3.5) | (-1.5) | (3.5) |

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

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

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

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times0=0
$$



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=2-(2)=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^{(2)}=0+0+0=0
$$



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



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



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

**Only coordinate**

Inertia = keep a fraction of the old velocity.



$$
I=0.5\times(-1.5)=-0.75
$$



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



$$
d_p=3.5-(3.5)=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=2-(3.5)=-1.5
$$



Multiply the social coefficients, then multiply by that difference.



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





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



Add the three velocity contributions.



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



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



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



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

**Particle A**



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



**Particle B**



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



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

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

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

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

| Particle | Position | Velocity | pbest |
| --- | --- | --- | --- |
| A | (2) | (0) | (2) |
| B | (2) | (-1.5) | (2) |

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