Project

OPTIMIZATION OF STALAGMITE FUNCTION AND FINDING THE GLOBAL MAXIMA

AIM

To write a program to optimize the stalagmite function and find the global maxima of the function

GENETIC ALGORITHM

Genetic algorithm is a method used to solve both constrained and unconstrained optimization problems based on natural selection. It repeatedly changes the population of individual solutions. At each step genetic algorithm uses the individuals at random value of the current populations as parents to produce the children of the next generation.

ga SYNTAX:

x = ga(fun,nvars)
x = ga(fun,nvars,A,b)
x = ga(fun,nvars,A,b,Aeq,beq)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon)
x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,options)
x = ga(problem)
[x,fval] = ga(__)
[x,fval,exitflag,output] = ga(__)
[x,fval,exitflag,output,population,scores] = ga(__)

FUNCTION TO BE OPTIMIZED:

FUNCTION OF THE STALAGMITE:
function [F] = 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.667)^2)/(0.64));
f4 = exp(-4*log(2)*((b-0.667)^2)/(0.64));

F =-(f1*f2*f3*f4);
end
In this \'-\' is used to find the global maxima.
PROGRAM TO OPTIMISE THE STALAGMITE FUNCTION:
clear all
close all 
clc
%defining sapce
x = linspace(0,0.6,150);
y = linspace(0,0.6,150);
number = 50;
                  
%2 dimension
[xx yy] = meshgrid(x,y);

%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;
    
    %study of statistical behaviour of genetic algorithm
    
   tic
    for i = 1:number
     [inputs,fopt(i)] = ga(@stalagmite,2)
     xopt(i)= inputs(1);
     yopt(i)= inputs(2);
    end
    
    time_study1 = toc
     figure(2)
    subplot(2,1,1)
    hold on
    surfc(xx,yy,f)
    shading interp
    plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'r\')
    subplot(2,1,2)
    plot(fopt)
    xlabel(\'Iterations\')
    ylabel(\'global values\')
    
    %study of statistical behaviour of genetic algorithm with upper and lower bounds
    
    tic 
    for i =1:number
      [inputs,fopt(i)] =ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
      xopt(i)=inputs(1);
      yopt(i)=inputs(2);
    end
    
    time_study2=toc
    
    figure(3)
    subplot(2,1,1)
    hold on
    surfc(xx,yy,f)
    shading interp
    plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'g\')
    subplot(2,1,2)
    plot(fopt)
    xlabel(\'iterations\')
    ylabel(\'gloabal values\')
    
    %study of statistical behaviour of genetic algorithm with increasing
    %the population
    options =optimoptions(\'ga\');
    options =optimoptions(options,\'populationsize\',180);
    
    tic
    for i=1:number
        [inputs,fopt(i)] =ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
        xopt(i) = inputs(1);
        yopt(i) = inputs(2);
    end
     time_study3 = toc
     
     figure(4)
     subplot(2,1,1)
     hold on
     surfc(xx,yy,f)
     shading interp
     plot3(xopt,yopt,fopt,\'marker\',\'o\',\'markersize\',5,\'markerfacecolor\',\'b\');
     subplot(2,1,2)
     plot(fopt)
     xlabel(\'iterations\')
     ylabel(\'global values\')

EXPLANATION

  • Find the function of the stalagmite using the given data.
  • Using linspace command assign the values for both x and y and let the no of optimizing value be 50
  • Convert the x and y values into two-dimensional using meshgrid command.
  • Using the functional code find the stalagmite function.
  • Plot the optimum values of x and y and find the global values of the function.

This plot shows the global maximum values but while running furtherly the results keep on change. As the genetic algorithm changes the random individuals the results also differ.

Therefore we have to study the genetic algorithm with three cases.

1.study case 1 - unbounded

2.study case 2 - bounded(defines a set of upper and lower bound values)

3.study case 3 - bounded(defines a set of upper and lower bound values with increase

in population)

STUDY CASE 1:

This graph clearly shows that the maximum values keep on changes for every iteration.

STUDY CASE 2:

In this graph, you can see that the variation of maximum values is slightly reduced.

STUDY CASE 3:

At the final study, you could find the global maximum value without any variation.

ERRORS FACED:

Error in the syntax of ga.

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.