Investigation of the Global Maxima of a Stalagmite Function by using Genetic Algorithm
Genetic Algorithm (GA)s are Optimization Algorithms based on Darwin's theory of Natural Evolution. It is dependent on natural selection in natural genetics.
GA is based on an analogy with the genetic behaviour within a population of indivduals:
There are lots of species exist in our environment, but only the fittest species manage to survive and the unfit species are eliminated from the environment. So individuals in a species or, population compete for resources and mates. The most successful individuals produce more offsprings than the poorly performed individuals. Sometimes genes from good individuals move throughout the population and produce offsprings which are better than their parents. Thus each consecutive generation becomes more suitable for their environment. Based on this, GA is intoduced and hence it simulates the survival of the fittest among all the individuals over consecutive generation to solve a real world complex problem.
After random generation of initial population, GA algorithm evolves through three operators:
(1) Selection that equates to survival of the fittest i.e. Selection of the Most Successful Individuals,
(2) Crossover which represents mating between individuals i.e. Creation of Offsprings,
(3) Mutation which introduces further Random Modifications.
This robust technique delivers good as well as fast solution. Most of the real word complex problems lack of efficient methods to provide optimized solution, but GA provides efficient solution near the optimal solution.
This method is widely used in DNA Analysis, Encryption, Image Processing Technique, Vehicle Routing, Business and many other complex situations.
To calculate the Global Maxima of a Stalagmite Function:
The Fitness Function is,
function F = stalagmite_HW(input_vector);
f1 = (sin((5.1)*pi*input_vector(1)+0.5))^6;
f2 = exp((-4*log(2)*(input_vector(1)-0.667)^2)/0.64);
f3 = (sin((5.1)*pi*input_vector(2)+0.5))^6;
f4 = exp((-4*log(2)*(input_vector(2)-0.667)^2)/0.64);
f = f1*f2*f3*f4;
F = -f;
end
NB: With GA in Matlab, we can find the Minimas and Maximas of our function easily. GA always provides the minimum values of the function where the Global Minima is zero. But if we want to find the maximum of the function, -1 must be multiplied with the function. So in this program, " F = -1*f ". Now GA of F gives the minimum value of function F i.e. -f and this value is the maximum value of f.
The Stalagmite Main Function is,
close all
clear all
clc
% Input Search Space %
x = linspace(0,0.8,120);
y = linspace(0,0.8,120);
% No. of Variables %
nvars = 2;
% Boundary of GA Iterations %
LB = [0;0];
UB = [1;1];
% GA Iterations %
options = gaoptimset('MutationFcn',@mutationadaptfeasible,'PlotFcns',{@gaplotbestf @gaplotrange},'Generations',200,'PopulationSize',300,'Display','off');
% 1D--->2D meshing %
[A B] = meshgrid(x,y);
for i = 1:length(A);
for j = 1:length(B);
input_vector(1) = A(i,j);
input_vector(2) = B(i,j);
F_min(i,j) = stalagmite_HW(input_vector);
end
end
f_max=F_min;
% Plotting %
surfc(A,B,f_max)
xlabel('x')
ylabel('y')
zlabel('f max')
title('Maximas of Stalagmite Function')
% shading interp
[inputs,f_glob_max] = ga(@stalagmite_HW,nvars,[],[],[],[],LB,UB,[],options);
fprintf('The Global Maxima Value found: %g\n',f_glob_max);
fprintf('Final x value: %g\n', inputs(1));
fprintf('Final y value: %g\n', inputs(2));
RESULTS:
The Global Maxima Value found: -0.998774
Final x value: 0.655135
Final y value: 0.655134
PLOTS: