Project

Genetic algorithm to find Global maxima

1)clear all
close all 
clc

%Genetic algorithm
a=linspae(0,1.2,210);
b=linspace(0,1.2,210);
[aa bb]=meshgrid(a,b);

for i=1:length(aa)
   for j=1:length(bb)
       s(1)=aa(i,j);
       s(2)=bb(i,j);
       f(i,j)=stalagmite(s);
       end
   end

options=optimoptions(\'ga\')
options=optimoptions(options,\'populationsize\',500)
 for i=1:length(aa)
[axis fval(i)]=ga(@stalagmite(s),2,[],[],[],[],[0;0],[0.9;0.9],[],[],options);
a1(i)=axis(1);
b1(i)=axis(2);
end

figure(3)
subplot(2,1,1);
surf(aa,bb,-f);
shading interp
xlabel(\'a value\');
ylabel(\'b value\');

plot3(a1,b1,-fval,\'marker\',\'o\',\'markersize\',2,\'markerfacecolor\',\'b\');
subplot(2,1,2);
plot(-fval)
xlabel(\'iterations\')
ylabel(\'function maximum\')

2)%Stalagmite function
function [F]=stalagmite(s)
a=s(1);
b=s(2);
f1=(sin(5.1*pi*a)+0.5)^6;
f2=(sin(5.1*pi*b)+0.5)^6;
f3=exp(-4*log(2)*(a-0.0667).^2./0.64;
f4=exp(-4*log(2)*(b-0.0667).^2./0.64;
F=-(f1*f2*f3*f4);
end

Brief note-
Genetic algorithm predicts the biological evolution. It takes the solution of individual from current population and gives children for next generation.
Genetic algorihm gives minimum value of the function, so in order to get the global maximum we will invert the funtion.

In GA program initially we will produce values of a and b by using linspace command.
Then meshgrid is used to produce matrix for plotting.
For every value of a and b it is alloted to Stalagmite function value.
Then options are used to modify the optimisation process so as to increase the populationsize.
Shading interp is used so as to hide the grid lines on the plot.
Plots are plotted \'b value\' vs \'a value\' and \'maximum optimisation\' vs \'iterations\'
so as to specify global maxima.


Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.