OPTIMIZATION OF STALAGMITE FUNCTION USING GENETIC ALGORITHM
WHAT IS GENETIC ALGORITHM?
WHAT IS OPTIMIZATION PROBLEM?
HOW GENETIC ALGORITHM WORKS?
Genetic algorithm is a method for solving both constrained & unconstrained optimization problems based on natural slection process that mimics or simulates biological evolution.
Optimization Problem :- In this problem, we have to select the best element (with regard to some condition/criterion) from the given available alternatives
It consist of maximising or minimising a objective function by systematically choosing inputs values from the allowed set of inputs & computing the values of the function.
GENETIC ALGORITHM METHODOLOGY:-
Genetic algorithm randomly selects individuals from the current population & uses them as parents to produce the children for the next generation ,over successive generations,the population evolves towards the optimal solution.
there are three main steps or procedure by which genetic algorithm proceeds:
1)Selection: this step involves selection of best individuals from the population according to there fitness scores (this is obtained by inputting the individuals values into objective function hence from the output results individual fitness score (i.e closeness to optimal solution) is decided)
these selected individuals are taken as parents and hence give rise to next sucessive generation i.e their childrens
2) childrens are produced either by CROSS OVER i.e by combining the vector entries of a pair of parents or by MUTATION i.e changing the single parent values
3) some childrens are also produced as such from the individuals of previous generation which have best fitness values ,these are konwn as ELITE childrens.
As the sucessive generation proceeds , childrens get more and more closer to optimal solution or minimum point.
NOTE:: ga() function is a in-built function to find minimum of the fitness function.
hence to find maximum from the ga()function we have to change our objective function sign by -ve , i.e -f(x) will give us maxima point
PROGRAM TO OPTIMIZE THE STALAGMITE FUNCTION :-
% Defining our region of search
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
%Creating a 2D mesh which will help us to select all possibilities
[XX , YY] = meshgrid(x,y);
f = zeros(150);
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
%STUDYING AND ANALYSING THE RESULTS OBTAINED
% STUDY (1)
num_repeats = 100;
tic
for k = 1:num_repeats
[inputs , fval(k)] = ga(@stalagmite,2);
xopt(k) = inputs(1);
yopt(k) = inputs(2);
end
study_time_1 = toc;
figure(1)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fval,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\"Unbounbed inputs\")
subplot(2,1,2)
plot(fval)
xlabel(\"Iterations\")
ylabel(\"function minimum\")
%Study 2 bounding by upper and lower limits of x from 0 to 1 and y from 0 to 1
for k = 1:num_repeats
[inputs , fval(k)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
xopt(k) = inputs(1);
yopt(k) = inputs(2);
end
study_time_2 = toc;
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fval,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\"Bounbed inputs\")
subplot(2,1,2)
plot(fval)
xlabel(\"Iterations\")
ylabel(\"function minimum\")
%Study (3) now increasing population size to increase accurarcy
options = optimoptions(\'ga\');
options = optimoptions(options,\'PopulationSize\',300);
for k = 1:num_repeats
[inputs , fval(k)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
xopt(k) = inputs(1);
yopt(k) = inputs(2);
end
study_time_3 = toc;
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,f)
shading interp
plot3(xopt,yopt,fval,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\"Bounded inputs with modified population size\")
subplot(2,1,2)
plot(fval)
xlabel(\"Iterations\")
ylabel(\"function minimum\")
STALAGMITE FUNCTION :-
function [z]=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));
z = -(f1x).*(f2x).*(f1y).*(f2y);
end
OUTPUTS :
STUDY (1)
STUDY (2)
STUDY (3) population size is 300, iteration is 100 ,so finally we get only one peak point(value = 0.99999985 approx.)
as the population size increases the accuracy of result increases but alongwith it time duration of studying increases.