Choosing optimal values from the genetic algorithm
조회 수: 21 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Sam Chak
2023년 2월 3일
편집: Sam Chak
2023년 2월 3일
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!