Genetic Algorithm Initial Population Problem in Matlab
Show older comments
How can I generate initial population of 50*11 in Matlab? The Upper and Lower limits are as under;
ub = [80 75 35 60 50 1.1 1.1 1.1 1.1 1.1 1.1];
lb = [20 0 10 0 0 0.95 0.95 0.95 0.95 0.95 0.95];
dim=11;
Population=50;
Answers (1)
Star Strider
on 6 Jan 2020
This is what I would do:
opts = optimoptions('ga', 'InitialPopulationMatrix',[randi([20 80], 50, 5) randi([95 110], 50, 6)*1E-2]);
The ga function does not need to know all the ranges, however it is (in my experience) usually better to begin with lower values than higher values, since ga more easily increases than decreases the individual elements in the population ‘genes’.
Include whatever other options you want. Then be sure to include ‘opts’ as the last argument to the ga call, remembering to fill all the intervening arguments with appropriate arguments or the empty matrix [].
4 Comments
Salah Djerouni
on 8 Mar 2020
hi ,
can you tell me ,how can define the pouplation in my case
objfnc=@first4;
nvar=7;
%% Bounds %
% %% beta
Lbeta=0;
Ubeta=0.5;
% %% Mass
m1_min=0; % TMD
m1_max=20;
c1_min=0; % TMD
c1_max=370;
k1_min=0; % TMD
k1_max=39765;
m2_min=0; % TMDI
m2_max=50;
c2_min=0; % TMDI
c2_max=370;
k2_min=0; % TMDI
k2_max=99413;
LB=[Lbeta m1_min c1_min k1_min m2_min c2_min k2_min ];
UB=[Ubeta m1_max c1_max k1_max m2_max c2_max k2_max ];
% options = gaoptimset('PlotFcns',@gaplotbestf );
% % options = gaoptimset(@gamultiobj,'PlotFcn',{@gaplotpareto});
% [x,fval]=ga(objfnc,nvar,[],[],[],[],LB,UB,[],options);
Walter Roberson
on 8 Mar 2020
What is the reason to supply your own random initial population? ga will construct a population inside of the bounds you give.
There are reasons to use an initial population, especially if there are constraints that might be difficult satisfy, but I do not see the reasoning in this situation?
Christopher Jarrett
on 21 Mar 2021
Edited: Christopher Jarrett
on 21 Mar 2021
What if you needed to run the population of genes(variables) row by row threw a loop that did some calculation with the genes that generates another vector? How could you make it do that?
Walter Roberson
on 21 Mar 2021
You would probably code that through the selection function, mutation function, or crossover function.
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!