7 Swarm intelligence: Particles
Swarm intelligence uses the collective, emergent behavior of many simple agents to solve hard problems, and particle swarm optimization (PSO) is a practical embodiment of this idea. Inspired by phenomena like bird flocks and bee swarms—and abstracted by rules such as alignment, cohesion, and separation—PSO deploys a population of “particles” that explore a search space and gravitate toward promising regions discovered by themselves and their peers. It is particularly effective for large, continuous, and high-dimensional optimization tasks in which exhaustive search is infeasible and the global optimum can be obscured by many local optima.
The chapter reframes optimization as navigating a multidimensional landscape defined by a fitness function, where each input variable is a dimension and the function value represents solution quality. Through a concrete drone-design example (cast on a known benchmark surface), it shows how particles carry position, velocity, and a memory of their personal best, while the swarm tracks the global best. PSO’s lifecycle is simple but powerful: initialize a well-distributed swarm, evaluate fitness, and iteratively update velocities and positions. Movement blends three forces: inertia (momentum for exploration), a cognitive pull toward a particle’s personal best, and a social pull toward the swarm’s best. Tuning particle count, initialization, and the inertia/cognitive/social constants balances exploration and exploitation to avoid premature convergence while accelerating progress toward good solutions.
Convergence is monitored across iterations, with practical stopping criteria such as a fixed budget or stagnation of the best fitness; parameters can be adjusted if the swarm stalls in a local optimum. In the worked example, the swarm correctly converges to the known global optimum, illustrating PSO’s dynamics and the role of personal and global memories. Beyond toy functions, PSO serves as a versatile black-box optimizer: it can co-optimize neural network weights, improve motion tracking in videos, enhance speech by tuning noise-reduction filters, and even configure electrode directions in deep brain stimulation to maximize therapeutic targets while minimizing side effects and energy use. Overall, PSO offers an intuitive, implementation-friendly approach to navigating vast search spaces with minimal problem-specific assumptions.
An example bird flock formation
Rules that guide a swarm
A bee swarm converging on its goal
Pepper spice vs. pepper size
Pepper spice vs. pepper size trend
An example function for pepper spice vs. pepper size
Pepper spice vs. pepper size vs. pepper color
A function visualized in the 3D space as a plane
The function that represents the surface in figure 7.8
The drone optimization example
The example function for optimizing aluminum (x) and plastic (y)
Properties of a particle
The life cycle of a particle swarm optimization algorithm
Set up the particles.
A visualization of the initial positions of four particles in a 3D plane
Calculate the fitness of the particles.
The example function for optimizing aluminum (x) and plastic (y)
Fitness calculations for each particle
Update the positions of the particles.
The movement of particles over five iterations
Formula to calculate velocity
The intuition of the factors influencing velocity updates
Particle velocity calculation walkthrough
Calculating the new position of a particle
Particle velocity calculation walkthrough
A visualization of the movement of particles in the search space
Visualization of convergence of particles and a known surface
Has the algorithm reached a stopping condition?
Exploration converging and exploiting
Example of factors involved for probes in deep brain stimulation
Grokking AI Algorithms, Second Edition ebook for free