Genetic Algorithm: undefined function or method for input arguments of type' double '.
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 18 Sep 2020
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 Comments
Star Strider
on 18 Sep 2020
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.
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!