Genetic Algorithm: Failure in initial user-supplied fitness function evaluation. GA cannot continue.
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Nicolas
il 10 Nov 2017
Commentato: VIGNESH KUMAR R C
il 5 Mag 2023
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 Commento
VIGNESH KUMAR R C
il 5 Mag 2023
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.
Risposta accettata
Star Strider
il 10 Nov 2017
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.
2 Commenti
Star Strider
il 10 Nov 2017
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!