?作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
智能优化算法 ?神经网络预测 雷达通信 无线传感器
信号处理 图像处理 路径规划 元胞自动机 无人机
? 内容介绍
人工神经网络的最大缺点是训练时间太长从而限制其实时应用范围,近年来,极限学习机(Extreme Learning Machine, ELM)的提出使得前馈神经网络的训练时间大大缩短,然而当原始数据混杂入大量噪声变量时,或者当输入数据维度非常高时,极限学习机算法的综合性能会受到很大的影响.深度学习算法的核心是特征映射,它能够摒除原始数据中的噪声,并且当向低维度空间进行映射时,能够很好的起到对数据降维的作用,因此我们思考利用深度学习的优势特性来弥补极限学习机的弱势特性从而改善极限学习机的性能.为了进一步提升DELM预测精度,本文采用人工蜂群算法进一步优化DELM超参数,仿真结果表明,改进算法的预测精度更高。





? 部分代码
clc;
clear;
close all;
%% Problem Definition
CostFunction=@(x) Sphere(x);? ? ? ? % Cost Function
nVar=5;? ? ? ? ? ? ?% Number of Decision Variables
VarSize=[1 nVar];? ?% Decision Variables Matrix Size
VarMin=-10;? ? ? ? ?% Decision Variables Lower Bound
VarMax= 10;? ? ? ? ?% Decision Variables Upper Bound
%% ABC Settings
MaxIt=200;? ? ? ? ? ? ? % Maximum Number of Iterations
nPop=100;? ? ? ? ? ? ? ?% Population Size (Colony Size)
nOnlooker=nPop;? ? ? ? ?% Number of Onlooker Bees
L=round(0.6*nVar*nPop); % Abandonment Limit Parameter (Trial Limit)
a=1;? ? ? ? ? ? ? ? ? ? % Acceleration Coefficient Upper Bound
%% Initialization
% Empty Bee Structure
empty_bee.Position=[];
empty_bee.Cost=[];
% Initialize Population Array
pop=repmat(empty_bee,nPop,1);
% Initialize Best Solution Ever Found
BestSol.Cost=inf;
% Create Initial Population
for i=1:nPop
? ? pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
? ? pop(i).Cost=CostFunction(pop(i).Position);
? ? if pop(i).Cost<=BestSol.Cost
? ? ? ? BestSol=pop(i);
? ? end
end
% Abandonment Counter
C=zeros(nPop,1);
% Array to Hold Best Cost Values
BestCost=zeros(MaxIt,1);
%% ABC Main Loop
for it=1:MaxIt
? ??
? ? % Recruited Bees
? ? for i=1:nPop
? ? ? ??
? ? ? ? % Choose k randomly, not equal to i
? ? ? ? K=[1:i-1 i+1:nPop];
? ? ? ? k=K(randi([1 numel(K)]));
? ? ? ??
? ? ? ? % Define Acceleration Coeff.
? ? ? ? phi=a*unifrnd(-1,+1,VarSize);
? ? ? ??
? ? ? ? % New Bee Position
? ? ? ? newbee.Position=pop(i).Position+phi.*(pop(i).Position-pop(k).Position);
? ? ? ??
? ? ? ? % Evaluation
? ? ? ? newbee.Cost=CostFunction(newbee.Position);
? ? ? ??
? ? ? ? % Comparision
? ? ? ? if newbee.Cost<=pop(i).Cost
? ? ? ? ? ? pop(i)=newbee;
? ? ? ? else
? ? ? ? ? ? C(i)=C(i)+1;
? ? ? ? end
? ? ? ??
? ? end
? ??
? ? % Calculate Fitness Values and Selection Probabilities
? ? F=zeros(nPop,1);
? ? MeanCost = mean([pop.Cost]);
? ? for i=1:nPop
? ? ? ? F(i) = exp(-pop(i).Cost/MeanCost); % Convert Cost to Fitness
? ? end
? ? P=F/sum(F);
? ??
? ? % Onlooker Bees
? ? for m=1:nOnlooker
? ? ? ??
? ? ? ? % Select Source Site
? ? ? ? i=RouletteWheelSelection(P);
? ? ? ??
? ? ? ? % Choose k randomly, not equal to i
? ? ? ? K=[1:i-1 i+1:nPop];
? ? ? ? k=K(randi([1 numel(K)]));
? ? ? ??
? ? ? ? % Define Acceleration Coeff.
? ? ? ? phi=a*unifrnd(-1,+1,VarSize);
? ? ? ??
? ? ? ? % New Bee Position
? ? ? ? newbee.Position=pop(i).Position+phi.*(pop(i).Position-pop(k).Position);
? ? ? ??
? ? ? ? % Evaluation
? ? ? ? newbee.Cost=CostFunction(newbee.Position);
? ? ? ??
? ? ? ? % Comparision
? ? ? ? if newbee.Cost<=pop(i).Cost
? ? ? ? ? ? pop(i)=newbee;
? ? ? ? else
? ? ? ? ? ? C(i)=C(i)+1;
? ? ? ? end
? ? ? ??
? ? end
? ??
? ? % Scout Bees
? ? for i=1:nPop
? ? ? ? if C(i)>=L
? ? ? ? ? ? pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
? ? ? ? ? ? pop(i).Cost=CostFunction(pop(i).Position);
? ? ? ? ? ? C(i)=0;
? ? ? ? end
? ? end
? ??
? ? % Update Best Solution Ever Found
? ? for i=1:nPop
? ? ? ? if pop(i).Cost<=BestSol.Cost
? ? ? ? ? ? BestSol=pop(i);
? ? ? ? end
? ? end
? ??
? ? % Store Best Cost Ever Found
? ? BestCost(it)=BestSol.Cost;
? ??
? ? % Display Iteration Information
? ? disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]);
? ??
end
? ??
%% Results
figure;
%plot(BestCost,'LineWidth',2);
semilogy(BestCost,'LineWidth',2);
xlabel('Iteration');
ylabel('Best Cost');
grid on;
img =gcf;? %获取当前画图的句柄
print(img, '-dpng', '-r600', './运行结果.png')? ? ? ? ?%即可得到对应格式和期望dpi的图像
? 运行结果



? 参考文献
[1]吴强,卢雪琴忠,何怡林,等。基于鲸鱼算法优化极限学习机的微电网故障诊断方法[J]. 智慧电力, 2022, 50(2):7.
?? 关注我领取海量matlab电子书和数学建模资料
??部分理论引用网络文献,若有侵权联系博主删除