✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
为了进一步完善电力市场化的构建以提高电网公司的市场竞争力,短期电力负荷预测对电网的规划以及检修都具有关键的作用。所以要求对短期电力负荷预测进行更深入的研究与探索。对样本数据进行相应的分析处理,对于异常数据进行修正。进行负荷预测还要将不同影响因素的量纲考虑在其中,量纲的不同对最后的预测结果也存在一定的影响,故对样本数据进行归一化处理,以消除不同量纲对短期电力负荷预测结果的影响。当进行负荷预测时,长短期记忆(LSTM)神经网络模型存在的不足是:关键参数主要是依靠研究人员的经验选取的。为了解决此问题,引入麻雀搜索算法(Sparrow Search Algorithm,SSA)对其关键参数进行寻优,找到最优的模型参数。为提高预测精度,本文提出了SSA-CNN-LSTM模型,对CNN-LSTM模型的参数进行优化,从而得到该模型中较好的一组参数,,结果表明SSA-CNN-LSTM模型具有更高的预测精度。
⛄ 部分代码
%_________________________________________________________________________________
% Salp Swarm Algorithm (SSA) source codes version 1.0
%
% Main paper:
% S. Mirjalili, A.H. Gandomi, S.Z. Mirjalili, S. Saremi, H. Faris, S.M. Mirjalili,
% Salp Swarm Algorithm: A bio-inspired optimizer for engineering design problems
% Advances in Engineering Software
% DOI: http://dx.doi.org/10.1016/j.advengsoft.2017.07.002
%____________________________________________________________________________________
function [FoodFitness,FoodPosition,Convergence_curve]=SSA(N,Max_iter,lb,ub,dim,fobj)
if size(ub,1)==1
ub=ones(dim,1)*ub;
lb=ones(dim,1)*lb;
end
Convergence_curve = zeros(1,Max_iter);
%Initialize the positions of salps
SalpPositions=initialization(N,dim,ub,lb);
FoodPosition=zeros(1,dim);
FoodFitness=inf;
%calculate the fitness of initial salps
for i=1:size(SalpPositions,1)
SalpFitness(1,i)=fobj(SalpPositions(i,:));
end
[sorted_salps_fitness,sorted_indexes]=sort(SalpFitness);
for newindex=1:N
Sorted_salps(newindex,:)=SalpPositions(sorted_indexes(newindex),:);
end
FoodPosition=Sorted_salps(1,:);
FoodFitness=sorted_salps_fitness(1);
%Main loop
l=2; % start from the second iteration since the first iteration was dedicated to calculating the fitness of salps
while l<Max_iter+1
c1 = 2*exp(-(4*l/Max_iter)^2); % Eq. (3.2) in the paper
for i=1:size(SalpPositions,1)
SalpPositions= SalpPositions';
if i<=N/2
for j=1:1:dim
c2=rand();
c3=rand();
%%%%%%%%%%%%% % Eq. (3.1) in the paper %%%%%%%%%%%%%%
if c3<0.5
SalpPositions(j,i)=FoodPosition(j)+c1*((ub(j)-lb(j))*c2+lb(j));
else
SalpPositions(j,i)=FoodPosition(j)-c1*((ub(j)-lb(j))*c2+lb(j));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
elseif i>N/2 && i<N+1
point1=SalpPositions(:,i-1);
point2=SalpPositions(:,i);
SalpPositions(:,i)=(point2+point1)/2; % % Eq. (3.4) in the paper
end
SalpPositions= SalpPositions';
end
for i=1:size(SalpPositions,1)
Tp=SalpPositions(i,:)>ub';Tm=SalpPositions(i,:)<lb';SalpPositions(i,:)=(SalpPositions(i,:).*(~(Tp+Tm)))+ub'.*Tp+lb'.*Tm;
SalpFitness(1,i)=fobj(SalpPositions(i,:));
if SalpFitness(1,i)<FoodFitness
FoodPosition=SalpPositions(i,:);
FoodFitness=SalpFitness(1,i);
end
end
Convergence_curve(l)=FoodFitness;
l = l + 1;
end
⛄ 运行结果
⛄ 参考文献
[1]徐先峰, 黄刘洋, 龚美. 基于卷积神经网络与双向长短时记忆网络组合模型的短时交通流预测[J]. 工业仪表与自动化装置, 2020.
[2]姜南林. 基于改进麻雀搜索算法优化长短期记忆网络的短期电力负荷预测研究.