CALCULATE THE GLOBAL MAXIMA OF A STALAGMITE FUNCTION BY USING GENETIC ALGORITHM METHOD
AIM: To create the global maxima of a stalagmite function using GENETIC ALGORITH
SOFTWARE: MATLAB R2019b
GENETIC ALGORITH - In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection.
PROCEDURE:
STEP1: Open MATLAB.
STEP2: Select Editor window.
STEP3: Input code required to create a row and coulmn vector.
STEP4: Use SAVE option to save your work.
CODE GENERATED:
NOTE: Initially use the basic code
clear all (Previous Worked data are cleared)
close all (Previous Worked graphs are cleared)
clc (Previous Worked commands used in command window are cleared).
CREATE A FUNCTION CODE STALAGMITE:
function v = stalagmite(input_vector)
x=input_vector(1);
y=input_vector(2);
f1x=(sin(5.1*pi*x+0.5))^6;
f1y=(sin(5.1*pi*y+0.5))^6;
f2x=exp(-4*log(2)*(x-0.0667)^2/0.64);
f2y=exp(-4*log(2)*(y-0.0667)^2/0.64);
v=-f1x*f1y*f2x*f2y;
end
CREATE GENETIC ALGORITHM (GA) CODES:
clear all
close all
clc
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=100;
[xx,yy]=meshgrid(x,y);
for i=1:length(xx)
for j=1:length(yy)
input_vector(1)=xx(i,j);
input_vector(2)=yy(i,j);
f(i,j)=stalagmite(input_vector);
end
end
%study 1 unbound inputs
tic
for i=1:num_cases
[input,fopt(i)]=ga(@stalagmite,2);
xopt(i)=input(1);
yopt(i)=input(2);
end
study1_time=toc;
figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'marker','*','markersize',6,'markerfacecolor','b')
title('STUDY 1')
subplot(2,1,2)
plot(-fopt)
xlabel('ITERATION')
ylabel('MINIMUM')
shading interp
% study 2 bounded inputs
tic
for i=1:num_cases
[input,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
xopt(i)=input(1);
yopt(i)=input(2);
end
study2_time=toc;
figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'marker','*','markersize',6,'markerfacecolor','b')
title('STUDY 2')
subplot(2,1,2)
plot(-fopt)
xlabel('ITERATION')
ylabel('MINIMUM')
shading interp
%study 3 bounded inputs with increase in population
options = optimoptions('ga');
options = optimoptions(options,'Populationsize',200);
tic
for i=1:num_cases
[input,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],options);
xopt(i)=input(1);
yopt(i)=input(2);
end
study3_time=toc;
figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'marker','*','markersize',6,'markerfacecolor','b')
title('STUDY 3')
subplot(2,1,2)
plot(-fopt)
xlabel('ITERATION')
ylabel('MINIMUM')
shading interp
CODING EXPLAINED:
We create a meshgrid and plot a surface pot for the respective function. Values (0.6 0.6).
We run the program by inserting "STALAGMITE FUNCTION CODE" into "GENETIC ALGORITHM CODE" to get "GLOBAL MAXIMA".
Three different case studies are created to understand the different output we get by giving different input values.
Finally we plot the variuous values of time range in each case studies.
STUDY 1:
We allow the genetic algorithm to generate population in the entire domain, without giving any input parameters.
Genetic algorithm function "ga(@stalagmite,2)" generated.
Plot shows the maximum values for various population, FOR ITERATION100. (50 is the basic default number of iteration provided by the MATLAB.
Below plot shows us that the maxima values lies between (less that 0.1 -1).
STUDY 2:
Allowed genetic algorithm to generate population for the specificed upper and lower bounds (0;1) for 100 iterations.
Function used "ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],options)".
Global maixma values lies between (0 -0.3).
Plot shows that the maxima values lies among the 4 points which were found.
STUDY 3:
Genetic algorithm to generate the population for the specified domain range and given popluation range is 200.
Function for global maixma points
options = optimoptions('ga');
options = optimoptions(options,'Populationsize',200);
ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],options) and lies between (0 -0.1).
RESULTS:
STUDY 1 - 7.6427
STUDY 2 - 11.380
STUDY 3 - 36.6557
CONCLUSION:
Using matlab we learned and able to find global maxima for the stalagmite function.