Genetic algorithm only runs when length of upper bound is less than length of lower bound?

2 views (last 30 days)
Hello,
I am having trouble running genetic algorithm. Specifically, a strange error occurs when the length of the upper bound vector equals the length of the lower bound vector. When I remove one element from the upper bound vector (xU), the code runs. However, this means I have 15 lower bound specified and only 14 upper bounds. Here is part of the code:
%GA version: Parameter Order
% zL, zC, deltaC, kC, kLG, kLB, yLG, betaL, alpha, muL, rhoB, rhoG, rhoGE, betaC, muC
xL=[ 0, 0, 0, 0, 0, 0, yLB+.05, 0, .1, 0, .1, .1, .05, .05, 0];
xU=[yLB, 2, .6, 5, 8, 8, 5, 1, .95, 12, 20, 20, 20, .98, 500];
x0=[0.3100 0.2258 0.5249 4.4122 5.6260 1.8038 1.0989 0.3339 0.9092 0.6372 4.0550 1.5930 0.8329 0.2896 11.9331];
%0.3100 0.2258 0.5249 4.4122 5.6260 1.8038 1.0989 0.3339 0.9092 0.6372 4.0550 1.5930 0.8329 0.2896 11.9331];
options1=optimoptions(@ga,'Display','Iter','FunctionTolerance',1e-30,'MaxGenerations',50,'UseParallel',true,'InitialPopulationMatrix',x0,'MaxStallGenerations',15);
[parameters1,error1]=ga(@(x) func_main_endogref_OTJS_ga_test(x,r,D,gamma, yLB, mrktt_target,urate_target,replace_target,reffrac_target,reffracOTJS_target,lshare_target,costdiff_target,...
bdist_target,jtjfrac_target,EE_sepfrac_target,wagechange_target,jfprob_target,EE_EU_scale_target,...
EU_frac_target,Lc,deltaL,vc_cost_target,reffracU_target,esub),15,[],[],[],[],xL,xU,[],[],options1);
The error message I get is:
Error using trust (line 29) Input matrix contains NaN or Inf.
Error in trdog (line 108) st = trust(rhs,MM,delta);
Error in snls (line 319) [sx,snod,qp,posdef,pcgit,Z] = trdog(x,g,A,D,delta,dv,...
Error in lsqncommon (line 166) snls(funfcn,xC,lb,ub,flags.verbosity,options,defaultopt,initVals.F,initVals.J,caller, ...
Error in lsqnonlin (line 240) lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,...
Error in func_main_endogref_OTJS_ga_test (line 38) [vars2,error2]=lsqnonlin(@(x) func_endogref_OTJS_test(x,zL,zC,deltaC,deltaL,D, alpha, muLG, muC, kC, kLG, kLB, yLG, yLB, gamma, betaL, betaC, rhoB, rhoG, chi, Lc, muLB, rhoGE,esub),x0,xL,xU,options2);
Error in fcnvectorizer>@(x)func_main_endogref_OTJS_ga_test(x,r,D,gamma,yLB,mrktt_target,urate_target,replace_target,reffrac_target,reffracOTJS_target,lshare_target,costdiff_target,bdist_target,jtjfrac_target,EE_sepfrac_target,wagechange_target,jfprob_target,EE_EU_scale_target,EU_frac_target,Lc,deltaL,vc_cost_target,reffracU_target,esub)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 16) parfor (i = 1:popSize)
Error in makeState (line 58) Score = fcnvectorizer(state.Population(initScoreProvided+2:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in galincon (line 17) state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 374) [x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in calibration_endogref_OTJS_MF_test (line 71) [parameters1,error1]=ga(@(x) func_main_endogref_OTJS_ga_test(x,r,D,gamma, yLB, mrktt_target,urate_target,replace_target,reffrac_target,reffracOTJS_target,lshare_target,costdiff_target,bdist_target,jtjfrac_target,EE_sepfrac_target,wagechange_target,jfprob_target,EE_EU_scale_target,EU_frac_target,Lc,deltaL,vc_cost_target,reffracU_target,esub),15,[],[],[],[],xL,xU,[],[],options1);
Caused by: Failure in user-supplied fitness function evaluation. GA cannot continue.
What is even more strange is that if I use another function, such as fmincon, there are no problems at all, even with the upper and lower bound being the same length. So this problem seems to be unique to genetic algorithm. This is only part of the code, which is comprised of several function files, so I did not want to post everything. Let me know if more is needed. If anyone could provide some guidance on what exactly this error is telling me, that would be great.

Answers (0)

Community Treasure Hunt

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

Start Hunting!