Project

Global Maxima of Stalagmite Function

GENITIC ALGORITHM: A genetic algorithm is a search heuristic that is inspired by Charles Darwin’s theory of natural evolution. This algorithm reflects the process of natural selection where the fittest individuals are selected for reproduction in order to produce offspring of the next generation.

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.A genetic algorithm makes uses of techniques inspired from evolutionary biology such as selection, mutation, inheritance and recombination to solve a problem. The most commonly employed method in genetic algorithms is to create a group of individuals randomly from a given population. The individuals thus formed are evaluated with the help of the evaluation function provided by the programmer. Individuals are then provided with a score which indirectly highlights the fitness to the given situation. The best two individuals are then used to create one or more offspring, after which random mutations are done on the offspring. Depending on the needs of the application, the procedure continues until an acceptable solution is derived or until a certain number of generations have passed.

The Code to maximize the stalagmite function is as follows:

clear all
close all
clc


% input parametrs

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

[xx yy] = meshgrid(x,y);
num_case = 150;

for i = 1:length(x)
    for j = 1:length(y)
        input_vector(1) = xx(i,j);
        input_vector(2) = yy(i,j);
        F(i,j) = stalagmite(input_vector);
        
    end
end

% study_1
tic
for i = 1:num_case
    [inputs,Fopt(i)] = ga(@stalagmite,2);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end

study_time_1 = toc;

figure(1)
subplot(2,1,1);
hold on
surfc(xx,yy,F);
shading interp;
xlabel('x data');
ylabel('y data');
plot3(xopt,yopt,Fopt,'marker','o','markersize',5,'markerfacecolor','k')
title('Unbounded Inputs')
subplot(2,1,2)
plot(Fopt)
xlabel('Iterations')
ylabel('Function Maximum')

% Study 2
tic
for i = 1:num_case
    [inputs,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end
study_time_2 = toc;

figure(2)
subplot(2,1,1)
hold on
surfc(xx, yy, F)
shading interp
xlabel 'X data'
ylabel 'Y data'
plot3(xopt,yopt,Fopt,'marker','o','markersize',5,'markerfacecolor','k')
title('Bounded Inputs')
subplot(2,1,2)
plot(Fopt)
xlabel('Iterations')
ylabel('Function Maximum')

% Study 3
options = optimoptions('ga');
options = optimoptions(options,'PopulationSize',450);
tic
for i = 1:num_case
    [inputs,Fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end

study_time_3 = toc;

figure(3)
subplot(2,1,1)
hold on
surfc(xx, yy, F);
shading interp
xlabel 'X data'
ylabel 'Y data'
plot3(xopt,yopt,Fopt,'marker','o','markersize',5,'markerfacecolor','k');
title('Bounded Inputs with Increased Population Size');
subplot(2,1,2);
plot(Fopt);
xlabel('Iterations');
ylabel('Function Maximum');

max_value = [Fopt];

In the above code, we are running ourstalagmite function for 3 different scenarios:

1. Unbound Inputs where the inputs do not have any resrictions i.e., the inputs are randomly distributed even outside the working space

2. Bound Inputs where the inputs are restricted and are not allowed to go beyond our working space

3. Bounded Inputs with increased iterations: Here we are increasing the number of iterations and try out dufferent iterations.

Stalagmite Function:

function [F] = stalagmite(input_vector)

term_1 = (sin(5.1*pi*input_vector(1)+0.5))^6;
term_2 = (sin(5.1*pi*input_vector(2)+0.5))^6;
term_3 = exp((-4*log(2)*(((input_vector(1) - 0.0667)^2)/0.64)));
term_4 = exp((-4*log(2)*(((input_vector(2) - 0.0667)^2)/0.64)));
F = (term_1.*term_2.*term_3.*term_4);
F = 1/(1+F);
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.