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)

回答(1 个)

Star Strider
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.
See the ga documentation section on fun.
  2 个评论
ad aymen
ad aymen 2020-9-18
Unfortunately,the same error, the results were there before, but when i saved the results neural network again, an error has occurred
Star Strider
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 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