Project

GENETIC ALGORITHM PROGRAM TO CALCULATE THE GLOBAL MAXIMA OF A STALAGMITE FUNCTION BY USING MATLAB

Introduction:

Local maximum and minimum :

Functions can have\"hills and valleys\":places where they reach a minimum or maximum values.

It may not be the minimum or maximum for the whole function, but locally it is.\"Local

Local Maximum:

First we need to choose an interval,

\"Local

Then we can say that a local maximum is the point where:

The height of the function at \"a\" is greater than (or equal to) the height anywhere else in that interval.

Or, more briefly:

f(a) ≥ f(x) for all x in the interval

In other words, there is no height greater than f(a).

Note: f(a) should be inside the interval, not at one end or the other.

Local Minimum:-

Likewise, a local minimum is:

f(a) ≤ f(x) for all x in the interval

The plural of Maximum is Maxima

The plural of Minimum is Minima

Maxima and Minima are collectively called Extrema

Global (or Absolute)Maximum and Minimum :

The maximum or minimum over the entire function is called an \"Absolute\" or \"Global\" maximum or minimum.

There is only one global maximum (and one global minimum) but there can be more than one local maximum or minimum.

\"Global

A Genetic algorithm is a method of solving optimization problems based upon the evaluation theory that was proposed by charles Darwin.

Matlab provides inbuilt functions that helps us to do quit comfortablly.

Writing a program for genetic algorithm to find gloabl maxima codes is given below by using Matlab:

clear all
close all
clc

%.........Step:1..........
%Defining one dimensional array.

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

%number of iterations
num_iterations = 100;
[xx, yy] = meshgrid(x,y);

%..........Step:2..........
%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

surfc(xx,yy,f)
shading interp

%..........Step:3..........
tic
%study 1 - statistical behaviour

for i=1:num_iterations
    [inputs,fopt(i)] = ga(@stalagmite, 2);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
    
end

study1_time = toc; 
figure(1)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xopt,yopt,-fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\'unbounded inputs\')
subplot(2,1,2)
plot(-fopt)
axis([0 100 0.4 0.6])
xlabel(\'iterations\')
ylabel(\'function minimum\')

%..........Step:4..........

tic
%study 2 - statistical behaviour - with upper and lower bounds

for i=1:num_iterations
    [inputs,fopt(1)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
    
end

study2_time = toc;

figure(2)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xopt,yopt,-fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\'bounded inputs\')
subplot(2,1,2)
plot(-fopt)
xlabel(\'iterations\')
ylabel(\'function minimum\')

%..........Step:5..........
%study 3 increasing GA iterations
options = optimoptions(\'ga\');
options = optimoptions(options,\'populationsize\',170);

tic
for i=1:num_iterations
    [inputs,fopt(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
    xopt(i) = inputs(1);
    yopt(i) = inputs(2);
    
end

study3_time = toc;
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xopt,yopt,-fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
title(\'Bounded inputs with modified population size\')
subplot(2,1,2)
plot(-fopt)
xlabel(\'iterations\')
ylabel(\'Function minimum\')

Step:1

Creating one dimensional array\'s x and y.Based on this one-dimensional arrays.creating two-dimesnional array.

To create one dimensional array\'s here we are using command called linspace.

To create our two dimensional array\'s here we are using command called meshgrid.

Step:2

Evaluating the stalagmite function.

Each value of x&y basically creating an array as input vector.Now the input vector actually a row vector meaning it as two columns

Step:3

in this we are going to see the statistical behaviour of stalagmite function.

Mathematical model that actually helps us to generate the local minima and maximas.

Step:4

in this we are going to see the statistical behaviour of upper & lower bounds.

here we are using function called ga it is used to minimum the function using genetic algorithm.

[inputs, fopt(1)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1])

stalagmite - fitnessfcn.

2-nvars,positive integer representing the number of variables in the problem.

[] - A,matrix for linear inequality constraints of the form.

[] - B,vector for linear inequality constraints of the form.

[] - Aeq,Matrix for linear equality constraints of the form.

[] - Beq,vector for linear equality constraints of the form.

[0;0] - vector of lower bounds.

[1,1] - vector of upper bounds.

Step:5

In this we will see the raise in the genetic algorithm iterations.

For that, We here are going to use new command called optimoptions it creates optimisation options specified as the output of optimoptions

Code for Solving the Stalagmite Function:

function [S] = stalagmite(input_vector)
a = input_vector(1);
b = input_vector(2);
f1 = (sin(5.1*pi*a+0.5))^6;
f2 = (sin(5.1*pi*b+0.5))^6;
f3 = exp(-4*log(2)*(a-0.0667)^2/0.64);
f4 = exp(-4*log(2)*(b-0.0667)^2/0.64);

S = -(f1*f2*f3*f4);

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.