Project

Genetic algorithm to find global maxima of stalagmite function

Genetic Algorithm to maximum value of the function

Genetic Algorithm is a search method used in artificial intelligence and computing it is used for finding optimized solution to search problems based in the theory of natural selection and evolutionary biology.

the genetic algorithm generates a population of points in each iteration

Selection selects the best value using the fitness equation provided

crossover With a crossover probability cross over the parents to form a new offspring (children). If no crossover was performed, offspring is an exact copy of parents

Mutation is children by applying random changes to a single individual in the current generation to create a child

and finaly after doing these things if the function is best and scores best in fitness value the loop exits.

the below steps are used for coding a matlab program to determine the maximum value of stalagmite fuction using GA.

1) A search space of 2D x & y is assigned b/w 0 to 0.6 for 170 division.

2)Mesh grid is created and Function program(Stalagmite) is written to evaluate the x & y values

3) Using built in func for genetic algorithm in matlab the calculated value in above step is evaluated for min(we inverted to find max in stalagmite)

4) the determined minimum value using inverse stalagmite func is stored in \"fval\"

5)the plot has been made using the 3d surface plot function

Statistical behaviour study

6) Genetic alogorithm solver is set to \'ga\' & population is set to 200 increasing the population leads to more computation time but increases accracy.

7) Number of iterations set to 50 (study for 50 times)

8) Ga uses random sampling so output may vary each time we run the iteration to reduce it we set the upper and lower bound using

[inputs,fopt(i)]= ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);

so the search space is x->0 to 1 y->0 to 1

9) the outputs are stored in xopt,yopt,fopt and the values are plotted using 3d plot and plot fopt

10) the computation time is calculated using tic toc cmd got 25.16 sec

clear all
close all
clc
% Program to find the Global Maxima
% Assigning search space
    x=linspace(0,0.6,170);
    y=linspace(0,0.6,170);
%Evaluating a 2-Dimensional mesh
    [xx yy] = meshgrid(x,y);
%Evaluating the stalagmite function
     for i=1:length(xx);
         for j=1:length(yy);
             x_y(1)=xx(i,j);
             x_y(2)=yy(i,j);
             f(i,j)=stalagmite(x_y);
         end
     end
    surfc(xx,yy,f);
    grid on
    xlabel(\'X Value\')
    ylabel(\'Y Value\')
    
   shading interp
    [inputs,fval]=ga(@stalagmite,2);
 %Study on statistical behaviour
 options = optimoptions(\'ga\');
 options = optimoptions(options,\'populationSize\',200);
num_iter=50; 
 tic
 for i=1:num_iter
     [inputs,fopt(i)]= ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    xopt(i)=inputs(1);
    yopt(i)=inputs(2);
 end
 stat_study=toc
 figure(2)
 subplot(2,1,1)
 hold on
 surfc(x,y,f)
 shading interp
 plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
 title(\'Bounded inputs\')
 subplot(2,1,2)
 plot(fopt)
 xlabel(\'Iterations\')
 ylabel(\'Funtion minimum\')
 

Stalagmite function

function[f]=stalagmite(x_y)
             x=x_y(1);
             y=x_y(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)];
f= -((f1x).*(f1y).*(f2x).*(f2y));
end

\"\"

output for population size=200 limits=(0,0)(1,1)

\"\"

Conclusion

The above images shows the result will change according to the populationsize and upper,lower limits one has to be carefull on setting up these parameter to increase the accuracy of the result.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.