Particle Swarm Optimization (PSO)
Particle Swarm Optimization
- Estimated duration
- 35 minutes
- Related questions
- 16
- Related algorithms
- 1
- Status
- Log in to track
Lesson objectives
- Deriving the velocity and position equations.
- Understanding the role of w, c₁, c₂ and the constriction coefficients.
- Applying PSO to a continuous and a binary problem.
Explanation
PSO is one of the simplest and most widely used swarm algorithms. Each particle remembers the best position it has visited, and knows the swarm's best position.
The velocity is updated from three components: inertia (keeping the direction), the cognitive component (returning to pbest) and the social component (heading to gbest). Then it is added to the position.
The parameters: Clerc and Kennedy's analysis showed that the constriction coefficients χ≈0.7298 with c₁=c₂≈1.49618 guarantee stable behaviour. An inertia weight decreasing linearly from 0.9 to 0.4 is another common form. Limiting the velocity with v_max prevents explosion.
The topology: gbest (each particle sees the swarm's best) converges fast, and the ring lbest (it sees only its neighbours) is slower but preserves diversity on multimodal functions.
The binary version (BPSO, Kennedy & Eberhart 1997) turns the velocity into a probability with a Sigmoid function for feature selection.
Mathematics
Velocity
v_i^{t+1} = w v_i^{t} + c_1 r_1 (p_i - x_i^{t}) + c_2 r_2 (g - x_i^{t})Position
x_i^{t+1} = x_i^{t} + v_i^{t+1}BPSO
x_{id} = 1\ \text{if}\ r < \frac{1}{1+e^{-v_{id}}}\ \text{else}\ 0Python code
# Full tested implementation is shown on the PSO algorithm card (Python tab).
from math import sqrt
phi = 4.1
chi = 2 / abs(2 - phi - sqrt(phi**2 - 4 * phi))
print(round(chi, 4), round(chi * phi / 2, 5)) # 0.7298 1.49618Simplified teaching code that works with NumPy only; for research experiments use a documented library and fix the random seed.
Practical exercise
In the simulator, run PSO on Ackley in two dimensions and watch the particles move, then change c₂ to 2.5 and notice the effect of stronger social attraction.
Common mistakes
- Not limiting the velocity with w≥1.
- Using gbest on highly multimodal functions without monitoring diversity.
- Confusing the original 1995 version (without w) with the inertia-weight version.
Summary
PSO = inertia + personal experience + social experience; the parameters and the topology set the balance of the search.
References
- Verified Particle swarm optimization J. Kennedy; R. Eberhart (1995) 10.1109/icnn.1995.488968
Related papers in the repository
- Particle swarm optimization Verified
Short quiz
5 questions are chosen at random from 16 questions linked to this lesson, and the quiz is graded on the server.
Links within the lab
- Algorithms
- Models
- Optimization types
- Related lessons
- In the paths
