While there exist many introductory materials on Particle Swarm Optimization (PSO), it is best to have an intuitive example, simple, understandable at first reading, and illustrative. I personally do not like those examples that try to bring all intricacies together. Here comes the simplest example I guess: to find a minimum for the function:
It is know that the optimal solution is found when x=-1, and the minimum is f(x)=0;
The below video demonstrate the results of finding this optimal solution using PSO based approach:
As you can see, after some initial random movements of the design variables, the design variable gradually converges to x=-1 (the black curve) and the optimal value reaches 0.
The basic procedures to implement this PSO based approach are as follows:
[1] Create a collection of particles, each particle represents an instance of the design variable. In this case, the design variable is a scalar-valued single parameter:
%Initialize a particle swarm with nParticals |
[2] For these particles, evaluate their performances:
for i=1:length(x) |
[3] Find the best of these particles, which generates the minimum errors
ErrMat=cell2mat(err); % Convert cell to array |
[4] The minimum value got so far is both the local best and the global best, keep them down for later use:
lBestX=x{idx}; % Local best |
[5] For each particles, move them according to the formula:
alpha1=2.0; % Local best influence; |
For details of these parameters and their physical meanings, Google “Particle Swarm Optimization”, a quick view of the result goes here.
[6] Terminate when the some conditions are met:
while gBestY> 1e-6 |
Here, RunMoveOnce() refers to the process described in [5].
The Matlab files can be download it below. Enjoy!
Filed under: Maths, Programming
