Error Message using GA Genetic Algorithm need help!

I am attempting to use a GA toolbox to optimize an input to a set of ODE equations. I am using a base function for the ODE solver, and a second function as the evaluation function for the GA. I have been able to run the ODE function with the evaluation function with no problem, but when I try to use the GA function, I recieve the message below
Error using eval Undefined function 'fhandle' for input arguments of type 'double'.
Error in ga (line 222) eval(e1str);
Error in Untitled (line 3) [w endPop] = ga([0 2],'fhandle',[],Feed,[1e-6 1 1],'maxGenTerm',1,...
Can anyone give me any guidance on what is going wrong or how to troubleshoot this issue? I am not sure where to go with this and I'm new to using this toolbox:
Top Level Script (GA Script) that is giving errors:
Feed =rand(10,1);
fhandle = @HybridomaSolver1;
[w endPop] = ga([0 2],'fhandle',[],Feed,[1e-6 1 1],'maxGenTerm',1,...
'normGeomSelect',[0.08],['arithXover'],[2 0],'nonUnifMutation',[2 1 3]);
Middle Function (Function I am attempting to use as my evaluation function in the GA)
function [mab_output,Feed] =HybridomaSolver1(Feed,options)
global Feed
Feed = rand(10,1);
x0 = [0.79 2E8 25 4 0 0 0];
tspan = [0 10];
%Push feed schedule and initial parameters into ODE
[t,x]=ode45(@hybridoma,tspan,x0);
mab_output = x(end,7)
ODE Function
function dx =hybridoma1(t,x)
global Feed
global F
%Define Variables
%Fermentor working volume (L) = x(1)
%Concentration of viable cells (cells/L) = x(2)
%Concentration of glucose (mM/l) =x(3)
%Concentration of glutamine (mM/l) = x(4)
%Concentration of Lactate (mM/l) = x(5)
%Concentration of Ammonia (mM/l) = x(6)
%Concentration of Monclonal Antibodies (mg/l)= x(7)
%Define parameter values of the kinetic model
umax = 1.09;
kdmax = 0.69;
yxvglc = 1.09E8;
yxvgln = 3.8E8;
mglc = 0.17E-8;
kmglc = 19.0;
kglc = 1.0;
kgln = 0.3;
alpha = 2.57E-8;
ku = 0.02;
beta = 0.35E-8;
kdlac = 0.01;
kdamm = 0.06;
kdgln = 0.02;
ylacglc = 1.8;
yammgln = 0.85;
f=F;
glcin = 25;
glnin = 4;
%Define kinetic expressions
u = umax*(x(3)/(kglc + x(3)))*(x(4)/(kgln + x(4)));
kd = kdmax*(1/(umax-kdlac*x(5)))*(1/(umax-kdamm*x(6)))*(kdgln/(kdgln+x(4)));
qgln = u/(yxvgln);
qglc = u/(yxvglc);
qlac = ylacglc*qglc;
qamm = yammgln*qgln;
alphaprime = (alpha/(ku + u));
qmab = alphaprime*u+beta;
if t < 1
F=Feed(1);
else
if t < 2
F=Feed(2);
else
if t < 3
F=Feed(3);
else
if t < 4
F=Feed(4);
else
if t < 5
F=Feed(5);
else
if t < 6
F=Feed(6);
else if t < 7
F=Feed(7);
else if t < 8
F=Feed(8);
else if t < 9
F=Feed(9);
else if t < 10
F=Feed(10);
end
end
end
end
end
end
end
end
end
end
dx=zeros(7,1);
dx = [f;x(2)*(u-kd)-x(2)*(f/(x(1)))...
;(glcin - x(3))*(f/x(1))-x(2)*qglc...
;(glnin - x(4))*(f/x(1))-x(2)*qgln...
;qlac*x(2) - (f/x(1))*x(5)...
;qamm*x(2) - (f/x(1))*x(6)...
;qmab*x(2) - (f/x(1))*x(7)];
end

1 Comment

Maybe I'm missing something in the documentation for ga, but the fitness function handle is supposed to be the first argument to ga, at least in 2012b. The second argument is supposed to be nvars, ‘Positive integer representing the number of variables in the problem.’ That certainly would explain the thrown error ‘Undefined function 'fhandle' for input arguments of type 'double'’
Could that be part of the problem?

Sign in to comment.

 Accepted Answer

Remove the '' from around 'fhandle' in the ga call:
[w endPop] = ga([0 2],fhandle,[],Feed,[1e-6 1 1],'maxGenTerm',1,...
'normGeomSelect',[0.08],['arithXover'],[2 0],'nonUnifMutation',[2 1 3]);

6 Comments

Now I'm getting a new error.
Undefined function 'lt' for input arguments of type 'function_handle'.
Error in ga (line 92)
if any(evalFN<48) %Not using a .m file
Error in Untitled (line 3)
[w endPop] = ga([0 2],fhandle,[],Feed,[1e-6 1 1],'maxGenTerm',1,...
But my evaluation function is a .M file so I'm not clear on why I'm getting the new error message.
I am confused, as one of the two "Error in" lines shows fhandle without quotes and the other shows fhandle with quotes?
Anyhow, try
[w endPop] = ga([0 2],'HybridomaSolver1',[],Feed,[1e-6 1 1],'maxGenTerm',1,...
'normGeomSelect',[0.08],['arithXover'],[2 0],'nonUnifMutation',[2 1 3]);
There was a copy/paste error in my comment. I updated the error message to clarify. If I put 'HybridomaSolver1' into the function I get the same error message as I got in the first post.
You would probably need to have HybridomaSolver1 in its own .m file for that to work.
From what I can see it is is in it's own .m file. I am using three different M files. One for the "Hybridoma" function, one for the "HybridomaSolver1" function and a third for the GA call.
It's still saying "Undefined function 'fhandle' for input arguments of type 'double'." ???
If it is taking instead about HybridomaSolver1 then it sounds like you have a path problem.

Sign in to comment.

More Answers (2)

If I use the suggestion given, which was to remove the ' ' from the function call, my code looks like this:
"[w endPop] = ga([0 2],fhandle,[],Feed,[1e-6 1 1],'maxGenTerm',1,... 'normGeomSelect',[0.08],['arithXover'],[2 0],'nonUnifMutation',[2 1 3]); "
And I get the following error:
Undefined function 'lt' for input arguments of type 'function_handle'. Error in ga (line 92) if any(evalFN<48) %Not using a .m file Error in Untitled (line 3) [w endPop] = ga([0 2],fhandle,[],Feed,[1e-6 1 1],'maxGenTerm',1,...
If I replace fhandle from the function and replace it with 'HybdridomaSolver1', I will get the error message you just referenced.
It seems like your original answer is pushing my code further along, but I don't know what the "undefined function 'lt' for input arguments of type "function handle" means.
Without trying to understand your code, perhaps this relatively new example can help you get on the right track. In particular, look at step 6.
Alan Weiss
MATLAB mathematical toolbox documentation

Products

Community Treasure Hunt

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

Start Hunting!