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
VIGNESH KUMAR R C 2023년 5월 5일
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