GA optimiser error in boxdirections
2 ビュー (過去 30 日間)
古いコメントを表示
I constantly get the error shown below here and I would very much appreciate if anyone could point to what I can do to avoid this. Version is Matlab 2013a. Thanks!
Error using / Matrix dimensions must agree.
Error in boxdirections (line 23) pollParam = 1/sqrt(MeshSize);
Error in mutationadaptfeasible (line 71) [Basis,TangentCone] = boxdirections(true,StepSize,x,linCon.lb,linCon.ub,tol);
Error in stepGA (line 36) mutateKids = feval(options.MutationFcn, parents((1 + 2 * nXoverKids):end), options,GenomeLength,FitnessFcn,state,thisScore,thisPopulation,options.MutationFcnArgs{:});
Error in galincon (line 63) [score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn);
Error in ga (line 351) [x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in GAOptimDesign (line 8) [x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB)
The code I am running is as follows, i.e. the ga optimiser from the optimtool:
ObjectiveFunction = @design; nvars = 12; % Number of variables LB = [-3 -3 -3 -3 18 10 10 5 65 65 65 65]; % Lower bound UB = [5 5 5 5 30 25 25 20 75 75 75 75]; % Upper bound
options = gaoptimset('PopulationSize',3) [x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB
The design function is way to large to describe here.
0 件のコメント
採用された回答
Igor
2014 年 1 月 7 日
Hi Ulrik,
From the docs: "You should set Population size to be at least the value of Number of variables, so that the individuals in each population span the space being searched".
If you have 12 design variables, the population size should at least be 12, not 3.
Other than that please check your code inside "design.m" to make sure you're supplying column vectors where it expects column vectors, and row vectors if it expects row vectors.
3 件のコメント
Igor
2014 年 1 月 7 日
Ulrik,
First of all, I believe you understand that the actual problem is probably not in the GA function, but in the way you call it. The MATLAB code for GA must have been tested many times. This does not mean there cannot be pitfalls, but chances are high that the code is correct.
With that said, I do not quite understand what you create the options structure for. If you call GA this way:
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB)
the options you have set won't be used. You can pass your options this way:
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,[],options);
Your error message is not about this though. As you claim to have never had problems with "design.m", may I ask you if you have ever used other optimization routines for it, or just called the function by itself? If the latter is true, it could help if you could provide the header of your function i.e. something like
function [ out1, out2, ... ] = design( in1, in2, ...)
その他の回答 (1 件)
Aliyu Bagudu
2016 年 4 月 5 日
I had the same problem however, I was able figure out where the problem actually comes from. The problem comes from the formula GA uses to calculate the number children of the next generation and thus the number of selected parents. There are 3 types of children in GA: Elite children(specified by EliteCount), Crossover children(specified by crossoverFraction) and calculated as crossoverFraction*(populationSize - EliteCount), and mutation children (calculated using populationSize - EliteCount - crossover children). You don't specify number of mutation children, it is calculated.
So the problem comes from rounding when calculation crossover fraction. The rounding is done to the nearest integer. So for some combination of populationSize, crossoverFraction, and EiltCount, this can result in total number of children that is not equal to populationSize.
Number of parents is 2 times number of children for crossover children. For mutation number of parents is equal to number of children.
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!