Stalagmite function Maximization
https://drive.google.com/open?id=1J6uFz5_owXpM13STlyT4jGRdRPk8xudk
Genetic algorithms(GAs) are adaptive heuristic search algorithm based on the evolutionary ideas of natural selection and genetics. As such they represent an intelligence exploitation of a random search used to solve optimization problems.Although randomized, GAs are by no means random, instead, they exploit historical information directly to the search into the region of better performance within the search space. The basic techniques of the GAs are designed to simulate processes in natural systems necessary for evolution, especially those follow the principles first laid down by Charles Darwin of \"survival of the fittest\". Since in nature, competition among individual for scanty resources result in the fittest individuals dominating over weaker ones.
The algorithm consists of several stages namely,
- Initial population-The initial population is the search space for the algorithm to find the solution.Initially, every member of the population is a solution to the problem.
- Fitness function-The fitness function is the function which determines how much fit an individual is to compete with other individuals.
- Selection- The fitness score is the criteria which is taken into account when selecting an individual for reproduction.
- Crossover-Crossover is the most significant phase in a genetic algorithm. For each pair of parents to be mated, a crossover point is chosen at random from within the genes.Offspring are created by exchanging the genes of parents among themselves until the crossover point is reached.
- Mutation-In certain new offspring formed, some of their genes can be subjected to a mutation with a low random probability. This implies that some of the bits in the bit string can be flipped.The algorithm terminates if the population has converged (does not produce offspring which are significantly different from the previous generation). Then it is said that the genetic algorithm has provided a set of solutions to our problem.
clear all
close all
clc
%Defining our search space
x = linspace(0,1,100);
y = linspace(0,1,100);
%Creating a 2D mesh
[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)
title(\'Stalagmite function\')
xlabel(\'x values\')
ylabel(\'y values\')
zlabel(\'fitness function values\')
shading interp
[inputs, fval] = ga( @stalagmite, 2)
********************************************************************
% Program for stalagmite function
% stalagmite function
function [f] = stalagmite(input_vector)
f1x = (sin((5.1*pi*input_vector(1))+0.5))^6;
f1y = (sin((5.1*pi*input_vector(2))+0.5))^6;
f2x = exp(-4*log(2)*((input_vector(1)-0.0667)^2)/0.64);
f2y = exp(-4*log(2)*((input_vector(2)-0.0667)^2)/0.64);
f = -f1x*f1y*f2x*f2y;
end