Genetic Algorithm: Failure in initial user-supplied fitness function evaluation. GA cannot continue.

7 次查看(过去 30 天)
Hello everyone !
I'm currently trying to use a genetic algorithm for a simple problem, but it fails and I don't know why. This is my first time using a genetic algorithm function.
I have a function AlgoGen with 3 variables:
[Sol] = AlgoGen(alpha,beta,gamma).
That I can calculate if I try several inputs, so this function works. But when I'm trying to use:
SOL = ga(@(x) AlgoGen(x),3,[],[],[],[],[1 2.25*10^-2 1],[5 15*10^-2 5])
This is the error message I get:
Not enough input arguments.
Error in AlgoGen (line 5)
length=[1 0.75 1 1 alpha gamma]*10^-2;
Error in @(x)AlgoGen(x)
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 galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 374)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
Anyone can help me ? Thank you.
  1 个评论
VIGNESH KUMAR R C
This is my Cost Function definition:
function f = costFn(i_d, i_q)
L_d = 100e-6;
L_q = 500e-6;
lambda_f = 0.01;
P = 6;
T_e = 2.5;
f = (T_e - (3/2)*(P/2)*(lambda_f.*i_q + (L_d-L_q).*i_d.*i_q)).^2;
end
This is how I am trying to implement ga:
clc;
clear;
type costFn
fun = @(i_d, i_q)(costFn(i_d, i_q));
fsurf(fun, [-50 50 -50 50])
colormap 'parula'
xlabel('i_d')
ylabel('i_q')
sol = ga(fun,2);
I am getting same error as above. Kindly help me out.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2017-11-10
You need to supply a function with a single vector argument to ga.
This should work:
SOL = ga(@(x) AlgoGen(x(1),x(2),x(3)),3,[],[],[],[],[1 2.25*10^-2 1],[5 15*10^-2 5])
Here, ‘x(1)=alpha’, ‘x(2)=beta’ and ‘x(3)=gamma’.
No other changes to your code should be necessary.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by