matlab多目标优先顺序,基于非支配排序的多目标PSO算法MATLAB实现

本文介绍了一种名为NSPSO (粒子群优化)的搜索算法,用于解决训练问题。通过迭代更新种群和个体位置,算法在给定的训练数据(train_F, train_L)中寻找最优解。它涉及群体行为、局部搜索和全局搜索策略,最终输出的是平均误差和最佳解决方案。
摘要由CSDN通过智能技术生成

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值