Project

global optimisation

GLOBAL OPTIMISATION OF STALAGMITE FUNCTION

Genetic algorithm works on random sampling,i will simply explain how ga works.

1. It made random selection between the parents in the poppulation.Parents with highest fitness are called elite members that are passed directly to the other generations.

2. Changes are made in other poppulation through mutation and cross over.

mutations-random changes in the genes of a single parent

crossover-exchange between vectors entries of pair of parents

replaces current generation with parent generation.

3.These steps are repeated untill any of stoping criteria is met.

stoping criteria are as follows -

a. Generations — The algorithm stops when the number of generations reaches the value of Generations.

b. Time limit — The algorithm stops after running for an amount of time in seconds equal Time limit

c. Fitness limit — The algorithm stops when the value of the fitness function for the best point in the current population is less than or equal to Fitness limit.

d.Stall generations — The algorithm stops when the average relative change in the fitness function value over Stall generations is less than Function tolerance

e.Stall time limit — The algorithm stops if there is no improvement in the objective function during an interval of time in seconds equal to Stall time limit.

Code

close all
clear all
clc

%defining our search space
x=linspace(0,0.6,150);
y=linspace(0,0.6,150);
 
num_cases=100;  %% it is basically equals to no of iterations

%creating 2d mesh
[xx yy]=meshgrid(x, y);


%evaluating 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)=stalegmite(input_vector);
    end
end



options=optimoptions(\'ga\');
options=optimoptions(options,\'populationsize\',1000);%here we define population size
tic
for i=1:100
    [input fopt(i)]=ga(@stalegmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    xopt(i)=input(1);
  yopt(i)=input(2);
end
study_time=toc
max=-fopt;

figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,f)
shading interp
plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\'bounded inputs\')
subplot(2,1,2)
plot(max)
xlabel(\'Iterations\')
ylabel(\'Function Maximum\')

Subcode for stalagmite function

function[val]=stalegmite(input_vector)
x=input_vector(1)
y=input_vector(2)


term1=(sin(5*pi*x+0.5)).^6;
term2=(sin(5*pi*y+0.5)).^6;
term3=exp(-4*log10(2)*(x-0.0667).^2/0.64);
term4=exp(-4*log10(2)*(y-0.0667).^2/0.64);
val=-term1.*term2.*term3.*term4;

end

Outcome

NOTE:one thing i want to mention here is that i plotted graph upside down this is done because ga compress the function to find minimum value of the function.So i here reverse the sighn of stalagmite function to find the max value.

RESULTS

According to above outcome the max value of the funtion is almost 0.9999 and is achieved at

x=0.0682 and y=0.0683

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.