loading...
running...
How to use
Pick a preset or build your own: choose a landscape, the number of particles and the three coefficients w, c1, c2. White crosses mark the true optimum, the gold ring is the swarm's best point, white dots are personal bests. Watch the best-f and spread graphs: a swarm that stalls with a large spread is exploring, one that stalls with zero spread has collapsed. Drag to orbit, wheel to zoom. Space pauses, R resets.
The display case, drones, flag and textures were modelled and baked in Blender; Three.js r160 drives every object from the swarm state.
The science
Particle swarm optimisation (Kennedy and Eberhart, 1995) moves N candidate solutions through the search space. Each particle remembers the best place it has visited (pbest) and is pulled toward it and toward the best place known to its neighbourhood (gbest):
v(t+1) = w v(t) + c1 r1 (pbest - x(t)) + c2 r2 (gbest - x(t))
x(t+1) = x(t) + v(t+1), r1, r2 ~ U(0,1) drawn per dimension
Why the constants matter. Freeze pbest and gbest at the origin and look at one dimension. The expected position obeys the linear recurrence E[x(t+1)] = (1 + w - (c1+c2)/2) E[x(t)] - w E[x(t-1)], which is stable for w in (-1,1) when c1+c2 < 4(1+w). The random factors add variance, and the second moment is stable only when c1 + c2 < 24 (1 - w²) / (7 - 5w) (Poli, 2009). For the Clerc-Kennedy constants w = 0.7298, c1 = c2 = 1.49618 that bound is 3.35 and the sum is 2.99, so the swarm contracts. The live readout compares your c1+c2 with the bound for the current w. Above it the speed limit vmax is the only thing that keeps the swarm inside the box.
Neighbourhoods. In the global (star) topology every particle sees the single best point, so information spreads in one step and the swarm can collapse into the first good basin. In the ring topology each particle only sees its two neighbours; good news travels slowly around the ring, diversity lasts longer, and multimodal landscapes such as Rastrigin are solved more reliably at the cost of speed.
Test functions. Sphere is convex. Rastrigin adds a cosine ripple with about ten local minima per axis. Ackley has a flat plateau and a narrow central funnel. Rosenbrock has a curved valley whose floor is almost flat. Himmelblau has four equal global minima. Griewank is a shallow bowl with a small ripple. The minima used in the checks are the published ones.
What the checks do. (1) A Monte Carlo run of 60,000 independent one-dimensional particles is compared with the closed-form expected-value recurrence. (2) The same Monte Carlo run is repeated at 0.9 and 1.6 times the stability bound to see the RMS position shrink or grow. (3) The test functions are evaluated at their published minima. (4) The full 2-D swarm is run for 300 iterations on Sphere.
Simplifications. Boundaries are handled by clamping the particle to the wall and zeroing that velocity component. Updates are synchronous: every particle moves, then every fitness is evaluated, then the bests are updated. Results on a single seed are anecdotes, not benchmarks: change the seed to see the spread. The inertia schedule option (0.9 falling to 0.4) is the classic Shi-Eberhart schedule.
3D view. Relief height is log(1+f) scaled to the landscape maximum, so deep valleys are exaggerated for readability: height is not f itself.