Choosing optimal values from the genetic algorithm
2 views (last 30 days)
Show older comments
As GA are probabilistic and indetriministic everytime I run the code I am getting different optimas with the same value of objective function.
How to choose the proper and best optima when the function value remains same for different optimias.
Is there any way to choose the best optima.
Thank you in Advance!!
0 Comments
Answers (1)
Sam Chak
on 3 Feb 2023
Edited: Sam Chak
on 3 Feb 2023
Hi @Vivek
You can try setting the rng to 'default' for the reproducibility of the result.
If the function has multiple extrema, I'd probably set the lower and upper bounds on the design variables, so that the solution is searched and found in the range of interest.
xx = linspace(-pi, pi, 51);
yy = linspace(-pi, pi, 51);
[X, Y] = meshgrid(xx, yy);
Z = (sin(X)).^2 + (cos(Y)).^2;
% contour(X, Y, Z)
surfc(X, Y, Z)
xlabel('x_1'), ylabel('x_2'), zlabel('f(x_1, x_2)')
rng default % For reproducibility
fun = @(x) (sin(x(1))).^2 + (cos(x(2))).^2;
lb = [-pi -pi]; % lower bound
ub = [pi pi]; % upper bound
x = ga(fun, 2, [], [], [], [], lb, ub)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!