Optimization of Stalagmite Function
a). Working of Genetic Algorithm
The following outline summarizes how the genetic algorithm works:
-
The algorithm begins by creating a random initial population.
-
The algorithm then creates a sequence of new populations. At each step, the algorithm uses the individuals in the current generation to create the next population. To create the new population, the algorithm performs the following steps:
-
Scores each member of the current population by computing its fitness value. These values are called the raw fitness scores.
-
Scales the raw fitness scores to convert them into a more usable range of values. These scaled values are called expectation values.
-
Selects members, called parents, based on their expectation.
-
Some of the individuals in the current population that have lower fitness are chosen as elite. These elite individuals are passed to the next population.
-
Produces children from the parents. Children are produced either by making random changes to a single parent—mutation—or by combining the vector entries of a pair of parents—crossover.
-
Replaces the current population with the children to form the next generation.
-
-
The algorithm stops when one of the stopping criteria is met.
b) Matlab code to optimize the Stalagmite function.
clear all
close all
clc
%defining our search space
x=linspace(0,0.8,150);
y=linspace(0,0.8,150);
%Creating a 2D mesh
[xx,yy] = meshgrid(x,y);
%Evaluating the stalagmite function
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
surfc(xx,yy,f)
xlabel(\'x value\')
ylabel(\'y value\')
shading interp
[inputs,fval]=ga(@stalagmite, 2);
%stalagmite function
function[f] = stalagmite(input_vector)
f(1) = (sin((5.1*pi*input_vector(1))+0.5))^6;
f(2) = (sin((5.1*pi*input_vector(2))+0.5))^6;
term1=(input_vector(1)-0.0667)^2/0.64;
term2=(input_vector(2)-0.0667)^2/0.64;
f(3)=exp(-4*log10(2)*term1);
f(4)=exp(-4*log10(2)*term2);
f = -f(1)*f(2)*f(3)*f(4); % to maximize the function the sign should be negative
end