Error:Too many input arguments in GA solver
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Dear programmers
I need to minimize a single-objective function in ga having two(2) input variables. But the solver is showing an error:Too many input arguments. Please help.
function y = simple_fitness(x)
%SIMPLE_FITNESS fitness function for GA
y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
rng default % For reproducibility
FitnessFunction = @simple_fitness;
numberOfVariables = 2;
lb = [-3,-3];
ub = [3,3];
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub);
채택된 답변
Mario Malic
2020년 8월 15일
편집: Mario Malic
2020년 8월 15일
function y = simple_fitness(x)
y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
end
rng default % For reproducibility
numberOfVariables = 2;
lb = [-3,-3];
ub = [3,3];
[x,fval] = ga(@(x)simple_fitness(x),numberOfVariables,[],[],[],[],lb,ub);
Now should be working.
댓글 수: 12
Dear Mario
Thank you for your reply. I have tried what you have suggested but it is showing same error. But the same error doesnot arise when I run the same code in multi-objective GA solver.
Edited the main answer
Dear Mario
Still not working.

What do you have in simple_fitness.m
Only this much piece of script. But I am astonished that the algorithm is running now when I have copied the files to Desktop and running from there rather than a different folder that I was running before. Thanks for the help Mario. But may I know what might be causing this problem?
function y = simple_fitness(x)
y = 100 * (x(1)^2 - x(2)) ^2 + (1 - x(1))^2;
end
With the same code I get this error: Optimization terminated: maximum number of generations exceeded.
I can't point out at something. Maybe your workspace contained variables from runs before, or interference with files/functions having the same name.
Dear Sara
What is the maximum number of generations you have provided as a stopping criteria ? If the algorithm reach your defined stopping criteria, it will terminate. Like in my case it has terminated as "Optimization terminated: average change in the fitness value less than options.FunctionTolerance." as the algorithm has already reached provided Function Tolerance.
Yes Mario...It might be a case though it is not rightly detectable since the code was okay. Thanks again.
This is what is saved in x and in fval is saved 1 constant ... 1.2344
Mario Malic
2020년 8월 15일
편집: Mario Malic
2020년 8월 15일
[x,fval,exitflag,output,population,scores] = ga(___)
This is a code if one should further investigate about the solution, and maybe try to check the available ga options if solution is not the optimal one.
Also, since this function is quite straight forward, one could just generate meshgrid within the bounds, evaluate objective function and then find a minimum of it.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

