Dear Geoff how can I find out at which iteration I got the result?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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?
1 件のコメント
採用された回答
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 件のコメント
Amir Hosseini
2020 年 3 月 25 日
thanks for youre attention Geoff!
actually I did it but still getting the same error. what should I do?
Amir Hosseini
2020 年 3 月 25 日
編集済み: Geoff Hayes
2020 年 3 月 25 日
yes-
function myfun %%which is main m.file
k1=0.6;
k2=0.25;
k3=0.15;
[x,fval] = ga(@(f)myfcn ,3)
function t=myfcn(f)
t=(k1*f(1)+k2*f(2)+k3*f(3));
end
end
and the error is:
>> myfun
Not enough input arguments.
Error in myfun>myfcn (line 15)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn(f)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 11)
[x,fval] = ga(fft,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Index exceeds the number of array elements (1).
Error in myfun>myfcn (line 15)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn(f(1),f(2),f(3))
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 11)
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Error using myfun>myfcn
Too many input arguments.
Error in myfun>@(f)myfcn(f(1),f(2),f(3))
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 11)
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Error using myfun>myfcn
Too many input arguments.
Error in myfun>@(f)myfcn(f(1),f(2),f(3))
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 11)
[x] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Error using myfun>myfcn
Too many input arguments.
Error in myfun>@(f)myfcn(f(1),f(2),f(3))
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 11)
x = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Error using functionHandleOrCell (line 12)
The constraint function must be a function handle.
Error in validate (line 228)
[nonlcon,NonconFcnArgs] = functionHandleOrCell('NonconFcn',nonlcon);
Error in gacommon (line 65)
[options,nvars,FitnessFcn,NonconFcn] = validate(options,type,nvars,fun,nonlcon,user_options);
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in myfun (line 11)
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3,[],[],[],[],[],[],100)
>> myfun
Error using functionHandleOrCell (line 12)
The constraint function must be a function handle.
Error in validate (line 228)
[nonlcon,NonconFcnArgs] = functionHandleOrCell('NonconFcn',nonlcon);
Error in gacommon (line 65)
[options,nvars,FitnessFcn,NonconFcn] = validate(options,type,nvars,fun,nonlcon,user_options);
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in myfun (line 11)
[x,fval,exitFlag,output,population,scores] = ga(@(f)myfcn(f(1),f(2),f(3)),3,[],[],[],[],[],[],100)
>> myfun
Error using preProcessLinearConstr (line 69)
The number of rows in Aeq must be the same as the length of beq.
Error in gacommon (line 97)
[Iterate.x,Aineq,bineq,Aeq,beq,lb,ub,msg,exitFlag] = preProcessLinearConstr( ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in myfun (line 11)
[x,fval,exitFlag,output,population,scores] = ga(@(f)myfcn(f(1),f(2),f(3)),3,[],[],100,[])
>> myfun
Error using preProcessLinearConstr (line 69)
The number of rows in Aeq must be the same as the length of beq.
Error in gacommon (line 97)
[Iterate.x,Aineq,bineq,Aeq,beq,lb,ub,msg,exitFlag] = preProcessLinearConstr( ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in myfun (line 11)
[x,fval,exitFlag,output,population,scores] = ga(@(f)myfcn(f(1),f(2),f(3)),3,[],[],100,[])
>> myfun
Error using preProcessLinearConstr (line 69)
The number of rows in Aeq must be the same as the length of beq.
Error in gacommon (line 97)
[Iterate.x,Aineq,bineq,Aeq,beq,lb,ub,msg,exitFlag] = preProcessLinearConstr( ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in myfun (line 11)
[x,fval,exitFlag,output,population,scores] = ga(@(f)myfcn(f(1),f(2),f(3)),3,[],[],100,[])
>> myfun
Error using preProcessLinearConstr (line 69)
The number of rows in Aeq must be the same as the length of beq.
Error in gacommon (line 97)
[Iterate.x,Aineq,bineq,Aeq,beq,lb,ub,msg,exitFlag] = preProcessLinearConstr( ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in myfun (line 11)
[x,fval,exitFlag,output,population,scores] = ga(@(f)myfcn(f(1),f(2),f(3)),3,[],[],100,[])
>> myfun
Error using myfun>myfcn
Too many input arguments.
Error in myfun>@(f)myfcn(f(1),f(2),f(3))
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Error using myfun/myfcn
Too many input arguments.
Error in myfun>@(f)myfcn(f(1),f(2),f(3)) (line 8)
[~,~] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[~,~] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Error using myfun/myfcn
Too many input arguments.
Error in myfun>@(f)myfcn(f(1),f(2),f(3)) (line 8)
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Not enough input arguments.
Error in myfun/myfcn (line 12)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Not enough input arguments.
Error in myfun/myfcn (line 12)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Not enough input arguments.
Error in myfun/myfcn (line 12)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Not enough input arguments.
Error in myfun/myfcn (line 12)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn (line 16)
[x,fval] = ga(@(f)myfcn ,3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 16)
[x,fval] = ga(@(f)myfcn ,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Not enough input arguments.
Error in myfun/myfcn (line 12)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
[x,fval] = ga(@(f)myfcn ,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>> myfun
Not enough input arguments.
Error in myfun/myfcn (line 12)
t=(k1*f(1)+k2*f(2)+k3*f(3));
Error in myfun>@(f)myfcn (line 8)
x = ga(@(f)myfcn ,3)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 398)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in myfun (line 8)
x = ga(@(f)myfcn ,3)
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>>
Geoff Hayes
2020 年 3 月 25 日
amir - replace this line
[x,fval] = ga(@(f)myfcn ,3)
with just
[x,fval] = ga(@myfcn ,3)
You do not need to specify the imput parameter.
Amir Hosseini
2020 年 3 月 25 日
wow thanks man it worked but I didn't get the desirable results of my article. However, youre answer was just accepted but do you think the wrong result may have caused by wrong f because we didn't assign the f for GA
Geoff Hayes
2020 年 3 月 25 日
there could be any number of reasons why you didn't get the desirable results. Are you comparing against the results from a published article? Did they use a genetic algorithm? Do you know which crossover methods they used or mutation?
Amir Hosseini
2020 年 3 月 25 日
yes I am comparing with a published article and they used GA but they didn't mention the type of mutations and crossovers.how should I find out?
and in this code which kind of mutation and crossover we are using?
Geoff Hayes
2020 年 3 月 25 日
編集済み: Geoff Hayes
2020 年 3 月 25 日
You could contact the author to find out what are the parameters they used for their GA. In the MATLAB code, you would be using the default crossover and mutation operators (you might find out which from Find minimum of function using genetic algorithm).
Amir Hosseini
2020 年 3 月 25 日
thank you very much indeed dear Geoff that was really nice of you!
will you please send me an empty email to amirhsn51@gmail.com please?
Geoff Hayes
2020 年 3 月 25 日
amir - unfortunately, I only correspond with MATLAB users via this forum.
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 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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)