MATLAB Answers

Genetic Algorithm: undefined function or method for input arguments of type' double '.

3 views (last 30 days)
ad aymen
ad aymen on 18 Sep 2020
Commented: Star Strider on 18 Sep 2020
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

Sign in to comment.

Answers (1)

Star Strider
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.
See the ga documentation section on fun.

  2 Comments

ad aymen
ad aymen on 18 Sep 2020
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 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.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!