Press "Enter" to skip to content

【预测模型-ELAMN预测】基于蝗虫算法优化ELMAN神经网络实现数据回归预测matlab代码

本站内容均来自兴趣收集,如不慎侵害的您的相关权益,请留言告知,我们将尽快删除.谢谢.

1 简介

 

风能,作为一种重要,有潜力,无污染,可再生、可持续的能源,已经成为全球发电最为迅速的能源之一,越来越受到世界各国的青睐。近年来,为缓解能源短缺问题,改善环境,实现经济乃至人类的可持续发展,世界各国纷纷大力发展风能资源。然而,在实际操作中,风能固有的波动性和间歇性通常会增加风能入网的难度,致使风电场输出功率不稳定,严重影响输出的电能质量,大大增加了电网安全性和稳定性运行风险,因此,风速预测在风电相关工作中至关重要,准确、可靠的预测结果不仅有利于调度人员事先掌握风电场的功率变化情况,及时制定调度运行计划,提高能量转换效率、降低风险,增加发电量等,同时也有利于风电并网稳定运行和有效消纳,对可能存在影响电网安全稳定运行的风险及时预警,从而避免风电功率随机波动造成电能损耗甚至电网崩溃。近年来,国内外学者进行了大量风速预测相关研究,风速预测水平得到一定程度的提升。单一预测模型虽简单容易实施,但其预测精度往往较低,难以满足风电场发电的需求。相比之下,基于优化算法和数据分解法的混合预测模型对风速预测性能有很大的提升。然而,现有的模型只是使用单目标优化算法,针对预测模型精度的提高,很少关注预测结果稳定性的增强,涉及多目标优化算法的混合预测模型更是少之又少。因此,这些模型往往会降低预测结果的稳定性,对风电场发电以及风电并网的安全性和稳定性带来巨大的挑战。针对如上问题,本文构建出一个基于蝗虫算法和Elman神经网络的混合预测模型,本文所提出的混合预测模型不仅可以降低预测误差,提高风速预测精度,增强预测结果的稳定性,同时对风电场发电的完善,发展以及风电并网安全管理也大有裨益。

 

Elman 神经网络是一种局部反馈递归神经网络,包括输入层、隐藏层、承接层和输出层,由于其良好的动态记忆和时变能力,自1990年Elman首次提出以来,Elman神经网络在时间序列预测中得到了广泛的应用,但由于随机选择初始值和阈值,且采用梯度下降法寻优,其网络学习速度较慢且预测的精度比较低。本文利用 GOA 优化 Elman神经网络的初始权值及阈值,提高了 Elman 神经网络的预测精度。

 

第一步 初始化 Elman 网络所需参数,并新建 Elman 网 络,net=newelm(minmax(input),[11,1],{’tansig’,’purelin’},’traingdx’),其中 input 是训练集数据,tansig 是隐藏层的激活函数,purelin是输出层激活函数,traingdx是梯度下降函数;

 

第二步 初始化GOA各参数,包括蝗虫的数量m 、最大迭代次数Maxiter,参数的上界ub及下界lb;

 

第三步不断迭代蝗虫位置优化网络,直到迭代结束形成最优个体,其中最优个体包括权值w1、w2及w3,阈值b1和b2;

 

第四步 Elman 神经网络解析最优个体,利用解析后的权值及阈值训练Elman神经网络并预测风速数据。

 

2 部分代码

 

% The Grasshopper Optimization Algorithm

 

function [TargetFitness,TargetPosition,Convergence_curve,Trajectories,fitness_history, position_history]=GOA(N, Max_iter, lb,ub, dim, fobj)

 

tic

 

disp(‘GOA is now estimating the global optimum for your problem….’)

 

flag=0;

 

if size(ub,1)==1

 

ub=ones(dim,1)*ub;

 

lb=ones(dim,1)*lb;

 

end

 

if (rem(dim,2)~=0) % this algorithm should be run with a even number of variables. This line is to handle odd number of variables

 

dim = dim+1;

 

ub = [ub; 100];

 

lb = [lb; -100];

 

flag=1;

 

end

 

%Initialize the population of grasshoppers

 

GrassHopperPositions=initialization(N,dim,ub,lb);

 

GrassHopperFitness = zeros(1,N);

 

fitness_history=zeros(N,Max_iter);

 

position_history=zeros(N,Max_iter,dim);

 

Convergence_curve=zeros(1,Max_iter);

 

Trajectories=zeros(N,Max_iter);

 

cMax=1;

 

cMin=0.00004;

 

%Calculate the fitness of initial grasshoppers

 

for i=1:size(GrassHopperPositions,1)

 

if flag == 1

 

GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,1:end-1));

 

else

 

GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,:));

 

end

 

fitness_history(i,1)=GrassHopperFitness(1,i);

 

position_history(i,1,:)=GrassHopperPositions(i,:);

 

Trajectories(:,1)=GrassHopperPositions(:,1);

 

end

 

[sorted_fitness,sorted_indexes]=sort(GrassHopperFitness);

 

% Find the best grasshopper (target) in the first population

 

for newindex=1:N

 

Sorted_grasshopper(newindex,:)=GrassHopperPositions(sorted_indexes(newindex),:);

 

end

 

TargetPosition=Sorted_grasshopper(1,:);

 

TargetFitness=sorted_fitness(1);

 

% Main loop

 

l=2; % Start from the second iteration since the first iteration was dedicated to calculating the fitness of antlions

 

while l<Max_iter+1

 

c=cMax-l*((cMax-cMin)/Max_iter); % Eq. (2.8) in the paper

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

for i=1:size(GrassHopperPositions,1)

 

temp= GrassHopperPositions’;

 

% for k=1:2:dim

 

S_i=zeros(dim,1);

 

for j=1:N

 

if i~=j

 

Dist=distance(temp(:,j), temp(:,i)); % Calculate the distance between two grasshoppers

 

r_ij_vec=(temp(:,j)-temp(:,i))/(Dist+eps); % xj-xi/dij in Eq. (2.7)

 

xj_xi=2+rem(Dist,2); % |xjd – xid| in Eq. (2.7)

 

s_ij=((ub – lb)*c/2)*S_func(xj_xi).*r_ij_vec; % The first part inside the big bracket in Eq. (2.7)

 

S_i=S_i+s_ij;

 

end

 

end

 

S_i_total = S_i;

 

% end

 

X_new = c * S_i_total’+ (TargetPosition); % Eq. (2.7) in the paper

 

GrassHopperPositions_temp(i,:)=X_new’;

 

end

 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

% GrassHopperPositions

 

GrassHopperPositions=GrassHopperPositions_temp;

 

for i=1:size(GrassHopperPositions,1)

 

% Relocate grasshoppers that go outside the search space

 

Tp=GrassHopperPositions(i,:)>ub’;Tm=GrassHopperPositions(i,:)<lb’;GrassHopperPositions(i,:)=(GrassHopperPositions(i,:).*(~(Tp+Tm)))+ub’.*Tp+lb’.*Tm;

 

% Calculating the objective values for all grasshoppers

 

if flag == 1

 

GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,1:end-1));

 

else

 

GrassHopperFitness(1,i)=fobj(GrassHopperPositions(i,:));

 

end

 

fitness_history(i,l)=GrassHopperFitness(1,i);

 

position_history(i,l,:)=GrassHopperPositions(i,:);

 

Trajectories(:,l)=GrassHopperPositions(:,1);

 

% Update the target

 

if GrassHopperFitness(1,i)<TargetFitness

 

TargetPosition=GrassHopperPositions(i,:);

 

TargetFitness=GrassHopperFitness(1,i);

 

end

 

end

 

Convergence_curve(l)=TargetFitness;

 

disp([‘In iteration #’, num2str(l), ‘ , target”s objective = ‘, num2str(TargetFitness)])

 

l = l + 1;

 

end

 

if (flag==1)

 

TargetPosition = TargetPosition(1:dim-1);

 

end

 

time=toc

 

3 仿真结果

 

 

 

 

4 参考文献

 

[1]朱昶胜, 康亮河, and 冯文芳. “基于自适应鲸鱼优化算法结合Elman神经网络的股市收盘价预测算法.” 计算机应用 40.5(2020):9.

 

[2]江远强. “一种基于蝗虫算法优化MLP神经网络的信用风险预测方法.”.

 

 

Be First to Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注