-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathselect.m
35 lines (35 loc) · 1.04 KB
/
select.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
function ret=select(individuals,sizepop)
% 该函数用于进行选择操作
% individuals input 种群信息
% sizepop input 种群规模
% ret output 选择后的新种群
%求适应度值倒数
[a bestch]=min(individuals.fitness);
%b=individuals.chrom(bestch);
%c=individuals.fitness(bestch);
fitness1=10./individuals.fitness; %individuals.fitness为个体适应度值
%个体选择概率
sumfitness=sum(fitness1);
sumf=fitness1./sumfitness;
%采用轮盘赌法选择新个体
index=[];
for i=1:sizepop %sizepop为种群数
pick=rand;
while pick==0
pick=rand;
end
for i=1:sizepop
pick=pick-sumf(i);
if pick<0
index=[index i];
break;
end
end
end
%index=[index bestch];
%新种群
individuals.chrom=individuals.chrom(index,:); %individuals.chrom为种群中个体
individuals.fitness=individuals.fitness(index);
%individuals.chrom=[individuals.chrom;b];
%individuals.fitness=[individuals.fitness;c];
ret=individuals;%出售各类算法优化深度极限学习机代码392503054