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 件のコメント
Rajdeep Ghosh
2020 年 8 月 15 日
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.
Mario Malic
2020 年 8 月 15 日
Edited the main answer
Rajdeep Ghosh
2020 年 8 月 15 日
Dear Mario
Still not working.

Mario Malic
2020 年 8 月 15 日
What do you have in simple_fitness.m
Rajdeep Ghosh
2020 年 8 月 15 日
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
Sara Boznik
2020 年 8 月 15 日
With the same code I get this error: Optimization terminated: maximum number of generations exceeded.
Mario Malic
2020 年 8 月 15 日
I can't point out at something. Maybe your workspace contained variables from runs before, or interference with files/functions having the same name.
Rajdeep Ghosh
2020 年 8 月 15 日
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.
Rajdeep Ghosh
2020 年 8 月 15 日
Yes Mario...It might be a case though it is not rightly detectable since the code was okay. Thanks again.
Sara Boznik
2020 年 8 月 15 日

Sara Boznik
2020 年 8 月 15 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
