Project

global maxima of a stalagmite function

1.Genetic algorithm

Genetic algorithm actually based on random sampling .It starts with random number of inputs , you evaluate the function and then comes the concept of natural selections where you take two generations and basically mutate them and do cross over and create a new generation which is better. Genetic algorithm produces different results every time.

1.In this problem first the search space is deifned for the genetic algorithm and the number of times the algortihm have to run is also defined.genetic algorithm shows only the minimum optimized value

2.Then genetic algorithm is created by giving the function fitness value and number of variables in it.Then plots are created for function performance and sub plots are created for showing the optimum values.

3.Then for better organisizing the plots upper and lower boundaries are given in the algorithm.

4.For global minium the number of iterations in the algorithm are increased . The more the iterations the more time it takes to compute.

2.

%stalagmite function
function f=stalagmite(input_vector)

      
    x=input_vector(1);
    y=input_vector(2);

   term_1 = (sin(16.02*x + 0.5)).^6;
   term_2 = (sin(16.02*y + 0.5)).^6;
   term_3 = exp((-4*log(2)*((x-0.0667).^2))/(0.64));
   term_4 = exp((-4*log(2)*((y-0.0667).^2))/(0.64));
   a=(term_1.*term_2.*term_3.*term_4);
   F=1/1+[a];
   f=1-[F];
   
end




%Genetic algorithm 
clear all
close all
clc

x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=50
%creating 2 dimensional mesh array
[x,y]=meshgrid(x,y);

% evaulating the stalagmite function
for i = 1:length(x)
    for j = 1:length(y)
    input_vector(1)=x(i,j);
    input_vector(2)=y(i,j);
    f(i,j)=stalagmite(input_vector);
    
    end
end  
[inputs,xval]=ga(@stalagmite,2)
surf(x,y,f)
shading interp
hold on


%1.genetic algorithm statistical  behaviour
tic
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
study_time1=toc;
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5)
title(\'unbounded inputs\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')
hold on




%2.genetic algorithm statiscal behaviour with  upper and lower boundaries.
tic
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end

study_time2=toc
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5)
title(\'bounded inputs\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')
hold on



%3.genetic algorithm -increasing iterations to 100. 
options=optimoptions(\'ga\')
options=optimoptions(options,\'populationsize\',100)
tic
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
study_time3=toc
figure(4)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5)
title(\'bounded inputs with more iterations_100\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')


%4.genetic algorithm -increasing iterations to 250.
options=optimoptions(\'ga\')
options=optimoptions(options,\'populationsize\',250)
tic
for i=1:num_cases
    [inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
end
study_time4=toc
figure(5)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5)
title(\'bounded inputs with more iterations-250\')
subplot(2,1,2)
plot(fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')




.

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.