MATLAB Answers

link a custom creation function

1 view (last 30 days)
Hello,
i am using optimization toolbox and i want to link m.file that contains my initial population matrix .
% Input Data
M= 1;
I=2;
J = 9;
P_Prop_left = [3200,2690,4500,2900,2300,2000,1000,500,0];
P_EL = [2190,3100,4100,900,2000,2300,125.5,2125.57,82.19];
P_EL_Max = max(P_EL);
P_Prop_max = max(P_Prop_left);
nvars = 30
% Initial values functions
P_mcr_m_Target_initial = (max(P_Prop_left)*1.2) ./ (M.* ones(1,M))
P_mcr_i_Target_initial = (P_EL_Max * 1.1) ./ (I .* ones(1,I))
Ld_left_initial = ( P_Prop_left + (0.5 .* P_EL)) ./ P_mcr_m_Target_initial';
Ld_left_initial (Ld_left_initial > 0.9) = 0.85
Ld_left_initial (Ld_left_initial < 0.25) = 0 % make it Like a constraint later on
Ld_left_initial = reshape (Ld_left_initial', 1, M*J)
P_BTot_initial= P_mcr_m_Target_initial' * Ld_left_initial
PTI_initial = P_Prop_left - ( P_mcr_m_Target_initial * Ld_left_initial) ;
PTO_initial = -1 .* PTI_initial;
PTO_initial(PTO_initial<0) = 0
PTI_initial(PTI_initial<0) = 0
LF_initial = (P_EL - 2 .* PTO_initial + 2 .* PTI_initial ) ./ (I .* P_mcr_i_Target_initial')
LF_initial = reshape( LF_initial', 1, I*J)
% IP Initial Population matrix of size 1x NoOfVariables
IP = [P_mcr_m_Target_initial, P_mcr_i_Target_initial, Ld_left_initial, LF_initial]
my m file returns a matrix of size 1x nvars.
Q1: can i consider this matrix as initial population matrix?
in my understanding, this creates only one individual of the whole population, which may be not enoght. if yes,
Q2: how i create a whole population close to the values returned by the IP .
Q3: and what the differnece between using Initial Population matrix and create a custom population creation function
i suppose to use uniform creation function , or constraint dependant creation function, and use the IP matrix on (initial population) cell on the optimization toolbox

Accepted Answer

Abdolkarim Mohammadi
Abdolkarim Mohammadi on 24 Sep 2020
Edited: Abdolkarim Mohammadi on 25 Sep 2020
1) "If you have a partial initial population, meaning fewer than PopulationSize rows, then the genetic algorithm calls CreationFcn to generate the remaining individuals."
2) You can do it by repeating your individual to make it a matrix, and then add a noise to the elements.
InitialPopulationMatrix = repmat(IP, [PopulationSize,1]);
InitialPopulationMatrix(2:end,:) = InitialPopulationMatrix(2:end,:) + a*randn(PopulationSize-1,nvars);
Where a is the standrad deviation of the random Normal numbers to be added as noise. However, an initial population with low diversity (high similarity between the individuals, low a) increases the chance of ga() getting stuck in local minimum. Initial population should cover the whole landscape, and not concentrating in a small portion of it.
3) ga() calls the creation function to create the intial population matrix. If you provide no initial population, the creation function creates all of the initial population. if you provide an initial population matrix with fewer individuals, ga() will create the rest to have exactly an initial population with PopulationSize individuals. If you provide all of the individuals, creation function does nothing.
  4 Comments
Nourhan Elsayed
Nourhan Elsayed on 27 Sep 2020
yes i found my answer here
InitialPopulationMatrix specifies an initial population for the genetic algorithm. The default value is [], in which case ga uses the default CreationFcn to create an initial population. If you enter a nonempty array in the InitialPopulationMatrix, the array must have no more than PopulationSize rows, and exactly nvars columns, where nvars is the number of variables, the second input to ga or gamultiobj. If you have a partial initial population, meaning fewer than PopulationSize rows, then the genetic algorithm calls CreationFcn to generate the remaining individuals
Thank you

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!