GA optimiser error in boxdirections
1 次查看(过去 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!