Social influence and social learning enable a person to maintain cognitive consistency. People solve problems by talking with other people about them, and as they interact their beliefs, attitudes, and behaviors change; the changes could typically be depicted as the individuals moving toward one another in a sociocognitive space.
The particle swarm simulates this kind of social optimization. A problem is given, and some way to evaluate a proposed solution to it exists in the form of a fitness function. A communication structure or social network is also defined, assigning neighbors for each individual to interact with. Then a population of individuals defined as random guesses at the problem solutions is initialized. These individuals are candidate solutions. They are also known as the particles, hence the name particle swarm. An iterative process to improve these candidate solutions is set in motion. The particles iteratively evaluate the fitness of the candidate solutions and remember the location where they had their best success. The individual's best solution is called the particle best or the local best. Each particle makes this information available to their neighbors. They are also able to see where their neighbors have had success. Movements through the search space are guided by these successes, with the population usually converging, by the end of a trial, on a problem solution better than that of non-swarm approach using the same methods.
The swarm is typically modelled by particles in multidimensional space that have a position and a velocity. These particles fly through hyperspace (i.e., ) and have two essential reasoning capabilities: their memory of their own best position and knowledge of the global or their neighborhood's best. In a minimization optimization problem, "best" simply meaning the position with the smallest objective value. Members of a swarm communicate good positions to each other and adjust their own position and velocity based on these good positions. So a particle has the following information to make a suitable change in its position and velocity:
The particle position and velocity update equations in the simplest form that govern the PSO are given by
As the swarm iterates, the fitness of the global best solution improves (decreases for minimization problem). It could happen that all particles being influenced by the global best eventually approach the global best, and there on the fitness never improves despite however many runs the PSO is iterated thereafter. The particles also move about in the search space in close proximity to the global best and not exploring the rest of search space. This phenomenon is called 'convergence'. If the inertial coefficient of the velocity is small, all particles could slow down until they approach zero velocity at the global best. The selection of coefficients in the velocity update equations affects the convergence and the ability of the swarm to find the optimum. One way to come out of the situation is to reinitialize the particles positions at intervals or when convergence is detected.
Some research approaches investigated the application of constriction coefficients and inertia weights. Numerous techniques for preventing premature convergence. The introduction of the fully informed particle swarm. Many variations on the social network topology, parameter-free, fully adaptive swarms, and some highly simplified models have been created. The algorithm has been analyzed as a dynamical system, and has been used in hundreds of engineering applications; it is used to compose music, to model markets and organizations, and in art installations.
The algorithm presented below uses the global best and local bests but no neighborhood bests. Neighborhood bests allow parallel exploration of the search space and reduce the susceptibility of PSO to falling into local minima, but slow down convergence speed. Note that neighborhoods merely slow down the proliferation of new bests, rather than creating isolated subswarms because of the overlapping of neighborhoods: to make neighborhoods of size 3, say, particle 1 would only communicate with particles 2 through 5, particle 2 with 3 through 6, and so on. But then a new best position discovered by particle 2's neighborhood would be communicated to particle 1's neighborhood at the next iteration of the PSO algorithm presented below. Smaller neighborhoods lead to slower convergence, while larger neighborhoods to faster convergence, with a global best representing a neighborhood consisting of the entire swarm. The tendency is now to use partly random neighborhoods (see Standard PSO on the Particle Swarm Central).
A single particle by itself is unable to accomplish anything. The power is in interactive collaboration.
Let be the fitness function that takes a particle's solution with several components in higher dimensional space and maps it to a single dimension metric. Let there be particles, each with associated positions and velocities , . Let be the current best position of each particle and let be the global best.
Note the following about the above algorithm:
// Initialize the particle positions and their velocities
for I = 1 to number of particles n do
for J = 1 to number of dimensions m do
X[I][J] = lower limit + (upper limit - lower limit) * uniform random number
V[I][J] = 0
enddo
enddo
// Initialize the global and local fitness to the worst possible
fitness_gbest = inf;
for I = 1 to number of particles n do
fitness_lbest[I] = inf
enddo
// Loop until convergence, in this example a finite number of iterations chosen
for k = 1 to number of iterations t do
// evaluate the fitness of each particle
fitness_X = evaluate_fitness(X)
// Update the local bests and their fitness
for I = 1 to number of particles n do
if (fitness_X(I) < fitness_lbest(I))
fitness_lbest[I] = fitness_X(I)
for J = 1 to number of dimensions m do
X_lbest[I,J] = X(I,J)
enddo
endif
enddo
// Update the global best and its fitness
[min_fitness, min_fitness_index] = min(fitness_X(I))
if (min_fitness < fitness_gbest)
fitness_gbest = min_fitness
for J = 1 to number of dimensions m do
X_gbest[J] = X(min_fitness_index,J)
enddo
endif
// Update the particle velocity and position
for I = 1 to number of particles n do
for J = 1 to number of dimensions m do
R1 = uniform random number
R2 = uniform random number
V[I][J] = w*V[I][J]
+ C1*R1*(X_lbest[I][J] - X[I][J])
+ C2*R2*(X_gbest[J] - X[I][J])
X[I][J] = X[I][J] + V[I][J]
enddo
enddo
enddo
Typical convergence conditions include reaching a certain number of iterations, reaching a certain fitness value, and so on.
Note that the research literature has uncovered many heuristics and variants determined to be better with respect to convergence speed and robustness, such as clever choices of , , and . There are also other variants of the algorithm, such as discretized versions for searching over subsets of rather than . There has also been experimentation with coevolutionary versions of the PSO algorithm with good results reported. Very frequently the value of is taken to decrease over time; e.g., one might have the PSO run for a certain number of iterations and DECREASE linearly from a starting value (0.9, say) to a final value (0.4, say) in order to facilitate exploitation over exploration in later states of the search. The literature is full of such heuristics. In other words, the canonical PSO algorithm is not as strong as various improvements which have been developed on several common function optimization benchmarks and consulting the literature for ideas on parameter choices and variants for particular problems is likely to be helpful.
Significant, non-trivial modifications have been developed for multi-objective optimization, versions designed to find solutions satisfying linear or non-linear constraints, as well as "niching" versions designed to find multiple solutions to problems where it is believed or known that there are multiple global minima which ought to be located.
There is also a modified version of the algorithm called repulsive particle swarm optimization, in which a new factor, called repulsion, is added to the basic algorithm step.
Although a relatively new paradigm, PSO has been applied to a variety of tasks, such as the training of artificial neural networks and for finite element updating. Very recently, PSO has been applied in combination with grammatical evolution to create a hybrid optimization paradigm called "grammatical swarms".

