Genetic Algorithm
Genetic Algorithm:
genetic algorithm are based on the principal of biological evolution or survival of fittest.
It starts with the random population of points and generates a random poupulation of points called individual at each iteration(generation)of the algorithm.
Three operators to improve a population and to converge to a final population of solution
- selection
- cross over
- mutation
MATLAB has two function of GA
- ga
- gamultiobj
In the given problem we have to find the maximum value of the function through genetic algorithm which solves for minimum value. therefore function is inverted so the max value becomes the min value and hence can be calculated through ga. function value is bounded in the range of .5 to 1.5
clear all
close all
clc
x = linspace(0,.6,150);
y = linspace(0,.6,150);
[xx yy] = meshgrid(x,y);
input = zeros(2);
for i = 1:length(xx)
for j = 1:length(yy)
input(1) = xx(i,j);
input(2) = yy(i,j);
func(i,j) = stalagmite(input);
end
end
surf(xx,yy,(func))
grid on
hold on
title('abc');
xlabel('x-axis');
ylabel('y-axix');
axis('fill')
shading interp
gcn = @stalagmite;
nvar = 2;
hold on
num = 100;
i =1;
opts = gaoptimset(@ga);
opts.populationsize =5;
opts.generations =100;
tic
for i=1:num
[x_m,val] = ga(gcn,2,[],[],[],[],[0,0],[.1,.3],[],[],opts);
fval(i) = val;
x_min(i) = x_m(1);
y_min(i) = x_m(2);
end
s = toc
plot3(x_min,y_min,fval)
figure(2)
plot(fval)
xlabel('Iterations');
ylabel('function minimum value');
ylim([-0.5,1.5]);
% stalagmite function
function [z] = stalagmite(input)
a = input(1);
b = input(2);
f1 = [sin(5.1*pi*a + .5)]^6;
f2 = [sin(5.1*pi*b + .5)]^6;
f3 = exp(-4*log(2)*((a -.0667)^2)/.64);
f4 = exp(-4*log(2)*((b - .0667)^2)/.64);
z = 1.5 - (f1*f2*f3*f4);
end
It is seen that function minimum value converges around .5051 at x&y = .068 & .067.
Thus at these points the maximum value of original function will occur.