normgeomselect.m

来自「实数编码的遗传算法」· M 代码 · 共 32 行

M
32
字号
function[newPop] = normGeomSelect(oldPop,options)% NormGeomSelect is a ranking selection function based on the normalized% geometric distribution.  %% function[newPop] = normGeomSelect(oldPop,options)% newPop  - the new population selected from the oldPop% oldPop  - the current population% options - options to normGeomSelect [gen probability_of_selecting_best]q=options(2); 				% Probability of selecting the beste = size(oldPop,2); 			% Length of xZome, i.e. numvars+fitn = size(oldPop,1); 			% Number of individuals in popnewPop = zeros(n,e); 			% Allocate space for return popfit = zeros(n,1); 			% Allocates space for prob of selectx=zeros(n,2); 			        % Sorted list of rank and idx(:,1) =[n:-1:1]'; 			% To know what element it was[y x(:,2)] = sort(oldPop(:,e)); 	% Get the index after a sortr = q/(1-(1-q)^n); 			% Normalize the distribution, q primefit(x(:,2))=r*(1-q).^(x(:,1)-1); 	% Generates Prob of selection fit = cumsum(fit); 			% Calculate the cumulative prob. funcrNums=sort(rand(n,1)); 			% Generate n sorted random numbersfitIn=1; newIn=1; 			% Initialize loop controlwhile newIn<=n 				% Get n new individuals  if(rNums(newIn)<fit(fitIn)) 		    newPop(newIn,:) = oldPop(fitIn,:); 	% Select the fitIn individual     newIn = newIn+1; 			% Looking for next new individual  else    fitIn = fitIn + 1; 			% Looking at next potential selection  endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?