Particle Swarm Optimization Matlab Toolbox 1 - Conformat
Particle Swarm Optimization Matlab Toolbox 1 - Conformat
Brian Birge
NCSU, MAE Dept.
726 N. West St., #B
Raleigh, NC 27603
birgeb@bellsouth.net
Abstract - A Particle Swarm Optimization Toolbox (PSOt) for Computational Intelligence arena. With the Particle Swarm
use with the Matlab scientific programming environment has Optimization Toolbox (PSOt), users can apply the algorithm
been developed. PSO is introduced briefly and then the use of to their problem without having to write their own PSO code
the toolbox is explained with some examples. A link to or really even understand much about PSO. Users can train
downloadable code is provided.
an Artificial Neural Network (ANN) with PSO and/or apply
PSO to their more general problem.
I. GENERAL INFORMATION
This paper originally came out of an effort to replace standard
A. Particle Swarm Optimization Toolbox (PSOt), Summary of
backpropagation trained ANNs with PSO in order to make
Included Files
better ANNs and was inspired by the freely available Matlab
implementation of a Genetic Algorithm function optimizer by
Main files:
Houck, Joines, and Kay referenced at the end of this paper
1) PSO – finds min/max of arbitrary MISO functions
[3].
using PSO
2) trainPSO – Function to train neural nets using PSO
It is hoped this suite of programs will be useful to classroom
3) tpso1,2,3 – called by trainPSO for training 0 hidden
lecturers wishing to add a PSO unit as well as fellow
layer, 1 hidden layer, and 2 hidden layer ANNs
researchers in Computational Intelligence.
respectively.
C. Matlab
Support files:
4) wrapmat – convert vector(s) into matrix(ces)
Matlab is a scientific computing language developed by
5) unwrapmat – convert any 2d matrix(ces) into a row
Mathworks that is run in interpreter mode on a wide variety
vector(s)
of operating systems. It is extremely powerful, simple to use,
6) normalize – takes a 2D matrix and reformats it to
and can be found in most research and engineering
any specified range
environments. It gets more powerful and specialized with the
7) goplotpso – called by trainpso for graphical display
addition of ‘toolboxes’, additional functions added to the
during training
Matlab environment by various developers for specific tasks
or fie lds. For example, the Neural Net toolbox adds functions
Demo and miscellaneous files:
that allow one to develop ANNs and the Control System
8) DemoTrainPSO – shows an example of using PSO
toolbox includes many traditional engineering controls
to train a neural net to the XOR function
functions. The PSOt aims to add not only stand alone
9) f6 – Schaffer’s f6 function
function optimization using PSO but also the ability to
10) hypara – 4 dimensional hyperbolic paraboloid
interface easily with the Neural Net toolbox, training ANNs
function
with PSO rather than backpropagation. The reader is
11) hypara2 – 8 dimensional hyperbolic paraboloid
expected to have a basic understanding of Matlab to use the
function
PSOt. Please refer to the appropriate Matlab documentation
to understand the code syntax examples [6].
The toolbox may be downloaded freely as a self extracting
zipfile from: http://www4.ncsu.edu/~bkbirge/PSO/PSOt.exe
D. Particle Swarm Optimization (PSO)
B. Introduction
Inspired initially by flocking birds, Particle Swarm
Optimization (PSO) is another form of Evolutionary
With the growth of more mainstream interest in
Computation and is stochastic in nature much like Genetic
computational intelligence algorithms applied to real-world
Algorithms. Instead of a constantly dying and mutating GA
engineering problems there is a need to build tools that can be
population we have a set number of particles that fly through
used in a wide variety of environments, from classroom to
the hyperspace of the problem. A minimization (or
field. Particle Swarm Optimization (PSO) is one recent
maximization) of the problem topology is found both by a
technique that has been used with great success in the
particle remembering its own past best position and the entire
group’s (or flock’s, or swarm’s) best overall position. This B. Development/Program Usage
algorithm has been shown to have GA like advantages
without the big computational hit. The set of programs that comprise the PSOt are designed with
two purposes in mind. The first purpose is to act as a
The PSO algorithm is based on the concept that complex standalone function optimizer. The second purpose is to
behavior follows from a few simple rules [5]. replace backpropagation with PSO during neural net training.
The intricacies of the algorithm are briefly outlined here. For C. Finding global min/max of MISO function using PSO
more details and discussion see the references, especially [4],
[5], and [8]. The first goal is achieved with the Matlab script ‘PSO.m’. It
is very simple to use but can be very flexible as well. The
II. TECHNICAL INFORMATION function only works with single input single output (SISO) or
multi-input single output (MISO) functions that need all the
A. PSO Algorithm input space searched. It will work with any size dimension of
input space, the toolbox miscellaneous functions include 2D,
The Basic PSO algorithm consists of the velocity and 3D, and 7D functions to experiment with. The PSO function
position equations: can either minimize or maximize the target function. The
basic syntax can be found by typing ‘help PSO’.
vi ( k +1) = vi ( k ) +γ 1i ( p i − xi ( k ) ) +γ 2i ( G − xi ( k ) ) (1)
TABLE I
MATLAB OUTPUT FOR TYPING ‘HELP PSO’
xi ( k +1) = xi ( k ) +v i (k +1) (2)
%[optOUT]=PSO(functname,D), or:
%[optOUT,tr,te]=
i – particle index % PSO(functname,D,VarRange,minmax,PSOparams)
k – discrete time index %
v – velocity of ith particle %Inputs:
x – position of ith particle % functname–
% name (string) of matlab function to optimize
p – best position found by ith particle (personal best) % D-
G – best position found by swarm (global best, best of % # of inputs to the function (problem dimension)
personal bests ) %
γ1,2 – random numbers on the interval [0,1] applied to thi %Optional Inputs:
% VarRange-
particle % matrix of ranges for input variable,
% default -100 to 100, form:
The most used PSO form is to include an inertia term and % [ min1 max1
% min2 max2
acceleration constants , hence the Common PSO algorithm: % ...
% minD maxD ]
v ( k +1) = %
i % minmax-
φ ( k ) v ( k ) + α γ1i ( pi − xi ( k ) ) + α γ 2i ( G − xi ( k ) ) (3)
% if 0 then funct is minimized
i 1 2 % if 1 then funct maximized, default=0
0
The output of the function is returned as a column vector of
the final global best position. The last entry in the vector is -20
the global best value. Optional outputs are the # of epochs it
took to reach consensus that optimization had occurred and -40
-10 -5 0 5 10 15 20 25
the value of global best as a function of epoch. Pos dimension 1
0
PSO: 2 dimensional prob search, Gbestval=0.0019752
10
A simple example would be to find the minimum of the sine
function from 0 to π/2:
Gbest value
-1
10
-2
10
pso(‘sin’,1,[0,pi/2],0)
-3
10
The name of the function is surrounded by single quotes, the 0 10 20 30 40 50 60 70 80
epoch
dimension of the problem is 1 (only one input so only one
searchable dimension), the range is from 0 to π/2, and the
minmax flag is set to 0 indicating we want to find the Running the ‘PSO.m’ function to find the maximum of f6
minimum. with the same bounds yields the following table.
TABLE V TABLE VI
‘TRAINPSO.M’ PARAMETERS MATLAB OUTPUT FOR ‘DEMOTRAINPSO.M’
-2
-4
-10 -8 -6 -4 -2 0 2 4
pos dim 1
E. Conclusion