PSO updates each particle's velocity as a weighted sum of three influences: its own momentum (inertia), attraction toward its personal best position (cognitive), and attraction toward the swarm's global best (social) — as introduced by Kennedy & Eberhart (1995), with the inertia weight refinement by Shi & Eberhart (1998).
The animation cycles through the velocity decomposition for a single particle with fixed parameters; the right panel gives the update equations and a pseudocode sketch of the full algorithm.
For a fully interactive simulation with adjustable parameters and live fitness landscapes, see Tab ② PSO Simulation.
Velocity decompositionInitializing…
Current position xPersonal best p✦Global best g→Current velocity v
➡ New Velocity
vi(t+1) = ωvi + φprp(pi−xi) + φgrg(g−xi)+ η
Clamped to |v| ≤ vmax. Position updated: xi(t+1) = xi(t) + vi(t+1). The η term is optional.
Pulls toward the particle's own historical best. Stochastic weight rp ∼ U(0,1) each step.
③ Social (Global Best)
φg · rg · (g − xi(t))
Pulls toward the best position any particle has ever visited. Separate stochastic weight rg ∼ U(0,1).
⊕ Velocity Noise — non-standard
η ∼ 𝒩(0, σ2I)
Additive Gaussian noise applied each step, independent of pbest and gbest.
Not part of Kennedy & Eberhart's (1995) canonical PSO —
inspired by the Vicsek (1995) flocking model and enables independent hill climbing by individuals.
Algorithm Sketch
initialize N particles randomly
xi ∼ U(lb, ub); vi ∼ U(−vmax, vmax)
pi ← xi; g ← argmaxi f(xi)
repeatfor each particle i:
rp, rg ∼ U(0,1)
ηi ∼ 𝒩(0,σ²I)// non-standard
vi ← ωvi + φprp(pi−xi)
+ φgrg(g−xi)
+ ηi// non-standard
vi ← clip(vi, −vmax, vmax)
xi ← xi + viif f(xi) > f(pi): pi ← xiif f(xi) > f(g): g ← xiuntil// mean|v| < ε or iter ≥ max
Convergence guarantee
Clerc & Kennedy (2002) analyzed convergence by writing the update as
v(t+1) = χ [v(t) + φp rp(p−x) + φg rg(g−x)],
where χ is the constriction factor. Convergence can be guaranteed under the conditions
χ = 2 / |2−φ−√(φ2−4φ)|
where φ ≜ φp + φg and φp + φg > 4
(which ensures χ is real and less than 1).
The canonical choice φp = φg = 2.05 gives φ = 4.1 and χ ≈ 0.729 in this constriction-factor form.
Distributing χ into the bracket recovers the inertia-weight form used here,
with ω = χ ≈ 0.729 and effective coefficients χφp = χφg ≈ 1.494.
The displayed φp, φg sliders on Tab ② control these distributed effective coefficients (which sum to > 4χ).
Watch the swarm navigate a 2-D fitness landscape in real time.
Each particle shows its velocity arrow and a hollow ghost at its personal best.
The global best is marked with a ✦.
Adjust ω, φp, φg, swarm size (N), and maximum speed (vmax), then hit Run (or Resume after pausing).
Fitness landscapeidle
ParticlePersonal best✦Global best→Velocity
g-best / max p-bestmedian p-bestmean |v| (norm.)landscape max
Landscape
PSO Parameters
ω0.72
φp1.49
φg1.49
N20
vmax1.00
Display
Show velocity arrows
Show personal bests
Velocity noise (non-standard)
σ0.20
η ∼ 𝒩(0,σ2I) added to velocity each step. Not in canonical PSO. Inspired by Vicsek (1995).
Controls
speed1×
Iteration
—
g-best f
—
mean |v|
—
max |v|
—
Convergence
The φp, φg sliders above control the distributed effective coefficients χφp, χφg,
where ω = χ ≈ 0.729 is the constriction factor (Clerc & Kennedy, 2002).
Convergence is guaranteed when the raw coefficients satisfy φp + φg > 4 in the constriction-factor form —
equivalent to ω ≈ 0.729 with the default slider values of 1.49.
See Tab ① for the full derivation.