Week 5 - Genetic Algorithm
Aim
To Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function.
Before writing the code to fing global maxima of Genetic algorithm we have to understand the GA and global maxima nad mina functions
Genetic Algorithm
The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural selection, the process that drives biological evolution. The genetic algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm selects individuals from the current population to be parents and uses them to produce the children for the next generation.

with this chart we can understand what the GA is the function to calculate the mutation of generations with codes in matlab tool
the ga has three rules
1) Elite childrens
Selection rules select the individuals, called parents, that contribute to the population at the next generation. The selection is generally stochastic, and can depend on the individuals' scores
it is a function which used by selecting the random induviduals as a function to find the population of the next generation of pure induviduals without changes in chromosome or genes of the induviduals
2) cross-over
the cross-over is the method which a individual from different generation are combined to produce the next generations while this method the chromosome and genes of two different are combined and produce a different generation
For problems with linear constraints, the default crossover function creates the child as a random weighted average of the parents.
3)Mutation
The mutation in generations can be occur in in the changes of chromosome or gene changes from the previous generation parents can make some changes in the present generation compare to the previous
The algorithm creates mutation children by randomly changing the genes of individual parents. By default, for unconstrained problems the algorithm adds a random vector from a Gaussian distribution to the parent. For bounded or linearly constrained problems, the child remains feasible.

The following figure shows the children of the initial population, that is, the population at the second generation, and indicates whether they are elite, crossover, or mutation children.

Global maxima and minima
Programs to find the GA in three different cases
Before that we have to evaluate the stalgamite function which based on the equation given in the video
Now we can able to find the varitions occur in three different cases with same outputs for the 3 cases even
1) Study 1
Explanation
In this first study we are going to find the plots of unbounded statistical behaviour
for this function the input of [inputs,fopt(a)] = ga(@stalagmite,2); are run against the number of cases which is given a 50 and the optimum values of inputs are also find using for loops
After that with using of plot commands we use plot 3 command gives the 3D graph for the global maxima of the study against the total number of time which the program run with numcases
the anothe subplot is used to understand the optimum values of f and number of ga iteration run in the function
2)Study 2
x to fun, subject to the linear equalities Aeq*x = beq and A*x ≤ b. (Set A=[] and b=[] if no linear inequalities exist


