Matlab Fitness Function Genetic Algorithm Error
Show older comments
Hey everyone, I am trying to use genetic algorithm in matlab to perform SMM. However, I am having difficulties with passing extra parameters through the ga function. I have successfully used this function (and successfully passed the parameters through) with lsqnonlin, so I suspect there is some formatting error I am not understanding.
Here is where I call the function using ga:
xL=[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,1.5,1.5];
xU=[.5,.5,.6,.6,.95,10,5, 5, .15, .15,.95,1,1,.95,.95,2,2,10,7,7];
FitFunc=@(x) lsqnonlindiscretecalibrate_V2_AR(x,A1,A2,r,discount,fracc,matchfrac1,matchfrac2,wageprem,N,targetu1,targetu2,sepfrac,thetatarget,...
percent1,percent2,moverate_target,jfptarget,jsptarget,lstarget,avgutarget,replacetarget,etarget,duration_target1,duration_target2,...
fsize,emplyfrac_target,lag1target,lag2target,ssq1target,ssq2target,durtarget,sims,burn,yfrac_target);
options2=optimoptions(@ga,'Display','Iter','FunctionTolerance',1e-30,'MaxGenerations',3,'UseParallel',true);
[vars_parameters,error_param]=ga(FitFunc,20,[],[],[],[],[],xL,xU,options2);
Here is the beginning of the function file itself:
function SSRc=lsqnonlindiscretecalibrate_V2_AR(x,A1,A2,r,discount,fracc,matchfrac1,matchfrac2,wageprem,N,targetu1,targetu2,sepfrac,thetatarget,percent1,percent2,moverate_target,jfptarget,jsptarget,lstarget,avgutarget,replacetarget,etarget,duration_target1,duration_target2,fsize,emplyfrac_target,lag1target,lag2target,ssq1target,ssq2target,durtarget,sims,burn,yfrac_target)
z1=x(1);
z2=x(2);
rho1=x(3);
rho2=x(4);
beta=x(5);
k1=x(6);
mu1=x(7);
mu2=x(8);
deltac=x(9);
deltad=x(10);
ps=x(11);
alpha1=x(12);
alpha2=x(13);
Lp1=x(14);
Lp2=x(15);
psig1=x(16);
psig2=x(17);
k2=x(18);
p1bar=x(19);
p2bar=x(20);
....Some stuff... end
And here is the error I get:
Error using functionHandleOrCell (line 12) The constraint function must be a function handle. Error in validate (line 228) [nonlcon,NonconFcnArgs] = functionHandleOrCell('NonconFcn',nonlcon);
Error in gacommon (line 65) [options,nvars,FitnessFcn,NonconFcn] = validate(options,type,nvars,fun,nonlcon,user_options); Error in ga (line 336) NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ... Error in discrete_calibration_V2_AR (line 92) [vars_parameters,error_param]=ga(FitFunc,20,[],[],[],[],[],xL,xU,options2);
Apologies for the lengthy names, I need to keep everything straight. I understand that I am inputting something in a way Matlab doesn't like, but I cannot figure out what it should be. I have read the documentation for passing parameters in ga, and I think this is correct. Any help would be greatly appreciated, I assume it's something simple I do not understand/missed!
Accepted Answer
More Answers (0)
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!