Swarm intelligence: Particles
Particle swarm optimization (PSO) is a swarm algorithm. Swarm intelligence relies on emergent behavior of many individuals to solve difficult problems as a collective. Bird flocks are an ideal example of swarm intelligence in nature. When a single bird is flying, it might attempt several maneuvers and techniques to preserve energy, like jumping and gliding through the air or leveraging wind currents to carry it in the direction it wants to travel. This behavior indicates some primitive level of intelligence in a single individual. But birds also have the need to migrate between different seasons. In winter, there is less availability of insects and other food, and suitable nesting locations also become scarce. Birds tend to flock to warmer areas to take advantage of better weather conditions, which improves their likelihood of survival. Migration is usually not a short trip. It takes thousands of miles of movement to arrive at an area with suitable conditions.
When birds travel these long distances, they tend to flock. Birds flock because there is strength in numbers when facing predators; additionally, it saves energy. The formation that we observe in bird flocks has many advantages. A large, strong bird will take the lead, and when it flaps its wings, it creates uplift for the birds behind it. These birds can fly while using significantly less energy. Flocks can change leaders if the direction changes or if the leader becomes fatigued. When a specific bird moves out of formation, it experiences more difficulty in flying via air resistance and corrects its movement to get back into formation.

Rules that guide bird flocks
Craig Reynolds developed a simulator program in 1987 to understand the attributes of emergent behavior in bird flocks and used the following rules to guide the group. These rules are extracted from observation of bird flocks:
- Alignment — An individual should steer in the average heading of its neighbors to ensure that the group travels in a similar direction.
- Cohesion — An individual should move toward the average position of its neighbors to maintain the formation of the group.
- Separation — An individual should avoid crowding or colliding with its neighbors to ensure that individuals do not collide, disrupting the group.

A drone problem
Imagine that we are developing a drone, and several materials are used to create its body and propeller wings (the blades that make it fly). Through many research trials, we have found that different amounts of two specific materials yield different results in terms of optimal performance for lifting the drone and resisting strong winds. These two materials are aluminum, for the chassis, and plastic, for the blades. Too much or too little of either material will result in a poor-performing drone. But several combinations yield a good-performing drone, and only one combination results in an exceptionally well- performing drone.

Particle swarm optimization (PSO)
Three components are used to calculate the new velocity of each particle: inertia, cognitive, and social. Each component influences the movement of the particle. We will look at each of the components in isolation before diving into how they are combined to update the velocity and, ultimately, the position of a particle:
-
Inertia — The inertia component represents the resistance to movement or change in direction for a specific particle that influences its velocity. The inertia component consists of two values: the inertia magnitude and the current velocity of the particle. The inertia value is a number between 0 and 1.
-
Cognitive — The cognitive constant is a number greater than 0 and less than 2. A greater cognitive constant encourages individual independence (or personal exploration), preventing the particle from blindly following the swarm and ensuring it thoroughly checks the area around its own discoveries.
-
Social — The social component represents the ability of a particle to interact with the swarm. A particle knows the best position in the swarm and uses this information to influence its movement. Social acceleration is determined by using a constant and scaling it with a random number. The social constant remains the same for the lifetime of the algorithm, and the random factor encourages diversity in favoring the social factor.

Optimize the drone
Play with the values for plastic and aluminum to find a well-performing drone, then see how fast a PSO algorithm can find the best-performing drone. Particles explore aluminium (x) and plastic (y) mixes to minimize the stability function. Pick the aluminium mix (x) and plastic mix (y) that minimizes: f(x,y) = (x + 2y - 7)² + (2x + 4 - 5)²