Genetic Algorithm - Vectorized Mode - Reg

'Position' is a (68,6) array of doubles representing the population of Genetic algorithm. 'classGA1 ' is a (68,1) cell array of the type of population class ( inventory class A,B or C) . 'ClassDM1 ' is a (68,1) cell array of the inventory class(A,B, or C)given by the decision maker (materials manager).
[Fitness] = InvClassifyGAFitnessFunc(Position,classGA1,ClassDM1);
is the Fitness is a (68,1) double array determining the fitness of population.
I want to operate the GA in vectorized mode.
[Fitness] = @(Position)InvClassifyGAFitnessFunc(Position(':',1:6),classGA1{':',1},ClassDM1{':',1});
% vff = @(Position) InvClassifyGAFitnessFunc(Position(':',1:6), classGA1{':'},CDM1{':'});
A=[0,0,0,0,-1,1];
b=[0];
Aeq=[1,1,1,1,0,0];
beq=[1];
lb=[0,0,0,0,0,0];
ub=[1,1,1,1,1,1];
options= gaoptimset('PlotFcn',@gaplotbestf,'Vectorized','on');
[x,fval]=ga(Fitness,6,A,b,Aeq,beq,lb,ub,[],options);
The genetic algorithm is giving the error message
Error using InvClassifyGAFitnessFunc
Too many input arguments.
How to run my genetic algorithm in vectorized mode.

Answers (2)

'classGA1 ' is a (68,1) cell array of the type of population class
When that is the case, then
classGA1{':',1}
expands into 68 different arguments, equivalent to classGA1{:}

4 Comments

madhan ravi
madhan ravi on 30 Dec 2018
Edited: madhan ravi on 30 Dec 2018
+1 sir Walter really humbled(gentled) with your answer as always, interesting was the fact is classGA1{':',1} (was really new) is equivalent to classGA1{:} (which I was aware of this).
out of curiosity : Is there any link about this notation so that more can be learn't?
This gets down to some some internals on how MATLAB processes the : operator . When : is used by itself as a parameter, then what gets passed is ':' (the character), and subsref detects that and understands it as requesting the entire array along that dimension.
Stephen23
Stephen23 on 30 Dec 2018
Edited: Stephen23 on 30 Dec 2018
@madhan ravi: indexing using parentheses, curly braces, etc, is just a convenience notation for subsref. You can see examples in its help:
And also some threads on this forum, showing how this is useful:
This is also why those tutors who give assignments which boldly state "inbuilt functions cannot be used" really are making life very hard for their pupils!

Sign in to comment.

madhan ravi
madhan ravi on 29 Dec 2018
Your function requires only two inputs whereas you have stuffed in 3 .

4 Comments

shall i have to combine the functions 'classGA1' and 'ClassDM1' into a single function ( say name of the combined function is 'class_new' ) .Then it will be o.k?
I don't have any experience with GA but seeing your previous question but it's clear that the function was made with two input arguments there.
i combined the two input arguments to the fitness function into a single argument and ran the GA. but the same error message too many input arguments in the fitness function is coming.
Stephen23
Stephen23 on 30 Dec 2018
Edited: Stephen23 on 30 Dec 2018
"Your function requires only two inputs whereas you have stuffed in 3 ."
There are actually 137 inputs to InvClassifyGAFitnessFunc:
Three inputs is probably the correct number, judging by this earlier thread:

Sign in to comment.

Products

Release

R2015b

Asked:

on 29 Dec 2018

Edited:

on 30 Dec 2018

Community Treasure Hunt

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

Start Hunting!