Reputation: 2867
I am running into a puzzling error when when using the ga
function in MATLAB's global optimization toolbox, the error message is pasted below to see if anyone can decipher what this means.
I am trying to seed the ga
with an initial population, a matrix of pop-by-nvar. However, this produces the error below. I can only get the ga
to run if I pass in an initial population vector of (pop-1)-by-nvar. This is a little inconvenient since I want to specify the entire population. I hope someone who is familiar with the global optimization toolbox and the ga
function can shed some light here!
??? Index exceeds matrix dimensions.
Error in ==> gacreationlinearfeasible>lhsLambda at 213
[lambda(i,:),f,e] = fmincon(fun,lambda(i,:),[],[],Aeq,beq,lb,ub,[],opts);
Error in ==> gacreationlinearfeasible>feasibleLHS at 180
initialPopulation(boundary_points+1:interior_points+boundary_points,:) = ...
Error in ==> gacreationlinearfeasible at 42
feasiblePop = feasibleLHS(individualsToCreate,GenomeLength,options);
Error in ==> makeState at 30
state.Population = feval(options.CreationFcn,GenomeLength,FitnessFcn,options,options.CreationFcnArgs{:});
Error in ==> galincon at 18
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 282
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Upvotes: 0
Views: 2488
Reputation: 1
I had the same problem when fully defining the initial population (population size is equal to the number of rows of the initial population matrix). It was caused by the violation of the linear constraints by one of the individuals of the initial population. So check if the manually assigned individuals do not violate the linear constraints.
Upvotes: 0
Reputation: 124553
Here is an example of using GA with specifying an initial population:
%# find minima
initPop = bsxfun(@plus, [2 3], randn(20,2)*2); %# 20-by-2 matrix
opts = gaoptimset('InitialPopulation',initPop);
[x, fx, flag, out, pop] = ga(@rastriginsfcn, 2, [],[], [],[], [],[], [], opts);
%# plot solution
figure('Renderer','opengl')
ezsurfc(@(x,y) rastriginsfcn([x,y])), colormap hot
line(x(1), x(2), fx, 'Marker','.', 'MarkerSize',50, 'Color','b')
view(3)
Here is the solution I get after 72 generations:
Note that the Rastrigin function has the global minimum at (0,0)
Upvotes: 2