-
Notifications
You must be signed in to change notification settings - Fork 33
/
sus.m
40 lines (34 loc) · 1.31 KB
/
sus.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% 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, comments
% 22.01.03 tested under MATLAB v6 by Alex Shenfield
function 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