Project

maximum value by using genetic algorithm

How GA works:

First of all we have to creat random initial vector. we can call it as population vector.

Then by using random vector algorithm creats another randome pair of number. to creat new pairs or population.

By calculating fitness value called raw fitness scores.

Scale the raw fitness score to convert them into a more usable range of values. These scaled values are called expectation values.

Produce the number of new generation by this parents member.

Selects members, called parents, based on their expectation. produced either by making random changes to a single parent—mutation—or by combining the vector entries of a pair of parents—crossover.

Here i find maximum value of function by genetic algorithm.

But as we know genetic algorithm use only for minimum value and insted of this i am intrested in to find maximum value.

For that i modify my stalagmite function code so, its directly give the me maximum value.

For that i use \"F = -f\" minimum value of function F is our maximum value for \"f\".

code for find the maxima of the given function.

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);

function = (term1.*term2.*term4.*term3);

stalagmite function:

function [f] = stalagmite(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);

[f] =  -(term1.*term2.*term4.*term3);
end

code for find maxima:

clear all
close all
clc

%creating row vector
x = linspace(0,0.6,100);
y = linspace(0,0.6,100);

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

%eveluting 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)
xlabel(\'x value\')
ylabel(\'y value\')

shading interp

options = optimoptions(\'ga\');
options = optimoptions(options,\'populationsize\',170);

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

screen short of output:

maximum value in optimization graph:

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.