✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

⛄ 内容介绍

一种基于灰狼算法优化LSTM的网络流量预测方法,属于网络流量预测领域,该方法包括以下步骤:对第一网络流量数据集进行极差标准化处理,得到第二网络流量数据集,并划分为训练集和测试集,并确定灰狼算法优化LSTM神经网络中输入层单元个数,输出层单元个数和隐藏层单元个数;用得到第二网络流量数据集,在过程中利用灰狼算法来优化LSTM神经网络的参数,得到训练完成的决策算法优化LSTM神经网络;灰狼优化算法可以有效解决优化中的求解问题,可应用于工程,经济,调度等问题求解.灰狼优化算法利用自身的全局最优能力弥补传统LSTM容易收敛于局部最优解的缺点,提高LSTM避免局部最优能力;加快LSTM神经网络参数收速度.实验证明,灰狼算法优化LSTM能够有效减少神经网络的训练时间,提高了股价预测精度.

LSTM 是循环神经网络中的一个特殊网络,它能够很好的处理序列信息并从中学习有效特征,它把以往的神经单元用一个记忆单元( memory cell) 来代替,解决了以往循环神经网络在梯度反向传播中遇到的爆炸和衰减问题. 一个记忆单元利用了输入门 it、一个记忆细胞 ct、一个忘记门 ft、一个输出门 ot 来控制历史信息的储存记忆,在每次输入后会有一个当前状态 ht,ht 计算如下:

时序预测 | MATLAB实现GWO-LSTM灰狼算法优化长短期记忆神经网络时间序列预测_神经网络

时序预测 | MATLAB实现GWO-LSTM灰狼算法优化长短期记忆神经网络时间序列预测_hg_02

其中,xt 为 t 时刻输入的情感词向量,σ 为 sigmoid 函数, 代表向量对应元素依次相乘,其中水电费 Wi,Ui,Vi,bi, Wg,Ug,bg,Wo,Uo,Vo,bo 为 LSTM 参数.

时序预测 | MATLAB实现GWO-LSTM灰狼算法优化长短期记忆神经网络时间序列预测_算法优化_03

时序预测 | MATLAB实现GWO-LSTM灰狼算法优化长短期记忆神经网络时间序列预测_算法优化_04

⛄ 部分代码

clc

clear all

close all hidden

disp('****************************ANTENNA DIPOLE PROJECT******************************')

disp('                             farshid.azhir                                  ')

disp('NOTICE!:This project includes 3type of dipole 1)INFINITESIMALE DIPOLE') 

disp('                                              2)SMALL DIPOLE')

disp('                                              3)FINIT LENGHT DIPOLE')

F=input('Please Enter Frequency F(Hz)=\n');

disp('----------------')

lambda=(3e8/F)

disp('----------------')

L=input('Please Enter length L(meter)=\n');

disp('----------------')

I=input('Please Enter Current(Amplitude) I0=');

T=input('Please Enter current(Phase) theta=');

i=I.*exp(j.*T)

disp('              ')

w=2.*pi.*F;

B=2*pi/lambda;

etha=377;

if L<=lambda/50

    disp('~~~~~~~~~~~~~~~~~~~~~~~INFINITESIMALE DIPOLE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

r=1000*lambda/(2*pi);

x=0:0.0005:pi;

q=0:0.001:2*pi;

E=(1./(4.*pi.*r)).*etha.*B.*I.*L.*sin(x).*cos((2.*pi.*F).*q-B.*r+pi./2+T);

subplot(2,2,1)

plot(x,E)

title('Electric Field')

H=(1./(4.*pi.*r)).*B.*I.*L.*sin(x).*cos((2.*pi.*F).*q-B.*r+pi./2+T);

subplot(2,2,2)

plot(x,H)

title('Magnetic Field')

subplot(2,2,3)

P=sin(x);

polar(x,P)

hold on

p=sin(-x);

polar(x,p)

view(-270,-90)

title('Antenna pattern')

disp('**************************  Resistance density(Rr)=   ***************************')

Rr=80.*(pi).*(pi).*(L/lambda)^2

disp('**************************  Directivity=  ****************************************')

D=3/2

%current plot

subplot(2,2,4)

z=-L/2:0.001:L/2;

ii=I.*cos(2.*pi.*F.*z+T);

plot(ii,z)

title('Current distribution')

figure

% 1.- 3-D Mesh: Azimut & Elevation 

%---------------------------------- 

n_tehta = 130; % Samples on Elevation 

n_phi = 130; % Samples on Azimut 

[tehta,phi]=meshgrid(eps:pi./(n_tehta-1):pi,... 

            0:2*pi./(n_phi-1):2*pi) ; 

radio = sin(tehta); 

X=radio.*sin(tehta).*cos(phi); 

Y=radio.*sin(tehta).*sin(phi); 

Z=radio.*cos(tehta); 

surf(X,Y,Z)

camlight right

light

shading interp

colorbar

axis image 

rotate3D on

TITLE('3D-Pattern plot')

elseif (L>lambda/50)&(L<=lambda/10)

    %SMALL DIPOLE

    %CALCULATE-------------------------------------------------------

  disp('~~~~~~~~~~~~~~~~~~SMALL DIPOLE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

r=1000*lambda/(2*pi);

x=0:0.0005:pi;

q=0:0.001:2*pi;

E=(1./(8.*pi.*r)).*etha.*B.*I.*L.*sin(x).*cos(((w).*q)-B.*r+pi./2+T);

subplot(2,2,1)

plot(x,E)

title('Electric Field')

H=(1./(8.*pi.*r)).*B.*I.*L.*sin(x).*cos(((w).*q)-B.*r+pi./2+T);

subplot(2,2,2)

plot(x,H)

title('Magnetic Field')

subplot(2,2,3)

P=sin(x);

polar(x,P)

hold on

p=sin(-x);

polar(x,p)

view(-270,-90)

title('Antenna pattern')

disp('**************************  Resistance density(Rr)=   ***************************')

Rr=20.*(pi).*(pi).*(L/lambda).^2

disp('**************************  Directivity=  ****************************************')

D=3/2

subplot(2,2,4)

z=0:0.000001:L/2;

ii=I.*cos(2.*pi.*F.*z+T).*(1-(2/L).*z);

plot(ii,z)

hold on

z=-L/2:0.000001:0;

ii=I.*cos(2.*pi.*F.*z+T).*(1+(2/L).*z);

plot(ii,z)

figure

% 1.- 3-D Mesh: Azimut & Elevation 

n_tehta = 130; % Samples on Elevation 

n_phi = 130; % Samples on Azimut 

[tehta,phi]=meshgrid(eps:pi./(n_tehta-1):pi,... 

            0:2*pi./(n_phi-1):2*pi) ; 

radio = sin(tehta); 

X=radio.*sin(tehta).*cos(phi); 

Y=radio.*sin(tehta).*sin(phi); 

Z=radio.*cos(tehta); 

surf(X,Y,Z)

camlight right

light

shading interp

colorbar

axis image 

rotate3D on

TITLE('3D-Pattern plot')

else

    disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~FINITE LENGTH DIPOLE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

       r=1000000*lambda/(2*pi);

x=eps:0.001:2*pi;

q=eps:0.001:2*pi;

A=cos(B.*L/2);

p=cos(cos(x).*B.*L/2)-A;

m=p./sin(x);

E=(1./(2.*pi.*r)).*etha.*B.*I.*L.*m.*cos(((w).*q)-B.*r+pi./2+T);

subplot(2,3,1)

plot(x,E)

title('Electric Field')

H=(1./(2.*pi.*r)).*B.*I.*L.*m.*cos(((w).*q)-B.*r+pi./2+T);

subplot(2,3,2)

plot(x,H)

title('Magnetic Field')

subplot(2,3,3)

polar(x,m,'r')

hold on

m=-p./sin(x);

polar(x,m,'r')

view(-270,-90)

title('Antenna pattern')

subplot(2,3,4)

z=0:0.00001:L/2;

ii=I.*cos((w).*z+T).*(sin(B.*(-z+L/2)));

plot(ii,z)

hold on

z=-L/2:0.00001:0;

ii=I.*cos((w).*z+T).*(sin(B.*(z+L/2)));

plot(ii,z)

grid on

title('Current Distribution')

disp('**************************  Resistance density(Rr)=   ***************************')

rr=(0.5772+log(B*L))-cosint(B*L);

ro=rr+(1/2).*sin(B*L)*(sinint(2*B*L)-2*sinint(B*L));

Q=ro+(1/2).*cos(B*L)*(0.5772+log(B*L/2)+cosint(2*B*L)-2*cosint(B*L));

Rr=(etha/(2*pi)).*Q

subplot(2,3,5)

D=2.*(m.^2)./Q;

polar(x,D,'k')

view(-270,-90)

title('Directivity')

figure

% 1.- 3-D Mesh: Azimut & Elevation 

n_tehta = 130; % Samples on Elevation 

n_phi = 130; % Samples on Azimut 

[tehta,phi]=meshgrid(eps:pi./(n_tehta-1):pi,... 

            0:2*pi./(n_phi-1):2*pi) ; 

Bas = L/lambda; % Half Wave Dipole 

Num = cos(pi*Bas*cos(tehta))-cos(pi*Bas); 

Den = sin(tehta); 

radio = Num./Den; 

X=radio.*sin(tehta).*cos(phi); 

Y=radio.*sin(tehta).*sin(phi); 

Z=radio.*cos(tehta); 

surf(X,Y,Z)

camlight right

light

shading interp

colorbar

axis image 

rotate3D on

TITLE('3D-Pattern plot')

end

disp('          ')

disp('press any key to go to manipulation of feeder section')

pause

%-------------------manipulation of feeder--------

clc

close all hidden

disp('....................................change posision of feeder...........................')

f=input('Enter Frequency:\n'); 

 disp('------------------------------------------------------------')

  lambda=3e8/f

 disp('------------------------------------------------------------')

  L=input('Enter L(length of dipole:\n');

 disp('Please enter any key to continue...')

 pause

 disp('------------------------------------------------------------')

 disp('L/2')

 L/2

 disp('------------------------------------------------------------') 

 i=input('current:\n');

 b=2*pi/lambda;

  n=L/(lambda/2);

  if n<=1;

    disp('dipole antenna is lambda/2 or smaller ')

    disp('---------------------------------------')

    h=input('position of feeder,posision must be 0<position<L/2 or -L/2<position<0\n--->');

if (h>L/2)|(h<-L/2)

    error('you enter position feeder greater than Length of dipole')

    return

end

disp('              ')

disp('Rradiational when change posision feeder=')

Rr_new=Rr./((sin(B.*((L/2)-h))).^2) 

Rr_old=Rr

xp=h;

yp=-i:0.00001:-i+(i/100);

plot(yp,xp,'dr')

hold on

x=-L/2:0.01:L/2;

y=i*sin(b*((L/2)-(x+h)));

plot(y,x)

grid on

elseif n==2;

     disp('Length dipole antenna is lambda ')

    disp('---------------------------------------')

        h=input('position of feeder,posision must be 0<position<L/2 or -L/2<position<0\n--->');

if (h>L/2)|(h<-L/2)

    error('you enter position feeder greater than Length of dipole')

    return

end

disp('              ')

disp('Rradiational when change posision feeder=')

Rr_new=Rr./((sin(B.*((L/2)-h))).^2) 

Rr_old=Rr

xp=h;

yp=-i:0.001:-i+(i/100);

plot(yp,xp,'sr')

hold on

grid on

if h==0

  x=0:0.01:L/2;

y=i*sin(b*((L/2)-(x+h)));

plot(y,x)

hold on

x=-L/2:0.01:0;

y=i*sin(b*((L/2)+(x+h)));

plot(y,x)

grid on  

elseif h>0    

x=0:0.01:L/2;

y=i*sin(b*((L/2)-(x+h)));

plot(y,x)

hold on

x=-L/2:0.01:0;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

grid on

else

 x=-L/2:0.01:0;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

hold on

x=0:0.01:L/2;

y=i*sin(b*((L/2)+(x+h)));

plot(y,x)

grid on

end

elseif n==3;

       disp('Length dipole antenna is 3*lambda/2 ')

    disp('---------------------------------------')

        h=input('position of feeder,posision must be 0<position<L/2 or -L/2<position<0\n--->');

if (h>L/2)|(h<-L/2)

    error('you enter position feeder greater than Length of dipole')

    return

end 

disp('              ')

disp('Rradiational when change posision feeder=')

Rr_new=Rr./((sin(B.*((L/2)-h))).^2) 

Rr_old=Rr

xp=h;

yp=-i:0.001:-i+(i/100);

plot(yp,xp,'sr')

hold on

x=-L/2:0.01:L/2;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

grid on

elseif n==4;

      disp('Length dipole antenna is 2*lambda ')

    disp('---------------------------------------')

        h=input('position of feeder,posision must be 0<position<L/2 or -L/2<position<0\n--->');

if (h>L/2)|(h<-L/2)

    error('you enter position feeder greater than Length of dipole')

    return

end

disp('              ')

disp('Rradiational when change posision feeder=')

Rr_new=Rr./((sin(B.*((L/2)-h))).^2) 

Rr_old=Rr

xp=h;

yp=-i:0.001:-i+0.1;

plot(yp,xp,'sr')

hold on

grid on

if h==0

  x=0:0.01:L/2;

y=i*sin(b*((L/2)-(x+h)));

plot(y,x)

hold on

x=-L/2:0.01:0;

y=i*sin(b*((L/2)+(x+h)));

plot(y,x)

grid on  

elseif (0<h)&(h<lambda/2);

    x=0:0.01:lambda/2;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

hold on

x=lambda/2:0.01:lambda;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

x=0:-0.01:-lambda/2;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

x=-lambda/2:-0.01:-lambda;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

grid on

elseif ((lambda/2)<h)&(h<lambda);  

    x=lambda/2:0.01:lambda;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

hold on

x=0:0.01:lambda/2;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

x=0:-0.01:-lambda/2;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

x=-lambda/2:-0.01:-lambda;

y=i*sin(pi+b*((L/2)-(x+h)));

plot(y,x)

grid on

elseif ((-lambda/2)<h)&(h<0);  

x=lambda/2:0.01:lambda;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

hold on

x=0:0.01:lambda/2;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

x=0:-0.01:-lambda/2;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

x=-lambda/2:-0.01:-lambda;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

grid on

else

    ((-lambda/2)>h)&(h>(-lambda));  

x=lambda/2:0.01:lambda;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

hold on

x=0:0.01:lambda/2;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

x=0:-0.01:-lambda/2;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

x=-lambda/2:-0.01:-lambda;

y=i*sin(pi+b*((L/2)+(x+h)));

plot(y,x)

grid on

end

else 

disp('Length dipole antenna is greater than 2*lambda and undefined ')

    disp('--------------------Exit----------------------')

end

⛄ 运行结果

时序预测 | MATLAB实现GWO-LSTM灰狼算法优化长短期记忆神经网络时间序列预测_hg_05

⛄ 参考文献

[1]杜秀丽等. "一种基于决策灰狼算法优化LSTM的网络流量预测方法.", CN111371607A. 2020.

⛄ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料