Challenge

Week 4.1 - Genetic Algorithm

AIM - TO PREPARE THE GLOBAL MAXIMA BY USING OF STALAGMITE FUNCTION
clear all
close all
clc
% Defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
% Creating a 2 dimensional 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
% creating the 3dimensional
surfc(xx,yy,-f)
xlabel('x value')
ylabel('y value')
title ('stalagmite function')
shading interp
[inputs,fval]= ga(@stalagmite,2)
% performing the unbonded conditions
num_cases=50;
for i=1:num_cases
[inputs,fopt(i)]=ga(@stalagmite,2);
xopt(i)= inputs(1);
yopt(i)= inputs(2);
end
tic
study_1=toc
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,-f)
title('Unbounded inputs')
xlabel('x value')
ylabel('y value')
shading interp
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
legend ('function maximum', 'iterations')
% performing the bounded conditions
tic;
for i=1:num_cases
[inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6]);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_2_time=toc
figure(3)
subplot(2,1,1)
surfc(x,y,-f)
shading interp
title('Bounded inputs')
xlabel('x value')
ylabel('y value')
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
subplot(2,1,2)
plot(-fopt)
xlabel('iterations')
ylabel('function maximum')
% incresing the population size
options=optimoptions(@ga)
options=optimoptions(@ga,'PopulationSize',500) %increasing the population size
tic
for i=1:num_cases
[inputs,fopt(i)]=ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
xopt(i)=inputs(1);
yopt(i)=inputs(2);
end
study_3_time=toc %gives the time taken for study
figure(4)
subplot(2,1,1)
surfc(x,y,-f) %creates a surface to visualise 3D
shading interp
title('bounded inputs with increased population size')
xlabel('x value')
ylabel('y value')
hold on
plot3(xopt,yopt,-fopt,'marker','o','markersize',4,'markerfacecolor','r')
subplot(2,1,2)
plot(-fopt) %plotting -f vs number of iterations
xlabel('iterations')
ylabel('function maximum')
CONCEPT OF GENETIC ALGORITHEM
The Genetic algorithem works on the process of natural selection
It is a method for solving the both constraned and un constraned optimization problems that is based on the natural selection
Some of the population based Algorithems are
1- genetic algorithems
2- differential evalution
3- partical swarn optimization
The process flow from the working of genetic algorithems
The 3 main process are going to behind the GA
1 - selection
2- cross over
3- mutation
These 3 steps are create the next generations by the use of current population
SELECTION
It rules the selet the individuals called parents, that contribute the population at the next generation
MUTATION
It rules apply random changes to individuals parents to form the childrens
CROSS OVER
It rules combine two parents to form childrens for the next generation
SYNTEX FOR GA
SYNTEX for defending GA
The GA syntax in matlab is used to find the minimum of function using genetic algorithm. There are several ways to define the GA function depending on the problem being solved. The syntax used for this study is shown below
x= ga (fun,nvars)

where,

x = optimal solution/variables;

fun = Objective function;

nvars = Number of variables;

x = ga (fun,nvars,A,B,Aeq,BEQ,lb,ub)

where,

A, B = Linear inequality constraints

Aeq, Beq = Linear equality constraints

If there are no linear equalities and inequalities, then A, B, Aeq, Beq are set to '[]'

x= ga (fun,nvars,A,B,Aeq,Beq,lb,ub,non icon,Intcon,options)

where,

nonlcon = Nonlinear constraints

IntCon = Integer Values

options = Optimization options

If there are no nonlinear constraints and integer values, the nonlcon and IntCon are set to '[]'.

ERRORS

The following are the facing errors while write the programme

i am facing above the these errors and it over come by the use of command window and what i am gives incorect values and rectify the correct values and it will be easy to over come easily .

CONCLUTION

1 To find out the GA while using stalagmite function

the eqation of stalagmite fucntion is

term1 = [sin(5.1*pi*x+0.5)]^6;
term2 = [sin(5.1*pi*y+0.5)]^6;
term3 = exp(-4*log(2)*(((x-0.0667)^2)/0.64));
term4 = exp(-4*log(2)*(((y-0.0667)^2)/0.64));
f = -(term1*term2*term3*term4)
2 The results and plots are shown by the figures
3 The syntex of ga is
x= ga (fun,nvars)
x = ga (fun,nvars,A,B,Aeq,BEQ,lb,ub)
x= ga (fun,nvars,A,B,Aeq,Beq,lb,ub,non icon,Intcon,options)
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.