Project

genetic alogorithm using stalagmite function

AIM : coding in matlab to optimize the stalagmite function and find the global maxima of the function .

OBJECTIVE :

  • optimize stalagmite function .

  • finding global maxima of the following function.

  • explaining the concept of genetic algorithm and the syntax for it \"ga\" .
  • 3 case studies and plot their results .

THEORY :

A genetic algorithm is a heuristic search method used in artificial intelligence and computing. It is used for finding optimized solutions to search problems based on the theory of natural selection and evolutionary biology. Genetic algorithms are excellent for searching through large and complex data sets. They are considered capable of finding reasonable solutions to complex issues as they are highly capable of solving unconstrained and constrained optimization issues.

Genetic algorithm solver for mixed-integer or continuous-variable optimization, constrained or unconstrained

Genetic algorithm solves smooth or nonsmooth optimization problems with any types of constraints, including integer constraints. It is a stochastic, population-based algorithm that searches randomly by mutation and crossover among population members.

according to the matlab inbuilt pogram for genetic algorithm there are some functions and their syntax to use it are :-

here ,

fun = function ; nvars = num of variable ; A = inequality constraints matrix ; b = inequality constraints vector ; Aeq = equality constraints matrix ; beq = equality constraints vector ;
lb = lower bounds ; ub = upper bounds ; nonlcon = non linear constraints ; IntCon = integer constraints ; options = it is used to optimise the following option

In these syntax \"[]\" are used for the constraints value is not exist

REQUIRED INPUTS :

the limits for x and y are taken as

x = linspace (0,0.6,150);
y = linspace (0,0.6,150);

\'n\' is taken for the no of cases

n = 50

the formula taken for the stalagmite function is

F = f1,x *f1,y *f2,x *f2,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));

Global Optimization Toolbox optimization functions minimize the objective (or fitness) function.If you want to maximize f(x), minimize –f(x), because the point at which the minimum of –f(x) occurs is the same as the point at which the maximum of f(x) occurs.

g(x)=−f(x)

thats why we are taking in consider this function value in negative to find out the global maximum value.

MATLAB CODE :

the code for the function of stalagmite

% function for stalagmite

function[F] = stalagmite(input_vector)
x = input_vector(1);
y = input_vector(2);

% assuming the following variables
% f1 = f1,x , f2 = f1,y , f3 = f2,x , f4 = f2,y

f1 = (sin((5.1*pi*x)+0.5))^6;
f2 = (sin((5.1*pi*y)+0.5))^6;
f3 = exp(-4*log(2)*(((x-0.0667)^2)/0.64));
f4 = exp(-4*log(2)*(((y-0.0667)^2)/0.64));

f = (f1*f2*f3*f4)

F = -f
end

the code for the main function to find the value and with the 3 case studies using \"ga\" syntaxs

clear all
close all
clc

% defining our search space 
x = linspace (0,0.6,150);
y = linspace (0,0.6,150);

% creating 2d mesh
[xx yy] = meshgrid(x,y);
n = 50;
% 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
tic
% study 1 - statistical behaviour 
for i = 1:n 
    [inputs,final_output(i)] = ga(@stalagmite,2)
    x_output(i) = inputs(1);
    y_output(i) = inputs(2);
end
study_1_time = toc 
% plot for case study 1
figure(1)
subplot (2,1,1);
hold on
surfc(xx,yy,f);
shading interp
xlabel(\'x value\');
ylabel(\'y value\');
plot3(x_output,y_output,final_output,\'marker\',\'o\',\'markerfacecolor\',\'r\');
title(\'unbounded inputs\')
subplot(2,1,2);
plot(final_output)
xlabel(\'iterations\');
ylabel(\'function value\');

tic
% study 2 using upper and lower bounds 
for i = 1:n ;
    [inputs,final_outputs(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6]);
    % the \'[]\' are using for there is no input for inequality and equality
    % constraints
    x_output(i) = inputs(1);
    y_output(i) = inputs(2);
end
study_2_time = toc 

%plot for case study 2
figure(2)
subplot (2,1,1);
hold on
surfc(xx,yy,f);
shading interp
xlabel(\'x value\');
ylabel(\'y value\');
plot3(x_output,y_output,final_output,\'marker\',\'o\',\'markerfacecolor\',\'r\');
title(\'bounded inputs\')
subplot(2,1,2);
plot(final_output)
xlabel(\'iterations\');
ylabel(\'function value\');

% study 3 using \'option\' and increasing population size

options = optimoptions(\'ga\')
options = optimoptions(options,\'populationSize\',400);
tic

for i = 1:n
    [inputs,final_outputs(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.6;0.6],[],[],options);
% the \'[]\' are using for there is no input for
% inequality,equality,non-linear and integer constraints  
    x_output(i) = inputs(1);
    y_output(i) = inputs(2);
end
study_3_time = toc 

%plot for case study 3
figure(3)
subplot (2,1,1);
hold on
surfc(xx,yy,f);
shading interp
xlabel(\'x value\');
ylabel(\'y value\');
plot3(x_output,y_output,final_output,\'marker\',\'o\',\'markerfacecolor\',\'r\');
title(\'bounded inputs with increase population size\')
subplot(2,1,2);
plot(final_output)
xlabel(\'iterations\');
ylabel(\'function value\');

ERRORS AND EXPLAINATION :

error 1 :

\"\"

in this case the input command for population size is wrong enterd that is corrected in the pogram

RESULTS :

in matlab by optimizing the stalagmite function we find out the global maxima of the function . but the accurate value we have to go with the further studies and look up in the 3 cases to find out the most approximate values

so, here are the results in the for of plotted graphs and the time taken for the study is also given in the below images.

GENERAL EQUATION VALUE :

\"\"

CASE 1 :

\"\"

CASE 2 :

\"\"

CASE 3 :

\"\"

the values in the workspace are shown

\"\"

REFERENCE :

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.