时序预测 | MATLAB实现GWO-BiLSTM灰狼算法优化双向长短期记忆神经网络股票价格预测

本文涉及的产品
云原生数据库 PolarDB 分布式版,标准版 2核8GB
简介: 时序预测 | MATLAB实现GWO-BiLSTM灰狼算法优化双向长短期记忆神经网络股票价格预测

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

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

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信      无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机

⛄ 内容介绍

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

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

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

⛄ 部分代码

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


⛄ 运行结果

⛄ 参考文献

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

⛄ 完整代码

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


相关实践学习
Polardb-x 弹性伸缩实验
本实验主要介绍如何对PolarDB-X进行手动收缩扩容,了解PolarDB-X 中各个节点的含义,以及如何对不同配置的PolarDB-x 进行压测。
相关文章
|
25天前
|
机器学习/深度学习 自然语言处理 数据处理
大模型开发:描述长短期记忆网络(LSTM)和它们在序列数据上的应用。
LSTM,一种RNN变体,设计用于解决RNN处理长期依赖的难题。其核心在于门控机制(输入、遗忘、输出门)和长期记忆单元(细胞状态),能有效捕捉序列数据的长期依赖,广泛应用于语言模型、机器翻译等领域。然而,LSTM也存在计算复杂度高、解释性差和数据依赖性强等问题,需要通过优化和增强策略来改进。
|
25天前
|
传感器 算法 计算机视觉
基于肤色模型和中值滤波的手部检测算法FPGA实现,包括tb测试文件和MATLAB辅助验证
该内容是关于一个基于肤色模型和中值滤波的手部检测算法的描述,包括算法的运行效果图和所使用的软件版本(matlab2022a, vivado2019.2)。算法分为肤色分割和中值滤波两步,其中肤色模型在YCbCr色彩空间定义,中值滤波用于去除噪声。提供了一段核心程序代码,用于处理图像数据并在FPGA上实现。最终,检测结果输出到&quot;hand.txt&quot;文件。
|
2天前
|
文字识别 算法 计算机视觉
图像倾斜校正算法的MATLAB实现:图像倾斜角检测及校正
图像倾斜校正算法的MATLAB实现:图像倾斜角检测及校正
12 0
|
5天前
|
机器学习/深度学习 算法
【MATLAB】GA_ELM神经网络时序预测算法
【MATLAB】GA_ELM神经网络时序预测算法
278 9
|
23天前
|
机器学习/深度学习 算法 数据可视化
基于GA优化的CNN-GRU-Attention的时间序列回归预测matlab仿真
该内容描述了一个使用CNN-LSTM-Attention模型优化时间序列预测的过程。在优化前后,算法的预测效果有明显提升,软件版本为matlab2022a。理论部分介绍了CNN用于特征提取,LSTM处理序列依赖,Attention关注重要信息,以及遗传算法(GA)优化超参数。提供的核心代码展示了GA的优化迭代和模型训练,以及预测结果的可视化比较。
|
24天前
|
算法
m基于log-MPA检测算法的SCMA通信链路matlab误码率仿真
MATLAB 2022a仿真实现了稀疏码多址接入(SCMA)算法,该算法利用码本稀疏性实现多用户高效接入。每个用户从码本中选取码字发送,接收端采用Log-MPA算法进行多用户检测。由于MAP检测计算复杂度高,故采用Log-MPA降低复杂性。仿真展示了不同迭代次数(1, 5, 10, 30)对误码率(BER)的影响,通过比较各次迭代的BER曲线,研究算法性能与迭代次数的关系。
18 0
|
2月前
|
机器学习/深度学习 算法 PyTorch
python手把手搭建图像多分类神经网络-代码教程(手动搭建残差网络、mobileNET)
python手把手搭建图像多分类神经网络-代码教程(手动搭建残差网络、mobileNET)
44 0
|
6月前
|
机器学习/深度学习 监控 算法
【tensorflow】连续输入的神经网络模型训练代码
【tensorflow】连续输入的神经网络模型训练代码
|
6月前
|
机器学习/深度学习 存储 自然语言处理
|
2月前
|
机器学习/深度学习 存储 算法
【轻量化:实操】动手实现神经网络中的裁枝操作(附演示代码&yolo系列)
【轻量化:实操】动手实现神经网络中的裁枝操作(附演示代码&yolo系列)
37 1

热门文章

最新文章