Function Optimization using Genetic Algorithm and Particle Swarm Optimization-Results and Comparison

In this article some experiments and their results are discussed for minimization of Rastrigin function, a famous mathematical function used in Optimization Techniques evaluation. The experiments are performed on certain setup, parameters and system. This has been performed using Genetic Algorithm (GA) and Particle Swarm Optimization (PSO). The fitness function is the given function to be optimized. This article just pays focus on the way experiments are to be performed and analyzed in students lab and by mentors teaching Machine Learning results do not play a role in benchmarking or changing existing theories. It is just for elaboration for the purpose of academicians and students to learn the art of optimizing function with the help of GA and PSO.

This function is given by

The function is usually evaluated on xi ∈ [-5.12, 5.12], for all i = 1, …, n . This has been tried on 5 different values of n between 10 and 100 as follows. Taking N as the size of the chromosome for GA and PSO implementation and population size of 10.

The Matlab implementation of fitness function is

%Fitness function
function z= testfunction(x)
%z= (x’x);
[M,N]=size(x);
z=[];
sum =0;
for j=1:M
for i = 1:N
sum = sum + (x(j,i)x(j,i) – 10 * cos (23.14x(j,i)));
end
z= [z;sum + 10*N]
end

The following table shows the experimental results.

NGA Final Minimum Value after 500 iterationsPSO Global Minimum Value after 500 iterations with C1=1, C2=2PSO Global Minimum Value after 500 iterations with C1=3, C2=3PSO Global Minimum Value after 500 iterations with C1=3, C2=2PSO Global Minimum Value after 500 iterations with C1=2, C2=3
1027.8663(500 epochs)/ 9.1 in 1000 epochs12.723  4.00028.46097.0004
20113.9635(500 epochs)74.58413.00131.87929.679
40399.6707 (500 epochs) / 235 in 1000 epochs   191.02 43.23 127.1 115.58
60918.9643(500 epochs)/ 619 (1000 epochs)372.296.065193.74189.75
801392.1043(500 epochs)    489.16220.28314.04286.96

The general analysis of results is that PSO is performing better than GA here given the same number of iterations. Though GA solutions are gradually decreasing while PSO solutions are oscillating.  Within PSO the c1=3, c2=3 seems to perform best, c1=1 and c2=2 seem to perform the worst in achieving global minimum. More details and comments below.

Num of chromosomes : 10

One point crossover GA., with 5% mutation rate.

Maximum  number of iterations: 500.

Graphical Visualization of Results

Command for plots:

plot(ga.iters,ga.minc,’:’,pso1.iters,pso1.minc,’green’, pso2.iters, pso2.minc ,’blue’ ,pso3.iters ,pso3.minc, ‘red’,pso4.iters,pso4.minc,’black’);

Here is plot for N=80

Green: PSO1: with parameters : c1=1,c2=2 : Oscillates and convergence not as fast as other parameters.

Blue: PSO2 : with parameters : c1=3,c2=3  :  Oscillates and reaches towards minima.

Red: PSO3 : with parameters : c1=3,c2=2  : Oscillates.  Reaches towards minima

Black: PSO4 : with parameters :  c1=2,c2=3 : Oscillates.  Reaches  towards minima

Dots : GA, still decreasing and is more stable though global minimum is not less than PSO.

And comparing GA and PSO , GA seems not to oscillates and be stable though its minimum not attained as fast.

PSO1 with c1=1,c2=2, seem to not be as fast in attaining minimum as compared to other parameters which are almost equivalent in attaining minimum. Here is separate result of c1=1, c2=2.

Plot of the three competing models is as follows:

Results for N=60

Green: PSO1: with parameters: c1=1,c2=2: Oscillates and convergence not as fast as other parameters.

Blue: PSO2 : with parameters : c1=3,c2=3  :  Oscillates and reaches towards minima.

Red: PSO3 : with parameters : c1=3,c2=2  : Oscillates.  Reaches towards minima

Black: PSO4 : with parameters :  c1=2,c2=3 : Oscillates.  Reaches  towards minima

Dots: GA, still decreasing and is more stable though global minimum is not less than PSO.

And comparing GA and PSO , GA seems not to oscillates and be stable though its minimum not attained as fast.

Plot of three competing models as follows

PSO1 with c1=1,c2=2, seem to not be as fast in attaining minimum as compared to other parameters which are almost equivalent in attaining minimum. Here is separate result of c1=1, c2=2.

Results for N=40

Green: PSO1: with parameters : c1=1,c2=2 : Oscillates and convergence not as fast as other parameters.

Blue: PSO2 : with parameters : c1=3,c2=3  :  Oscillates and reaches towards minima.

Red: PSO3 : with parameters : c1=3,c2=2  : Oscillates.  Reaches towards minima

Black: PSO4 : with parameters :  c1=2,c2=3 : Oscillates.  Reaches  towards minima

Dots: GA, still decreasing and is more stable though global minimum is not less than pso.

And comparing GA and PSO , GA seems not to oscillates so much and be stable though its minimum not attained as fast.

PSO1 with c1=1,c2=2, seem to not be as fast in attaining minimum as compared to other parameters which are almost equivalent in attaining minimum. Here is separate result of c1=1, c2=2.

Results for N=20

Green: PSO1: with parameters : c1=1,c2=2 : Oscillates and convergence not as fast as other parameters.

Blue: PSO2 : with parameters : c1=3,c2=3  :  Oscillates and reaches towards minima.

Red: PSO3 : with parameters : c1=3,c2=2  : Oscillates.  Reaches towards minima

Black: PSO4 : with parameters :  c1=2,c2=3 : Oscillates.  Reaches  towards minima

Dots: GA, still decreasing and is more stable though global minimum is not less than PSO.

And comparing GA and PSO , GA seems not to oscillates and be stable though its minimum not attained as fast.

PSO1 with c1=1,c2=2, seem to not be as fast in attaining minimum as compared to other parameters which are almost equivalent in attaining minimum. Here is separate result of c1=1, c2=2.

Results for N=11

Green: PSO1: with parameters : c1=1,c2=2 : Oscillates and convergence not as fast as other parameters.

Blue: PSO2 : with parameters : c1=3,c2=3  :  Oscillates and reaches towards minima.

Red: PSO3 : with parameters : c1=3,c2=2  : Oscillates.  Reaches towards minima

Black: PSO4 : with parameters :  c1=2,c2=3 : Oscillates.  Reaches  towards minima

Dots: GA, still decreasing and is more stable though global minimum is not less than PSO

And comparing GA and PSO , GA seems not to oscillates and be stable though its minimum not attained as fast.

PSO1 with c1=1,c2=2, seem to not be as fast in attaining minimum as compared to other parameters which are almost equivalent in attaining minimum. Here is separate result of c1=1, c2=2.

The experiments are performed on certain setup, parameters and system. The general impression and analysis are given at end of each experiment conducted. Changing parameters, the mutations functions, population to be performed for creating new chromosomes in case of GA drastically effects the results obtained. In a similar manner for PSO several parameters, initializations effect the results apart from C1 and C2 experimented above. The results are not benchmarks, they are elaborated for experimental setups in labs, and to be followed by mentors teaching Machine Learning Lab Work. For benchmark results look into peer-reviewed research papers.

Published by Nidhika

I have an eager research-based approach to solve problems in the various areas using my expertise. I find solutions based on my experience, research skills, strong knowledge Apart from profession, I have inherent interest in writing especially poems, stories, doing painting, cooking, photography, music to mention a few! And most important on my website you can find my views, ideas, my poems, stories, novels, my comments, my proposals, my blogs, my interests, my personal experiences and short occasional glimpses of my research work as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: