Week 4.1 - Genetic Algorithm
- Optimising the stalagmite funtion fequire to flip the entire funtion upside down which would convert maximas to minimas. This can be simply be done by multiplying the final formulation of stalagmite function by '-1'.
- Genetic Algorithm
- Genetic algorithm is an Darvin's naturals selection theory inspired optimization algorithm, to find minima. In this algorithm random data points are selected at first and then they are compared with pair of best candidates are chosen (parents) and then their initial parts are swapped with each other to give two new values (children) which would be better minimas, mutation rate is also involved in creating child value whcih flips the random bit after swapping from the parent values to reduce the chances to fall into local minima. Then these child values are used as parents. After lot of iterations (generation) population settels down either to a local minima or global minima.
- x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)
- fun = funtion that takes only one vector argument
- nvar = number of input variables in the argument vector
- A, Aeq, beq & b define a linear relation of x that facilitates in finding minima Ax < b, Aeqx = beqx
- LB & UB are lower and upper bound vectors that restrict the search area within those bounds
- It subjects the minimization in nonlcon
- option = changing the default parameters
Code explanation
- Defining the search space
- number of iterations genetic algorithm needed to be run
- Creating a meshgrid
- Evaluating stalagmite funtion
- within nested for loop of the meshgrid values obtained
- Input
- Vector with x & y
- operation
- plugging the x & y values within the function
- multiplying the final form by '-1' to flip the output (so that genetic function would give the location and value of maxima instead of minima)
- Output
- Flipped Stalagmite function
- Input
- Study 1
- Running a loop for pre-defined iterations
- running genetic algorithm
- collecting data for every iteration
- x
- y
- z
- Plotting
- stalagmite function
- collected x,y,z minima values at each iteration
- minima found at every iteration
- Running a loop for pre-defined iterations
- Study 2
- Running a loop for pre-defined iterations
- running genetic algorithm for smaller range by definig the upper and lower bounds from 0.6 to 0 which reduces the search field of genetic algorithm hence increasing the chances to find minima.
- collecting data for every iteration
- x
- y
- z
- Plotting
- stalagmite function
- collected x,y,z minima values at each iteration
- minima found at every iteration
- Running a loop for pre-defined iterations
- Study 3
- Running a loop for pre-defined iterations
- running genetic algorithm for smaller range by definig the upper and lower bounds from 0.6 to 0 which reduces the search field of genetic algorithm hence increasing the chances to find minima. On top of that defining the default value of Population size from 50 to 170, thish increases the number of search points further narrowing the search scope and increasing the chances and speed of finding the minima.
- collecting data for every iteration
- x
- y
- z
- Plotting
- stalagmite function
- collected x,y,z minima values at each iteration
- minima found at every iteration
- Running a loop for pre-defined iterations