Genetic Algorithm: undefined function or method for input arguments of type' double '.
3 次查看(过去 30 天)
显示 更早的评论
i just trained a neural network and I want to test it with new data and save them
namefunction = net;
save namefunction
clear all
clc
load namefunction
my program ga :
fitness= @namefunction ;
nvars=2;% Number of variables
LB=[8 5];%Lb Lower bound on x
UB=[30 10]; %Ub Upper bound on x
[x,y] = ga(@(x)-fitness(x),nvars,[],[],[],[],LB,UB)
i have error !!
??? Error using ==> makeState at 51
GA cannot continue because user supplied fitness function failed with the following error:
Undefined function or method 'namefunction' for input arguments of type 'double'.
Error in ==> galincon at 18
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 306
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in ==> Untitled3 at 5
[x,y] = ga(@(x)-fitness(x(1),x(2)),nvars,[],[],[],[],LB,UB)
0 个评论
回答(1 个)
Star Strider
2020-9-18
The fitness function needs to accept arguments, and (in general) needs to return a scalar result. That will likely require that ‘namefunction’ be specified with the argument list it accepts, for example:
[x,y] = ga(@(x)-namefunction(x(1),x(2)),nvars,[],[],[],[],LB,UB)
Note that since ‘namefunction’ is not provided, we cannot test it with a ga call to see what the problems could be.
2 个评论
Star Strider
2020-9-18
I have no idea what is ‘over the horizon’ — such as whatever ‘namefunction’ is and what its arguments and outputs might be — and so out-of-sight with respect to what you posted.
另请参阅
类别
在 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!