Challenge

Week 4.1 - Genetic Algorithm

GENTIC ALGORITHM

AIM

To optimise the stalagamite function and find the global maxima of the function

OBJECTIVES OF THE PROGRAM

Explaining the concept of the genitic algorithm and also explain the syntax for ga in matlab plot graphs for all 3studies and F maximum vs. no. of itreations.

Genitic algorithm(ga)

  • A gentic algorithm is a search experiential that is stimulated by charles darwin's theory of natural evolution.
  • the gentic algorithm is a technique for solving both contrained and uncontrained optimization problems that are based on natural selection,the process that drives biologigal evolution.
  • the genitic algorithm constantly modifies the population size of individual solutions.
  • initialization of population
  • fitness function
  • selection

reproduction

syntax for GA:

[x,fval,exitflag,output,population,scores]=ga(func,nvars,A,b,Aeq,Beq,ib,ub,nonlcon,lntcon,options)

x = optimum solution

exitflag =reason ga stopped

output = information about optimization process

population = final population

scores = final scores

fun = fitness function

nvars = number of variables

A,b = linear inequality constraints

Aeq,Beq =linear equality constraints

lb =lower bound

up = upper bound

nonlcon=use for nonlinear constraints

lntcon = to get solution in integer

options = to set population size minimum with non-defalt options

BODY OF THE CONTENT:

below the stalagmite function to plot the graph in the main functions.

function[f]= stalagmite(input_vector)
x = input_vector(1);
y = input_vector(2);
f1_x = (sin(5.1*pi*x + 0.5)).^6;
f1_y = (sin(5.1*pi*y + 0.5)).^6;
t1 = ((x-0.0667).^2)/(0.64);
f2_x = exp(-4.*log(2)*t1);
t2 = ((y-0.0667).^2)/(0.64);
f2_y = exp(-4.*log(2)*t2);
f = -(f1_x.*f2_x.*f1_y.*f2_y);
FUNCTION EXPLAIN
  • Firstly, creating the mesh from the two vectors which will be acting as a seach space to find the maxima of the function
  • creating the mesh of these two vectors using the 'mesh' command and defining the no. of iterations as num_cases to iterate the values of the optimum values of the function.
  • now calculating the values of fitness function at each point of the mesh grid formed.
  • now creating its surface through 'surfc' command which will also provide the contour of the generated surface.

while using surfc applying the -ve sing to the function will generate the surface upside down which will be quite good to get the maxima of the function, as it will provide positive value for the maxima using the -ve sing

code explanation:

num_cases (no.of iteration for which the funtion will evaluate the fitness)

f(i,j) = stalagmite(input_vector) =[value of function in given search space]
surfc = [generating the surface]
shading interp = [to remove the lines produced by the mesh grid]
tic = [calculating the study time through tic and toc command]
xopt(i)=inputs(1) - [at each iteration]
study1_time=toc - [displaying the time taken to evalute]
[inputs, fopt(j)] = ga(@stalagmite,2,[],[],[],[],[0;0],[0.4;0.4])- [calculating the optimized value]
xopt(j)=inputs(1) -[at each iteration with boundary]
ERROR:
SOLUTIONS:

RESULTS:

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.