Challenge

Week 4.1 - Genetic Algorithm

Genetic Algorithm theory : 

       Genetic algorithm is  a techniquec to find out the optimal value of the next generation.to perform for find out best solution to next and focuse on the optimization.it is based on darvan theory 

they have to convert phonotype to ganotype with the help of encode.

Phenotype means collection of row data.

Geniotype means to convert intezers decimal real number etc.

STEPS:

  1. firstly we use linespace comand to create150 value from 0 to 0.6
  2. we use the mashgraid comand to evalvate the funtion of two variable and these dimantional plots
  3. we use the stalgamite funtin for difrant iteration 
  4. we use  ga function to deline the stalagamite function for variouse iteration 
  5. we mwssure the time for each of 50 iteration and the optimum value is obtained

 stalgamite equation 

                  f(x y) = f1,xf2,xf1,yf2,y
 
                 f1_x =(sin(5.1*pi*x + 0.5) ).^6;
                 f1_y = (sin(5.1*pi*y + 0.5)).^6;
                 f2_x = exp(-4*log(2).* (((x-0.0667).^2)/0.64));
                 f2_y = exp(-4*log(2).* (((y-0.0667).^2)/0.64));

PROGRAM ON FIND OUT THE STALAGAMITE FUNCTION

%program to cal;culate goloble maximma of stalagamite function
close all
clear all
clc
 
%difining our surch space
x = linspace(0,0.6,150);
y = linspace (0,0.6,150);
%f = stalagmite_func(input_vector)
%creating a 2dimensional mesh
[xx,yy] = meshgrid (x,y);
num_cases = 50; % number of itteration to run ga i.e ga
%for loop for Evalvating or calling 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_func(input_vector);
end
end
%study 1 = statical behavior
%study_time1 = toc;
tic
for i = num_cases
[inputs , fopt(i)] = ga(@stalagmite_func, 2);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time1 = toc
%poltting
figure(1)
subplot(2,1,1)
hold on
surfc(x,y ,-f )
hold on
shading interp
plot3 (xopt ,yopt,-fopt,'marker','o','markersize',5,'markerfacecolor','r')
title ('Unbounded input')
subplot(2,1,2)
plot(-fopt)
xlabel('Itertions')
ylabel('Function maximum')
%legend('Itertion','finction minima')
tic
%study 2 = statical behavior with upper and lower bond
for i = num_cases
[inputs , fopt(i)] = ga(@stalagmite_func, 2,[],[],[],[],[0:0],[1:1]);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
study_time2 = toc;
figure(2);
subplot(2,1,1);
hold on
surfc(x,y ,f );
hold on
shading interp
plot3 (xopt ,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r');
title ('Bounded input');
subplot(2,1,2);
plot(fopt);
xlabel('Itertions');
ylabel('Function maximum');
%study 3 study GA ittration
option = optimoptions('ga');
option = optimoptions(option,'populationsize',150);
tic
study_time3 = toc;
for i = num_cases
[inputs , fopt(i)] = ga(@stalagmite_func, 2,[],[],[],[],[0:0],1:1,[],[]);
xopt(i) = inputs(1);
yopt(i) = inputs(2);
end
figure(3)
subplot(2,1,1)
hold on
surfc(x,y ,f )
hold on
shading interp
plot3 (xopt ,yopt,fopt,'marker','o','markersize',5,'markerfacecolor','r')
title ('bounded input with modified population size')
subplot(2,1,2)
plot(fopt)
xlabel('Itertions')
ylabel('Function maximma')

STALAGAMITE FUNCTION CODE:

function [f] = stalagmite_func(input_vector)
 
x = input_vector(1);
y = input_vector(2);
 
%f(input) = f1,xf2,xf1,yf2,y
f1_x =(sin(5.1*pi*x + 0.5) ).^6;
f1_y = (sin(5.1*pi*y + 0.5)).^6;
f2_x = exp(-4*log(2).* (((x-0.0667).^2)/0.64));
f2_y = exp(-4*log(2).* (((y-0.0667).^2)/0.64));
f =-f1_x.* f1_y.* f2_x.*f2_y;
end
 
 
 
 
 
 
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.