フィルターのクリア

Μultiple errors (error in rand, selectiontournament, stepGA, galincon, gaminlpengine, gaminlp, ga) when i try to use the ga toolbox

1 回表示 (過去 30 日間)
Stathis
Stathis 2023 年 2 月 15 日
回答済み: Yash 2023 年 9 月 6 日
clear all
clc
[inc,onc,net]=nn_creator_func(1);
prompt1='Give the thickness of the plate: \n';
pt=input(prompt1);
prompt2='Give the y coordinate of all points in the junction area: \n';
jpcy=input(prompt2);
prompt3='Give the x coordinate of a point: \n';
pcx=input(prompt3);
prompt4='Give the z coordinate of the same point: \n';
pcz=input(prompt4);
if (jpcy+0.004<=0.026 && (pcx>=0 && pcx<=0.039) && (jpcy>=0 && jpcy<=0.026) && (pcz>=0 && pcz<=pt));
%res=objective_cost_func(in_var,pt,jpcy,pcx,pcz,inc,onc,net);
%[x,fval]=ga(@(in_var)objective_cost_func(in_var,pt,jpcy,pcx,pcz,inc,onc,net),3);
options=struct('PopulationSize',70, 'InitailPopulationRange',[807 0.0026 187;992 0.0037 219],....
'EliteCount',0.04,'CrossoverFraction',0.7,....
'MaxGenerations',400,'MaxTime',180,'FitnessLimit',0.5,....
'MaxStallGenerations',10,'FunctionTolerance',0.0001,....
'MaxStallTime',15,'Display','diagnose',....
'PlotFcn',{@gaplotrange, @gaplotbestf});
[x,fval]=ga(@(in_var)objective_cost_func(in_var,pt,jpcy,pcx,pcz,inc,onc,net),3,[],[],[],[],[807 0.0026 187],[992 0.0037 219],[],1:2:3,options);
else
error('Error: Wrong input values')
end
The function nn_creator_func trains a neural network and returns the normalization constants of the input and output and the object of the neural network.
When i run the programm i get the following errors
Error using rand
Size inputs must be integers.
Error in selectiontournament (line 28)
playerlist = ceil(size(expectation,1) * rand(nParents,tournamentSize));
Error in stepGA (line 20)
parents = feval(options.SelectionFcn,state.Expectation,nParents,options,options.SelectionFcnArgs{:});
Error in galincon (line 62)
[score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn);
Error in gaminlpengine (line 36)
Error in gaminlp (line 34)
Error in ga (line 351)
[x,fval,exitFlag,output,population,scores] = gaminlp(FitnessFcn,nvars, ...
Error in ga_code (line 23)
[x,fval]=ga(@(in_var)objective_cost_func(in_var,pt,jpcy,pcx,pcz,inc,onc,net),3,[],[],[],[],[807 0.0026 187],[992 0.0037 219],[],1:2:3,options);
Does anyone know why these errors occur? It will help a lot.

回答 (1 件)

Yash
Yash 2023 年 9 月 6 日
Hi Stathis
The errors you are encountering seem to be related to the options you have set for the Genetic Algorithm (GA) solver in MATLAB. Let's go through the errors one by one and see how to resolve them:
  1. Error using rand - Size inputs must be integers: This error is occurring because the "tournamentSize" parameter for the selection method in your GA options is not an integer. In your options definition, you have specified "EliteCount", 0.04, which is not a valid integer value for the "EliteCount" parameter.
  2. Error in stepGA (line 20): This error occurs due to the previous error in the "selectiontournament" function, which is called by the GA solver. Fixing the first error should resolve this one as well.
  3. Error: Wrong input values: If you see this error, it means that the conditions in your if statement are not being met, and the code is raising this error message.
After fixing the issues mentioned above, your code should run without errors related to the GA solver.
Please refer to the documentation below for more information:
I hope this helps.

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by