CALCULATING THE GLOBEL MAXIMA BY USING GENETIC ALGORITHM
AIM:-
1.To find the globel maxima by using genetic algorithm
2.Need to write code in MATLAB to optimise the stalagmite function and find the global maxima of the function.
3.Expalination of genetic algorithm.
OBJECTIVES:-
1.Need to wright the stalagmite function to find the globel maxima.
2.Explination on genetic algorithm
THEORY:-
Genetic algorithmare commonly used to genarate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation,crossover and selection.
Jhon holland introduced genetic algorithms in 1960 based on the consept of Darwins's theory of evolution.
Optimization:-
Optimization is the selection of best element from the some set of available alternatives to find the minima & maxima of given problem.
What are the syntax we are genetic algorithm:-
1. [x favl]=ga (fun , nvars)
where
x=inputs
fval=function value
ga=genetic algorithm
fun=function name
nvar=number of variables
2.[x fval]=ga(fun,nvars,a,b,aeq,beq,lb,ub)
where
a,b= linear inequality constrains
aeq,beq=liner equality constrains
lb=lower bound
up=upper bound
3.[x fval]=ga(fun,nvars,a,b,[],[],lb,ub,nonicon,intcon,options)
where
nonicon=non-linear constraints
intcon=inter constraints
options=optimoptions
4.options=optimoptions(solver name)
solver name=ga
5.optins=optimoptions(solver name,name,value)
where
name=population size
value=population size value
Formula of function:-
(Star_fun) function program:-
Here we are creating the function according to the above show formula and to get the x,y variables ,thought behind this function is stalagmite
and We are calling the function with name star_fun.
function [f] = star_fun(input_vector)
x=input_vector(1);
y=input_vector(2);
s1x = (sin(5.1*pi*x+0.5))^6;
s1y = (sin(5.1*pi*y+0.5))^6;
s2x = exp(-4*log(2)*((x-0.0667)^2)/0.64);
s2y = exp(-4*log(2)*((y-0.0667)^2)/0.64);
[f]=-s1x*s1y*s2x*s2y;
end
Stalagmite :-
Stalagmite is type of rock formation that rises from the floor of a cave due to the accumulation of material deposited on the floor from celling dripping.
Figure:-
Based on stalagmite function we are working to get global maxima
Main program :-
clear all
close all
clc
%Defining our surch space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
num_cases=50;
% Creating 2Dimensional 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) = star_fun(input_vector);
end
end
surf(xx,yy,-f);
shading interp
tic
%study1-nstatical behaviour
for i=1:num_cases
[inputs , fopt(i)]=ga(@star_fun,2);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study1_time=toc
figure(1);
subplot(2,1,1);
hold on
surf(xx, yy, -f)
shading interp
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r');
title('un bounded input');
subplot(2,1,2);
plot(-fopt);
xlabel('interations');
ylabel('function minimum');
tic
%study2-nstatical behaviour
for i=1:num_cases
[inputs, fopt(i)]=ga(@star_fun,2,[],[],[],[],[0,0],[0.7,0.7]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study2_time=toc
figure(2);
subplot(2,1,1);
hold on
surf(xx, yy, -f);
shading interp
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
title('bounded input');
subplot(2,1,2);
plot(-fopt);
xlabel('interations');
ylabel('function minimum');
tic
%study3-nstatical behaviour
options=optimoptions('ga');
options=optimoptions(options,'populationsize',150)
for i=1:num_cases
[inputs, fopt(i)]=ga(@star_fun,2,[],[],[],[],[0,0],[0.7,0.7],[],[],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study3_time=toc
figure(3);
subplot(2,1,1);
hold on
surf(xx, yy, -f);
shading interp
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r');
title('bounded input');
subplot(2,1,2);
plot(-fopt);
xlabel('interations');
ylabel('function minimum');
Figure(1):-
Output : without any values of optimum plots
Here in fig(1) it will show local maxima and local minimas
Figure(2):-
STUDY-1:STATISTICAL BEHAVIOUR HERE WE ARE NOT PROVIDING LOWER BOUNDS ,UPPER BOUNDS AND POLUTION SIZE
The above figure shows optimized maximum values after 50 iterations, for each iteration which are ploted in red dots are not bounded in specific area, so they are scattered all over the graph.
Study takes= 3.9341sec to complite the 50 itrations
Figure(3):-
STUDY-2: STATISTICAL BEHAVIOUR HER WE ARE PROVIDING LOWER BOUNDS AND UPPER BOUNDS BUT NOT PROVIDING POPULATION SIZE
The above figure shows optimized maximum values after 50 itrations,for each itration will be ploted in red are actually with in the area which we have specified,values which are not in the specified area are not consider.so we will get the best results for the globel maxima with high accurecy.
study takes=5.4808sec to complite the 50 itrations
Figure(4):-
STUDY-3: STATISTICAL BEHAVIOUR HERE WE WRE PROVIDING LOWER BOUNDS,UPPER BOUNDS AND POPULATION SIZE
Since the population size increassed the above figure shown global maxima
Study takes=13.8301sec to complite it 50 itrations of 150 population size
CONCLUSION:-
1.In 'MATLAB' we use a function solver is called 'ga',here 'ga' is used to solve and find the global minima's here we have to find 'maxima's so we add "-" negative sign to function values to get globel maxima
2.In this case we are taken no.of ITRATION'S as 50 (num_case=50) to find very accurate value of globel maxima