Week 4.1 - Genetic Algorithm
AIM: To write a code in MATLAB to optimize stalagmite function and find the global maxima using genetic algorithm.
DESCRIPTION:
GENETIC ALGORITHM: Genetic algorithm makes use of optimization along with tchniques available for optimization along with genetic algorithm syntax.
Optimization is a decision making process by which a optimum solution is obtained with the help of Genetic algorithm.For example like there are certain cases like for Air foil needs to provide proper lift at different angles, so for it be providing a proper lift the drag force should be minimum. If we go on changing the parameters manually and doing the calcualtions it becomes too difficult to calcualte and is time consuming which doesn't result a proper output. So, for this to outcome we make use of optimization which reduces the calculations and gives and optimum results. Genetic algorithm carries the process in three steps
- Selection rules: where the individuals are selected called as parents, who contibute to the next coming generation.
- Crossover rules: where two parents combine to form children for next generation
- Mutation rules: where random changes to individual parents to form children.
In matlab G.A is an inbuilt function which performs optimization for finding the minimum/optimum value.So, here the main objective is to modify the stalagmite function such that the genetic algorithm optimizes the data and gives the minimized/optimized value.
SYNTAX FOR GENETIC ALGORITHM:
finds a local unconstrained minimum,x= ga(fun,nvars)x, to the objective function,fun.nvarsis the dimension (number of design variables) offunfinds a local minimumx= ga(fun,nvars,A,b)xtofun, subject to the linear inequalitiesA*x≤b.gaevaluates the matrix productA*xas ifxis transposed (A*x').finds a local minimumx= ga(fun,nvars,A,b,Aeq,beq)xtofun, subject to the linear equalitiesAeq*x=beqandA*x≤b. (SetA=[]andb=[]if no linear inequalities exist.)gaevaluates the matrix productAeq*xas ifxis transposed (Aeq*x').defines a set of lower and upper bounds on the design variables,x= ga(fun,nvars,A,b,Aeq,beq,lb,ub)x, so that a solution is found in the rangelb≤x≤ub. (SetAeq=[]andbeq=[]if no linear equalities exist.)subjects the minimization to the constraints defined inx= ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)nonlcon. The functionnonlconacceptsxand returns vectorsCandCeq, representing the nonlinear inequalities and equalities respectively.gaminimizes thefunsuch thatC(x)≤0andCeq(x) = 0. (Setlb=[]andub=[]if no bounds exist.)minimizes with the default optimization parameters replaced by values inx= ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)options. (Setnonlcon=[]if no nonlinear constraints exist.) Createoptionsusingoptimoptions.orx= ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon)requires that the variables listed inx= ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)intcontake integer values.
Here,
x = local minimum point
fun = objective function
nvars = number of variables used
Aeq & Beq = They are used if the inequa;ity Aeq*x = Beq exists in the function
A & B = they are used if the inequality A*x<=B exists in the function
lb = It is lower bound limit of the function
ub = It is upper bound limit of the function
nonlcon = The function nonlcon accepts x and returns vectors C and Ceq, representing the non linear inequalities and equalities respectively
IntCon = Takes integer values
options = This argument allows add extra parameters like increasing population size. The options argument is created by the command 'otimoptions'
STALAGMITE FUNCTION :
In order to find the best global maximas of the function we have 3 study cases for the stalagmite function
1. Study case1 : Unbounded i.e inputs are not subjected to any limits
2. Study case2 : Bounded i.e a set of lower and upper bounds on design variables
3. Study case3 : Bounded i.e a set of lower and upper bounds on the design variables with increase in population size
Global Maxima = -(Fopt)
Global Minima = +(Fopt)
PROGRAM FOR STALAGMITE FUNCTION:
OUTPUTS:
figure1

stalagmite plot with global maximas , global minimas, local maximas and local minimas are generated in the plot
figure2

for the 50 iterations the statistical behavior of GA is generated. The time taken is 12.006 seconds. But we are not satisfied with more peaks in the iterations vs Funstion minimum.
figure3

Here due to defining the upper and lower boundary the peaks are optimized to some extent but still we are not satisfied with the result.
figure4

Here increasing the population size and allocating the upper and lower bounds the peaks are optimized to a larger extent. Time taken here is 48.0065 seconds.
CONCLUSION
Hence, Code in MATLAB to optimize the stalagmite function and to find the Global maxima of function using a genetic Algorithm is generatted successfully.