Genetic Algorithm: undefined function or method for input arguments of type' double '.
조회 수: 2 (최근 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!