Project

FINDING THE GLOBAL MAXIMA of THE STALAGMITE FUNCTION USING (GA) GENETIC ALGORITHM in MATLAB

THE GLOBAL MAXIMA of THE STALAGMITE FUNCTION USING (GA) GENETIC ALGORITHM

INTRODUCTION:

A genetic algorithm (GA) is a method for solving both constrained and unconstrained optimization problems based on a natural selection process that mimics biological evolution. The algorithm repeatedly modifies a population of individual solutions. It Generates a population of points at each iteration.

HOW GENETIC ALGORITHM WORKS:

1.The algorithm begins by creating a random initial population.

2.The algorithm then creates a sequence of new populations. At each step, the algorithm uses the individuals in the current generation to create the next population.

3.Scores each member of the current population by computing its fitness value. These values are called the raw fitness scores.

4.Scales the raw fitness scores to convert them into a more usable range of values. These scaled values are called expectation values.

5.Selects members, called parents, based on their expectation.

6.Some of the individuals in the current population that have lower fitness are chosen as elite. These elite individuals are passed to the next population.

7.Produces children from the parents. Children are produced either by making random changes to a single parent, mutation, or by combining the vector entries of a pair of parents crossover.

8.Replaces the current population with the children to form the next generation.

FLOW CHART:

STALAGMITE FUNCTION:

CONSTRAINTS USED IN GA:

The highlighted syntax shown here is used in our solver (ga).

TOOLS USED IN OPTIMIZATION OF STALAGMITE FUNCTION:

Stopping criteria:determines what causes the algorithm to terminate.

Generations:specifies the maximum number of iterations the genetic algorithm performs.

Time limit:specifies the maximum time in seconds the genetic algorithm runs before stopping.

Fitness limit:If the best fitness value is less than or equal to the value ofFitness limit, the algorithm stops.

Stall generations:If the average change in the fitness function value overStall generations is less than Function tolerance, the algorithm stops.

Stall time limit:If there is no improvement in the best fitness value for an interval of time in seconds specified by Stall time limit, the algorithm stops.

Stall test:Determines whether the definition of “stall” is average change over the last Stall generations, or is the geometric weighted average change, where the geometric weighting factor is (1/2)N for N generations from the end.

Function tolerance:If the average change in the fitness function value over Stall generations is less than Function tolerance, the algorithm stops.

RNG:stands for random number generator and is often used in various situations pertaining to card games, as well as games that also revolve around some sort of outcome.

PROBLEMS GIVEN:

1.Code for defining the stalgamite function.

2.write a code to represent an individual local maxima and global maxima by deriving a stalagmite function.

3.Plot graphs for all 3 studies and for F maximum vs no. of iterations. Title and axes labels are a must, legends could be shown if necessary.

Study a.Without boundary conditions.

Study b.With boundary conditions.

Study C.Increasing the no.of.population size.

CODE FOR STALAGMITE FUNCTION:

function [f] = stalgamite_func(input)

f1_x= (sin(5.1*pi*input(1)+0.5)^6);
f1_y= (sin(5.1*pi*input(2)+0.5)^6);
f2_x= exp(-4*log(2)*(((input(1)-0.0667)^2)/0.64));
f2_y= exp(-4*log(2)*(((input(2)-0.0667)^2)/0.64));
      
    f = -(f1_x*f1_y*f2_x*f2_y);

end

CODE FOR INDIVIDUAL GLOBAL MAXIMA AND LOCAL MAXIMA:

clear all
close all
clc


%input variables
x = linspace(0,0.6,150)
y = linspace(0,0.6,150)
num=50
%creating 2d mesh
[xx,yy] = meshgrid(x,y);
for i =1:length(xx);
    for j = 1:length(yy);
        input(1)= xx(i,j);
        input(2) = yy(i,j);
        f(i,j) = stalgamite_func(input);
        
    end
end
surfc(xx,yy,-f)
shading interp

PLOT FOR GLOBAL MAXIMA AND LOCAL MAXIMA:

CODE FOR STALAGMITE FUNCTION FOR 3 STUDIES(a,b,c):

clear all
close all
clc

rng default

%input variables
x = linspace(0,0.6,150)
y = linspace(0,0.6,150)
num=50

%creating 2d mesh
[xx,yy] = meshgrid(x,y);
for i =1:length(xx);
    for j = 1:length(yy);
        input(1)= xx(i,j);
        input(2) = yy(i,j);
        f(i,j) = stalgamite_func(input);
        
    end
end

%variable without bounds
tic
for i = 1:50
    [inputs,fopt(i)] = ga(@stalgamite_func,2);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end
study1time = toc
 figure(1)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'-o','MarkerSize',5,'MarkerFaceColor','r')
title('unboundedinputs')
subplot(2,1,2)
plot(fopt)
xlabel('iterations')
ylabel('functionmaximum')
legend('iterations')



%variable with bounds
tic
for i = 1:50
    [inputs,fopt(i)] = ga(@stalgamite_func,2,[],[],[],[], [0;0], [0.1;0.1]);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end
study2time = toc
 figure(2)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'o','MarkerSize',5,'MarkerFaceColor','r')
title('boundedinputs')
subplot(2,1,2)
plot(fopt)
xlabel('iterations')
ylabel('functionmaximum')
legend('iterations')


%increasing ga iterations
options = optimoptions('ga')
options = optimoptions(options,'populationsize',50,'functiontolerance',1e-8)
tic
for i = 1:50
    
    [inputs,fopt(i)] = ga(@stalgamite_func,2,[],[],[],[],[0;0],[0.1;0.1],[],[],options);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
end
study3time = toc
 figure(3)
subplot(2,1,1)
hold on
surfc(xx,yy,-f)
shading interp
plot3(xopt,yopt,-fopt,'-o','MarkerSize',5,'MarkerFaceColor','r')
title('bounded inputs')
subplot(2,1,2)
plot(fopt)
xlabel('iterations')
ylabel('functionmaximum')
legend('iterations')

PLOT FOR STALAGMITE FUNCTION AT NO BOUNDARY CONDITIONS(Study a):

PLOT FOR STALAGMITE FUNCTION WITH BOUNDARY CONDITIONS(Study b):

PLOT FOR STALAGMITE FUNCTION WITH INCREASED POPULATION SIZE(Study c):

ASSUMPTION:

By knowing the absolute point of the maxima, we can icrease input data of boundary conditions.By expanded axes with respect to boundary inputs value the exact point of the global maxima is plotted.

CONCLUSION:

1.The stalagmite function is defined.

2.The plot for individual global maxima and local maxima is plotted.

3.Plotted graphs for all 3 studies.

Study a.Without boundary conditions.

Study b.With boundary conditions.

Study C.Increasing the no.of.population size.

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.