Hello everyone! this is the first time I am using GA and I encountered with this message:Failure in initial user-supplied fitness function evaluation. GA cannot continue.

2 ビュー (過去 30 日間)
here is my codes.
k1=0.6;
k2=0.25;
k3=0.15;
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
function t=myfcn(f)
t=(k1*f(1)+k2*f(2)+k3*f(3));
end
%%all f values have been attained in another code
can anyone help me with this?

採用された回答

Geoff Hayes
Geoff Hayes 2020 年 3 月 25 日
編集済み: Geoff Hayes 2020 年 3 月 25 日
amir - you don't need to supply the f, those f values that have been attained in another code. The genetic algorithm will provide those from the initial population and from the subsequent generations (via crossover and mutation). All you need to do is pass in the function handle like
[x,fval] = ga(@myfcn, 3)
Since your myfcn depends upon the k1, k2, and k3, then ensure that your fitness function is nested within the main function
function main
k1=0.6;
k2=0.25;
k3=0.15;
[x,fval] = ga(@myfcn,3)
function t=myfcn(f)
t=(k1*f(1)+k2*f(2)+k3*f(3));
end
end
and saved (in this case) to a file named main.m. (Perhaps you have already done this.)
  12 件のコメント
Geoff Hayes
Geoff Hayes 2020 年 3 月 25 日
amir - unfortunately, I only correspond with MATLAB users via this forum.
Amir Hosseini
Amir Hosseini 2020 年 3 月 25 日
yes thank you that is understandable. I wanted to make an offer of working together and expand my article to publish it soon.
I would really appreciate it if you let me know in case of your willingness by personal email.
yours truly!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by