How to incorporate write "options" into the main code (GA algorithm) for beginners
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
I am a beginner to writing matlab code for global optimization using GA algorithm. I can use the live editor to perform the optimization. However, I noticed more than one peak from the resulting plots. It means that there may be more than one optimum conditions. So I would like to write a code that can change number of parents, and at each number of parents, the GA optimization should give me a new set of solutions.
To accomplish this, I wen to this website, https://www.mathworks.com/help/gads/genetic-algorithm-options.html#f6593, and found that I should use options to pass these extra information to my code. This is where the problem started. I don't understand how to incorporate the inforamtion in the link above to my existing main code.
I know that I should write the following two lines:
options = optimoptions('ga','Option1','value1','Option2','value2'); (1)
[x,fval] = ga(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) (2)
To change number of parents, the link above said...
A function handle enables you to write your own selection function.
options = optimoptions('ga','SelectionFcn',@myfun); (3)
Your selection function must have the following calling syntax:
function parents = myfun(expectation, nParents, options) (4)
ga provides the input arguments expectation, nParents, and options. Your function returns the indices of the parents.
To get x and fval, should start with Line 3, followed by Lines 4 and 2?
Thanks
댓글 수: 0
답변 (1개)
Alan Weiss
2022년 1월 21일
I think that you have a misconception about How the Genetic Algorithm Works. ga always takes exactly two parents for creating a child, except when it takes one for a mutation child.
There may indeed be more than one optimum, but it doesn't mean that you should do any parameter tuning to run your optimization. Please read up on this and other topics in the genetic algorithm documentation such as
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
참고 항목
카테고리
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!