|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
#技术风云榜#基于非支配排序的多目标PSO算法MATLAB实现) q' D, {, ]1 j
/ v( ^8 b( b: i! t/ E
这一篇是Xue Bing在一区cybernetics发的论文,里面提出了两个多目标PSO特征选择算法,一个是NSPSO另一个是CMDPSO。
' A' Z% [6 h/ S' d Z Q& f+ ~
: }8 t) V4 W( O6 ?伪代码
1 [3 a* w! o c# `# t% q/ h
7 Y2 @4 Z& r. }0 o0 {& a
6 r1 u. |! o8 Q, F9 D
( X$ {3 @# y+ {
, D4 x% i& K$ E9 C$ P E2 Y具体流程( ?- ^: I5 I* y9 n7 ^
- ①划分数据集为测试集和训练集
- ②初始化PSO算法
- ③迭代开始
- ④计算两个目标值(论文中是特征数和错误率)
- ⑤非支配排序
- ⑥拥挤距离度量并排序
- ⑥对每个粒子从第一前沿面选择一个粒子作为gbest,更新当前粒子
- ⑦调整粒子群
- ⑧迭代结束返回
* F3 F$ C# S! H/ j2 e
/ ~9 d+ {* u1 g; r) g7 ^8 V7 I9 ~MATLAB实现:6 H; n3 ]& z( U5 G7 G* ^$ @- N
NSPSO:8 T! ?+ ~: }. e7 F4 T
- |& i5 }9 E- K
注意其中FSKNN是我的问题的评价函数,包含两个目标值,都存入到pfitness中
+ _" j }, D, G# e0 O. F2 U6 i% H
- function [solution,time,pop,pfitness,site,LeaderAVE] = NSPSO(train_F,train_L)
- tic
- global maxFES
- dim = size(train_F,2);
- FES = 1;
- sizep = 30;
- pop = rand(sizep,dim);
- popv = rand(sizep,dim);
- pfitness = zeros(sizep,2);
- LeaderAVE = zeros(1,2);
- while FES <maxFES
- Off_P = zeros(sizep,dim);
- Off_V = zeros(sizep,dim);
- ofitness = zeros(sizep,2);
- for i=1:sizep
- [pfitness(i,1),pfitness(i,2)] = FSKNN(pop(i,:),i,train_F,train_L);
- end
- Front = NDSort(pfitness(:,1:2),sizep);
- [~,rank] = sortrows([Front',-CrowdingDistance(pfitness,Front)']);
- LeaderSet = rank(1:10);
- solution = pfitness(LeaderSet,:);
- LeaderAVE(1) = mean(solution(:,1));
- LeaderAVE(2) = mean(solution(:,2));
- for i = 1:sizep
- good = LeaderSet(randperm(length(LeaderSet),1));
- r1 = rand(1,dim);
- r2 = rand(1,dim);
- Off_V(i,:) = r1.*popv(i,:) + r2.*(pop(good,:)-pop(i,:));
- Off_P(i,:) = pop(i,:) + Off_V(i,:);
- end
- for i=1:sizep
- [ofitness(i,1),ofitness(i,2)] = FSKNN(Off_P(i,:),i,train_F,train_L);
- end
- temppop = [pop;Off_P];
- tempv = [popv;Off_V];
- tempfiness = [pfitness;ofitness];
- [FrontNO,MaxFNO] = NDSort(tempfiness(:,1:2),sizep);
- Next = false(1,length(FrontNO));
- Next(FrontNO<MaxFNO) = true;
- PopObj = tempfiness;
- fmax = max(PopObj(FrontNO==1,:),[],1);
- fmin = min(PopObj(FrontNO==1,:),[],1);
- PopObj = (PopObj-repmat(fmin,size(PopObj,1),1))./repmat(fmax-fmin,size(PopObj,1),1);
- % Select the solutions in the last front
- Last = find(FrontNO==MaxFNO);
- del = Truncation(PopObj(Last,:),length(Last)-sizep+sum(Next));
- Next(Last(~del)) = true;
- % Population for next generation
- pop = temppop(Next,:);
- popv = tempv(Next,:);
- pfitness = tempfiness(Next,:);
- fprintf('GEN: %2d Error: %.4f F:%.2f\n',FES,LeaderAVE(1),LeaderAVE(2));
- FES = FES + 1;
- end
- [FrontNO,~] = NDSort(pfitness(:,1:2),sizep);
- site = find(FrontNO==1);
- solution = pfitness(site,:);
- LeaderAVE(1) = mean(solution(:,1));
- LeaderAVE(2) = mean(solution(:,2));
- toc
- time = toc;
- end
8 r4 D& P2 E* M0 ?! b2 v
/ o& k5 |4 c1 {6 l9 {2 i% a6 D7 l7 A% n! e+ {4 O# e+ R0 L
拥挤距离代码:
! A8 \% |/ h' M2 t+ t! B/ G7 I
2 f+ P* S& p9 M8 ~( A- function CrowdDis = CrowdingDistance(PopObj,FrontNO)
- % Calculate the crowding distance of each solution front by front
- % Copyright 2015-2016 Ye Tian
- [N,M] = size(PopObj);
- CrowdDis = zeros(1,N);
- Fronts = setdiff(unique(FrontNO),inf);
- for f = 1 : length(Fronts)
- Front = find(FrontNO==Fronts(f));
- Fmax = max(PopObj(Front,:),[],1);
- Fmin = min(PopObj(Front,:),[],1);
- for i = 1 : M
- [~,Rank] = sortrows(PopObj(Front,i));
- CrowdDis(Front(Rank(1))) = inf;
- CrowdDis(Front(Rank(end))) = inf;
- for j = 2 : length(Front)-1
- CrowdDis(Front(Rank(j))) = CrowdDis(Front(Rank(j)))+(PopObj(Front(Rank(j+1)),i)-PopObj(Front(Rank(j-1)),i))/(Fmax(i)-Fmin(i));
- end
- end
- end
- end$ }# W# b5 B) i, x) q
; O8 T$ Y& h: d' ^7 ?* B0 G' O8 C8 Z2 ~
Truncation.m代码:; i9 t5 U0 t/ V
/ w& D9 B$ v- q! a5 n5 A, X
- function Del = Truncation(PopObj,K)
- % Select part of the solutions by truncation
- N = size(PopObj,1);
- %% Truncation
- Distance = pdist2(PopObj,PopObj);
- Distance(logical(eye(length(Distance)))) = inf;
- Del = false(1,N);
- while sum(Del) < K
- Remain = find(~Del);
- Temp = sort(Distance(Remain,Remain),2);
- [~,Rank] = sortrows(Temp);
- Del(Remain(Rank(1))) = true;
- end
- end
/ ?% Z4 d; Y, |; ]) y% g( i
: v! t" q- O8 k/ V0 N
6 p8 S8 L8 Y8 i4 L ( K$ m' i! n' Y0 _* t0 c
|
|