⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 normlinearselect.sci

📁 基于SCILAB的The Genetic Algorithm Toolbox for SCILAB (GATS)工具箱
💻 SCI
字号:
function[newPop] = normLinearSelect(oldPop,options)
// NormGeomSelect is a ranking selection function based on the normalized
// geometric distribution.  
//
// function[newPop] = normLinearSelect(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(1); 				// Probability of selecting the best
e = size(oldPop,2); 			// Length of xZome, i.e. numvars+fit
n = size(oldPop,1); 			// Number of individuals in pop
newPop = zeros(n,e); 			// Allocate space for return pop
fit = zeros(n,1); 			// Allocates space for prob of select
x=zeros(n,2); 			        // Sorted list of rank and id
x(:,1) =[n:-1:1]'; 			// To know what element it was
[y x(:,2)] = gsort(oldPop(:,e),'g','i'); 	// Get the index after a sort
r = 2-q; 			                    // Normalize the distribution, q prime
fit(x(:,2))=(q-(q-r)*(x(:,1)-1)./(n-1))/n; 	// Generates Prob of selection 
fit = cumsum(fit); 			// Calculate the cumulative prob. func
rNums=gsort(rand(n,1),'g','i'); 	// Generate n sorted random numbers
fitIn=1; newIn=1; 			// Initialize loop control
while 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
  end
end

⌨️ 快捷键说明

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