Invalid value for OPTIONS parameter PopInitRange: must be an array of finite doubles with two rows.

hello everyone i have problem with this error in genetic algorithm(Invalid value for OPTIONS parameter PopInitRange: must be an array of finite doubles with two rows)
the code is
%To minimize our fitness function using the ga function, we need to pass in a function handle to the fitness function as well as specifying the number of variables as the second argument. Lower and upper bounds are provided as LB and UB respectively. In addition, we also need to pass in a function handle to the nonlinear constraint function.
ObjectiveFunction = @simple_fitness;
nvars = 14; % Number of variables
LB = [0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1]; % Lower bound for (x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
UB = [1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1]; % Upper bound for (x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14)
A=[-4.111 2.633;-4.870 2.992;-2.178 2.992;-3.857 3.130;-3.989 3.678;-4.979 3.620;-5.756 2.948;-5.826 1.607;-2.150 2.948;-6.920 1.607;-2.144 2.952;-5.365 2.952;-4.863 3.348;-5.073 3.680;-3.774 3.774;-6.920 2.995;-2.151 2.995;-4.288 3.237;-4.870 1.608;-5.365 1.608];
b=[-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3;-0.3];
Aeq=[];
beq=[];
nonlcon=[];
IntCon=[];
rng default % For reproducibility
options=gaoptimset('plotfcns',{'gaplotgenealogy','gaplotselection', 'gaplotbestf' ,@gaplotscorediversity});
options= gaoptimset(options,'Tolfun',1e-4,'TolCon',1e-3,'stallGenlimit',1000);
options= gaoptimset(options,'paretoFraction',0.5);
options=gaoptimset(options,'PopInitRang',[0.1 ; 1.1;0.1 ; 1.1;0.1 ;1.1;0.1 ;1.1;0.1 ; 1.1;0.1 ; 1.1;0.1 ; 1.1;0.1 ;1.1;0.1 ; 1.1;0.1 ; 1.1]);
options=gaoptimset(options,'PopulationSize',200);
options=gaoptimset(options,'Display', 'iter');
[x,fval,exitflag,output,population,scores] = ga(ObjectiveFunction,nvars,A,b,Aeq,beq,LB,UB,nonlcon,IntCon,options)
the problem in PopInitRange
many thanks

 Accepted Answer

The error message is telling you that PopInitRange must have two rows, but the value you have given has 20 rows.
ans =
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000
0.1000
1.1000

16 Comments

Yes, or you should use a 2x14 matrix if you want different initial ranges for each of your 14 variables.
Looking at the strange formatting of your input vector (some ; are surrounded by spaces, other are not), I suspect that some of the ; are supposed to be ,
Possibly, it's meant to be
[0.1, 1.1; 0.1, 1.1;0.1, 1.1; 0.1, 1.1; 0.1, 1.1;0.1, 1.1; 0.1, 1.1; 0.1, 1.1; 0.1, 1.1; 0.1, 1.1]'
a matrix with 2 rows and 10 columns. But how can we know? It's your code. Don't expect us to know what you meant to do. If you're not the author of the code then discuss it with the author.
i used this appear [0.1;1.1] a gain alarm (The number of columns in A must be the same as the length of X0.) how can i make the xo equal to A
This worked fine for me,
>> options=gaoptimset(options,'PopInitRang',[0.1 ; 1.1] );
yes i used that comand but the erroe was (The number of columns in A must be the same as the length of X0.) and the A matrix is 2 variable 20 row
Ah, I see. Well, the matrix multiplication A*X0 has to make sense, but in your case does not because A is 20x2 and X0 is 14x1 (you told ga() you had 14 variables).
what is the solution ?
i used this command options=gaoptimset(options,'PopInitRang',[0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;0.1 0.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1;1.1 1.1]);
and the alarm was (Invalid value for OPTIONS parameter PopInitRange: must be an array of finite doubles with two rows.)
The solution is to give inputs with dimensions that make sense.
We have already covered the problem with PopInitRange. It must have dimensions that are either 2x1 or 2xNvars. A 20x2 matrix input therefore makes no sense.
Your second error is due to the dimensions of the A,b inputs. The A matrix must have nVars=14 columns. The A matrix you have given, however, only has 2 columns and therefore makes no sense.
i have these linear constrain with bounded the inequality linear constrain (20)
4.112*x6-2.633*x1 >=0.3; %(linear constraint)
4.870*x1-2.992*x2 >=0.3; %(linear constraint)
2.178*x7-2.992*x2 >=0.3; %(linear constraint)
3.857*x2-3.130*x3 >=0.3; %(linear constraint)
3.989*x3-3.678*x4 >=0.3; %(linear constraint)
4.979*x4-3.620*x5 >=0.3; %(linear constraint)
5.756*x5-2.948*x6 >=0.3; %(linear constraint)
5.826*x5-1.607*x7 >=0.3; %(linear constraint)
2.150*x14-2.948*x6 >=0.3; %(linear constraint)
6.920*x13-1.607*x7 >=0.3; %(linear constraint)
2.144*x7-2.952*x8 >=0.3; %(linear constraint)
5.365*x9-2.952*x8 >=0.3; %(linear constraint)
4.863*x10-3.348*x9 >=0.3; %(linear constraint)
5.073*x11-3.680*x10 >=0.3;%(linear constraint)
3.774*x12-3.774*x11 >=0.3;%(linear constraint)
6.920*x13-2.995*x12 >=0.3;%(linear constraint)
2.151*x14-2.995*x12 >=0.3;%(linear constraint)
4.288*x8-3.237*x13 >=0.3; %(linear constraint)
4.870*x1-1.608*x14 >=0.3; %(linear constraint)
5.365*x9-1.608*x14 >=0.3; %(linear constraint)
0.1 <= x1 <= 1.1; %(bound)
0.1 <= x2 <= 1.1; %(bound)
0.1 <= x3 <= 1.1; %(bound)
0.1 <= x4 <= 1.1; %(bound)
0.1 <= x5 <= 1.1; %(bound)
0.1 <= x6 <= 1.1; %(bound)
0.1 <= x7 <= 1.1; %(bound)
0.1 <= x8 <= 1.1; %(bound)
0.1 <= x9 <= 1.1; %(bound)
0.1 <= x10 <= 1.1; %(bound)
0.1 <= x11 <= 1.1; %(bound)
0.1 <= x12 <= 1.1; %(bound)
0.1 <= x13 <= 1.1; %(bound)
0.1 <= x14 <= 1.1; %(bound)
Very good. The 20 linear inequalities should be expressed as A*x<=b where A is a 20x14 matrix and b is 20x1.
Well, I'll do the first few rows for you, enough for you to see how it works.
A=zeros(20,14); b=zeros(20,1);
A(1,1)=+2.633; A(1,6)=-4.112; b(1)=-0.3; %first row
A(2,1)=-4.870; A(2,2)=+2.992; b(2)=-0.3; %second row
etc...
You can just omit it, and let Matlab use its own defaults, if you don't have any specific plans for what the PopInitRanges should be.

Sign in to comment.

More Answers (0)

Products

Asked:

on 16 Oct 2018

Edited:

on 16 Oct 2018

Community Treasure Hunt

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

Start Hunting!