sus.m
来自「matlab的遗传算法的一个工具箱」· M 代码 · 共 41 行
M
41 行
% SUS.M (Stochastic Universal Sampling)%% This function performs selection with STOCHASTIC UNIVERSAL SAMPLING.%% Syntax: NewChrIx = sus(FitnV, Nsel)%% Input parameters:% FitnV - Column vector containing the fitness values of the% individuals in the population.% Nsel - number of individuals to be selected%% Output parameters:% NewChrIx - column vector containing the indexes of the selected% individuals relative to the original population, shuffled.% The new population, ready for mating, can be obtained% by calculating OldChrom(NewChrIx,:).% Author: Hartmut Pohlheim (Carlos Fonseca)% History: 12.12.93 file created% 22.02.94 clean up, commentsfunction NewChrIx = sus(FitnV,Nsel);% Identify the population size (Nind) [Nind,ans] = size(FitnV);% Perform stochastic universal sampling cumfit = cumsum(FitnV); trials = cumfit(Nind) / Nsel * (rand + (0:Nsel-1)'); Mf = cumfit(:, ones(1, Nsel)); Mt = trials(:, ones(1, Nind))'; [NewChrIx, ans] = find(Mt < Mf & [ zeros(1, Nsel); Mf(1:Nind-1, :) ] <= Mt);% Shuffle new population [ans, shuf] = sort(rand(Nsel, 1)); NewChrIx = NewChrIx(shuf);% End of function
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?