Finding global maxima point for stalagmite mathematical model in optimizational method
AIM
To finding the global maxima at the stalagmite mathematical model in optimize method in MATLAB.
OBJECTIVE
1) Write a code in matlab for creating a stalagmite function in optimizationally and finding the global maxima of the function.
2) To study the outline of genectic algorithm and flow of working.
3) Learn the concept of genetic algorithm and illustrating the syntax of genetic algorithm.
THEORY ABOUT GENETIC ALGORITHM
Define genetic algorithm
A genetic algorithm (GA) is a method for solving both constrained and unconstrained optimization problems based on a natural selection process that mimics biological evolution.
The algorithm repeatedly modifies a population of individual solutions. At each step, the genetic algorithm randomly selects individuals from the current population and uses them as parents to produce the children for the next generation. Over successive generations, the population "evolves" toward an optimal solution.
You can apply the genetic algorithm to solve problems that are not well suited for standard optimization algorithms, including problems in which the objective function is discontinuous, nondifferentiable, stochastic, or highly nonlinear.
Genetic algorithm is always calculating minimum values.
Genetic algorithm through from search techniques
The genetic algorithms technique is camed from search technique through the path of guided random search techniques, evolutionary algorithms and to genetic algorithms.
Outline and works of the basic genetic algorithm with stopping criteria
Step 1
- Randomly generate a set of possible solutions to a problem.
- Represent each solution as a fixed length character string.
Step 2
- Using a fitness function, test each possible solution against the problem to evaluate them.
Step 3
- Keep the best solutions.
- Use best solutions to generate new possible solutions.
Step 4
Repeat the previous two steps until
- Keep the best solutions.
- Use best solutions to generate new possible solutions.
STOPPING CRITERIA
The evaluated value is two categories:
One is fit value and another one is unfit value, the fit value is passed to the best individual value, the unfit value is passing to reproduction side. At the region of stopping criteria this process is happened.
BASIC OPERATION
The basic operators of Genetic Algorithm are
Selection (Reproduction)
- It is the first operator applied on the population.
- It selects the chromosomes from the population of parents to cross over and produce offspring.
- It is based on evolution theory of “Survival of the fittest” given by Darwin.
There are many techniques for reproduction or selection operator such as-
- Tournament selection
- Ranked position selection
- Steady state selection etc.
Crossover
- Population gets enriched with better individuals after reproduction phase.
- Then crossover operator is applied to the mating pool to create better strings.
- Crossover operator makes clones of good strings but does not create new ones.
- By recombining good individuals, the process is likely to create even better individuals.
Mutation
- Mutation is a background operator.
- Mutation of a bit includes flipping it by changing 0 to 1 and vice-versa.
- After crossover, the mutation operator subjects the strings to mutation.
- It facilitates a sudden change in a gene within a chromosome.
- Thus, it allows the algorithm to see for the solution far away from the current ones.
- It guarantees that the search algorithm is not trapped on a local optimum.
- Its purpose is to prevent premature convergence and maintain diversity within the population.
EQUATIONS
The equations is use to finding the stalagmite function in this problem and also finding the global maxima in optimizationally.
`f(x,y) = f1x,f2x,f1y,f2y`
`f1x = [sin5.1pix+0.5)]^6`
`f1y = [sin5.1piy+0.5)]^6`
`f2x = exp[-4ln(2)(x-0.0667)^2/0.64]`
`f2y = exp[-4ln(2)(y-0.0667)^2/0.64]`
SYNTAX OF GA FOR IN THIS PROBLEM
x = ga(fun,nvar)
In this syntax is finding a local unconstrained minimum of x , the objection function is stalagmite and number of variables is 2.
Syntax used for optimize the nonsmooth function using ga
x = ga(fun,nvar,A,b,Aeq,beq,lb,Ub)
In this syntax involves defining the upper and lower on the design variable x. So that solution range of x is between the lower bounds to upper bounds
A is a form of matrix at left hand side coefficients of variables of first equation.
b is a form of matrix at right hand side constant of first equation.
Aeq is a equalities and form of matrix at left hand side coefficients of variables on second equation.
beq is a equalities and form of matrix at right hand side constant of variables on second equation.
lb&Ub is a lower bounds and upper bounds
A,b,Aeq,beq is a no linear equalities exists. Syntax is used for linear constraints and bounds
x = ga(fun,nvar,A,b,Aeq,beq,lb,Ub,nonlcon,IntCon,options)
In this syntax additionly mentioning the nonlinear constriants , integer values and options.
Nonlcon, Intcon is empty matrix, option have craete by using the optimoptions.
MAIN PROGRAMMING CODE
clear all % Remove the all variables and corresponding values from workspace tab
close all % Closing the all figures
clc % Clean the command window
x = linspace(0,0.6,150) % Linspace is divide the linearly spacing values in x
y = linspace(0,0.6,150) % Linspace is divide the linearly spacing values in y
[xx yy] = meshgrid(x,y) % Meshgrid command is identified corresponding value for x coordinates & y coordinates
f = get_stalagmite_1(xx,yy) % Stalagmite function generate the function values by using x and y values
num_cases = 100 % Number of iteration is 100
tic % Tic & toc command is help to finding iterating time
% Study1_statistical behaviour of random fitness values at unbounded inputs
for i = 1:num_cases % For loop command pass the values in one by one at each iteration
[inputs,fvalue_1(i)] = ga(@stalagmite,2)
xvalue_1(i) = inputs(1);
yvalue_1(i) = inputs(2);
end
study1_time = toc
figure(1) % Creating the figure
subplot(2,1,1) % Subplot command is allow to figure it in multiple plot
hold on % Hold on command is allow to print in same plot
surfc(x,y,-f) % Surf command is generate the 3d image and c is a contour it shows in different oolor
shading interp % For removing the grid lines
plot3(xvalue_1,yvalue_1,-fvalue_1,'marker','o','markersize',5,'markerfacecolor','r')
title('Unbounded inputs and random fitness values') % Title for plot
xlabel('x values')
ylabel('y values')
zlabel('fit values')
subplot(2,1,2) % Create a another plot in same figure
plot(-fvalue_1) % Plotting individual for stalagmite functon value
title('Plotting fitness values over each iteration') % Title for that subplot
xlabel('Number of iteration')
ylabel('Maximum fitness value')
legend('Fitness values at each iteration')
tic
%Study2_statistical behaviour - with upper and lower bounds
for i = 1:num_cases
[inputs,fvalue_2(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1]);
xvalue_2(i) = inputs(1);
yvalue_2(i) = inputs(2);
end
study2_time = toc
figure(2)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xvalue_2,yvalue_2,-fvalue_2,'marker','o','markersize',5,'markerfacecolor','r')
title('Bounded inputs and bounded fitness values')
xlabel('x values')
ylabel('y values')
zlabel('fit values')
subplot(2,1,2)
plot(-fvalue_2)
title('Plotting fitness values over each iteration')
xlabel('Number of iteration')
ylabel('Maximum fitness value')
legend('Fitness values at each iteration')
% Study3 increasing GA iterations
options = optimoptions('ga');
options = optimoptions(options,'populationsize',170);
tic
for i = 1:num_cases
[inputs,fvalue_3(i)] = ga(@stalagmite,2,[],[],[],[],[0;0],[1;1],[],[],options);
xvalue_3(i) = inputs(1);
yvalue_3(i) = inputs(2);
end
study3_time = toc
figure(3)
subplot(2,1,1)
hold on
surfc(x,y,-f)
shading interp
plot3(xvalue_3,yvalue_3,-fvalue_3,'marker','o','markersize',5,'markerfacecolor','r')
title('Bounded inputs,Converged fitness values with initial population size')
xlabel('x values')
ylabel('y values')
zlabel('fit values')
subplot(2,1,2)
plot(-fvalue_3)
title('Plotting global maxima values over each iteration')
xlabel('Number of iteration')
ylabel('Global maxima value')
legend('Global maxima value at each iteration')
ILLUSTRATIONS
1) Generate the x and y values in linearly spaced by using linsapce command and split the x coordinate values and y coordinate values by using meshgrid command.
2) Create the stalagmite function individually by using that function we generate the stalagmite mathematical model.
3) By using for loop command we iterating the value and pass it into objective stalagmite function.
4) The genetic algorithm is generally calculate the minimum fitness values, by using subraction operation, the objection function is calcualtes maximum value. The syntax of ga is mention in above
5) Each iteration values the function is calculating two variables and one fitness values.
6) Saved the all data and make it into a figures.
7) By realtering the ga function with bounded input values and make it into figure.
8) By again realtering the ga function at third study with bounded input values and populationsize. Afterthat, figure it same manner in previously.
9) Finally, calculate the global maxima point in optimize method.
FUNCTION CODE FOR CREATING THE STALAGMITE MATHEMATICAL MODEL
function [f] = get_stalagmite_1(x,y);
f_1x = [sin(5.1*pi*x + 0.5)].^6;
f_1y = [sin(5.1*pi*y + 0.5)].^6;
f_2x = exp(-4*log(2)*(((x-0.0667).^2)/(0.64)));
f_2y = exp(-4*log(2)*(((y-0.0667).^2)/(0.64)));
f = -(f_1x.*f_2x.*f_1y.*f_2y);
end
ILLUSTRATION
1) The get stalagmite 1 function is used to generate the stalagmite mathematical model in the figure.
2) The x and y values passed into the expression with the help of x coordinate values and y coordinate values.
3) Expression are simplified in f.
FUNCTION CODE FOR OPTIMIZE THE STALAGMITE FUNCTION
function [z] = stalagmite(input_vector);
x = input_vector(1);
y = input_vector(2);
f_1x = [sin(5.1*pi*x + 0.5)].^6;
f_1y = [sin(5.1*pi*y + 0.5)].^6;
f_2x = exp(-4*log(2)*(((x-0.0667).^2)/(0.64)));
f_2y = exp(-4*log(2)*(((y-0.0667).^2)/(0.64)));
z = -(f_1x.*f_2x.*f_1y.*f_2y);
end
ILLUSTRATION
1) This function should be used for finding the ga for calcualting the global maxima.
2) The x and y values are passed into the expression and simplified into z.
3) In syntax we mention this stalagmite function.
RESULTS
1) Plotting the unbounded input GA and combine stalagmite model
1) In this generate without input bounds, the ga can be generate the random values, that values are crossing the stalagmite model bounds.
2) In below plot we mention the global maximum value in individually.
Same plot in z and x axis
The ga can't be calculated the global maxima point in accurately.
Same plot in three dimensional view
Same plot with point values
In this study clearly visible, the global maxima point could't be accurately. It's randomly marked.
2) Plotting the bounded input GA and combine stalagmite model
1) This plot shows, the random value are converged into the bounded range. But it does not represent the global maxima.
2) In some iteration are getting the global maxima, also some iteration are not getting the global maxima.
Same plot in z and x axis
It represent the ga identified the global maxima, but not accurate.
Same plot in three dimensional view
Same plot with point values
The global maxima point is calculated in some iteration, but in some times it also calculate wrong global maxima point. So, we further move to next study.
3) Plotting the bounded input GA with intial population and combine stalagmite model
1) In study 3 the solution get converted into the global maxima in all iteration expert few iterations.
2) The plot represent the global maxima point over the 100 iteration.
Same plot in z and x axis
Same plot in three dimensional view
Same plot with point values
In study 3 the global maxima point is accurate expert few iteration,
WORKSPACE
SIGNIFICANCE OF RUNNING MULTIPLE ITERATIONS
1) When the run the code in multiple iterations we know the solution is converted or not.
2) Easy to visible the random values.
ERRORS FACED WHILE PROGRAMMING
I forgot the parenthesis in both line number 35 and 61. Afterthat, I recorrect it program runs smoothly
Recheck the program in couple of times, so that error could not be appeared.
CONCLUSION
Finally, we finded the global maxima at the stalagmite mathematical model in optimize method in MATLAB coding.
REFERANCE
1) https://in.mathworks.com/help/gads/ga.html
3) https://slideplayer.com/slide/6219125/
4) https://www.gatevidyalay.com/genetic-algorithm-in-ai-operators-working/