【GRU时序预测】基于贝叶斯网络优化门控循环单元BO-GRU实现时间序列数据预测附matlab代码

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

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

🍊个人信条:格物致知。

⛄ 内容介绍

石油是世界经济政治发展不能缺少的重要能源之一,它在世界经济发展中产生了重要的影响。减少其负面影响的办法就是了解并掌握石油价格的变化,因此目前全球热衷于的话题就是石油价格。石油价格被种种因素影响,包括供需、经济、国际政治、军事、外交等。由于石油价格的不确定性、复杂非线性、多种影响因素,非数值型的信息,数值型信息的数据噪声也十分大。由于传统石油价格预测方法不可依靠或预测结果精度较低。故此,学术和工业界研究者的目标就是找到一种预测模型,使其研究精度相对较高、性能等各方面均相对较好,同时还可以广泛使用。基于贝叶斯网络优化门控循环单元BO-GRU实现时间序列数据预测附matlab代码。

⛄ 部分代码

%% Mackey Glass Time Series Prediction Using Least Mean Square (LMS)

% Author: SHUJAAT KHAN

clc

clear all

close all

%% Loading Time series data

% I generated a series y(t) for t = 0,1, . . . ,3000, using

% mackey glass series equation with the following configurations:

% b = 0.1, a = 0.2, Tau = 20, and the initial conditions y(t - Tau) = 0.

load Dataset\Data.mat 

time_steps=2;

teacher_forcing=1; % recurrent ARMA modelling with forced desired input after defined time steps 

%% Training and Testing datasets

% For training

Tr=Data(100:2500,1);    % Selecting a Interval of series data t = 100~2500

Yr(Tr)=Data(Tr,2);      % Selecting a chuck of series data y(t)

% For testing

Ts=Data(2500:3000,1);   % Selecting a Interval of series data t = 2500~3000

Ys(Ts)=Data(Ts,2);      % Selecting a chuck of series data y(t)

%% LMS Parameters

eta=5e-3;       % Learning rate

M=1;            % Order of LMS filter

U=zeros(M+1,1); % Initial values of taps

W=zeros(M+1,1); % Initial weight of LMS

MSE=[];         % Initial mean squared error (MSE)

%% Learning weights of LMS (Training)

tic % start

for t=Tr(1):Tr(end)-time_steps

    U(1:end-1)=U(2:end);    % Shifting of tap window

    

    if (teacher_forcing==1)

        if rem(t,time_steps)==0 || (t==Tr(1))

            U(end)=Yr(t);           % Input (past/current samples)

        else

            U(end)=Yp(t-1);          % Input (past/current samples)          

        end

    else

        U(end)=Yr(t);           % Input (past/current samples)

    end

    Yp(t)=W'*U;                         % Predicted output

    e(t)=Yr(t+time_steps)-Yp(t);        % Error in predicted output

    W=W+eta*e(t)*U;     % Weight update rule of LMS

    

    E(t)=e(t).^2;   % Current mean squared error (MSE)

end

training_time=toc; % total time including training and calculation of MSE

%% Prediction of a next outcome of series using previous samples (Testing)

tic % start

U=U*0;  % Reinitialization of taps (optional)

for t=Ts(1):Ts(end)-time_steps+1

    U(1:end-1)=U(2:end);    % Shifting of tap window

    if (teacher_forcing==1)

        if rem(t,time_steps)==0 || (t==Ts(1))

            U(end)=Ys(t);           % Input (past/current samples)

        else

            U(end)=Yp(t-1);          % Input (past/current samples)          

        end

    else

        U(end)=Ys(t);           % Input (past/current samples)

    end

    

    

    Yp(t)=W'*U;             % Calculating output (future value)

    e(t)=Ys(t+time_steps-1)-Yp(t);        % Error in predicted output

    E(t)=e(t).^2;   % Current mean squared error (MSE)

end

testing_time=toc; % total time including testing and calculation of MSE

%% Results

figure(1)

plot(Tr,10*log10(E(Tr)));   % MSE curve

hold on

plot(Ts(1:end-time_steps+1),10*log10(E(Ts(1:end-time_steps+1))),'r');   % MSE curve

grid minor

title('Cost Function');

xlabel('Iterations (samples)');

ylabel('Mean Squared Error (MSE)');

legend('Training Phase','Test Phase');

figure(2)

plot(Tr(2*M:end),Yr(Tr(2*M:end)));      % Actual values of mackey glass series

hold on

plot(Tr(2*M:end),Yp(Tr(2*M:end))','r')   % Predicted values during training

plot(Ts,Ys(Ts),'--b');        % Actual unseen data

plot(Ts(1:end-time_steps+1),Yp(Ts(1:end-time_steps+1))','--r');  % Predicted values of mackey glass series (testing)

xlabel('Time: t');

ylabel('Output: Y(t)');

title('Mackey Glass Time Series Prediction Using Least Mean Square (LMS)')

ylim([min(Ys)-0.5, max(Ys)+0.5])

legend('Training Phase (desired)','Training Phase (predicted)','Test Phase (desired)','Test Phase (predicted)');

mitr=10*log10(mean(E(Tr)));  % Minimum MSE of training

mits=10*log10(mean(E(Ts(1:end-time_steps+1))));  % Minimum MSE of testing

display(sprintf('Total training time is %.5f, \nTotal testing time is %.5f \nMSE value during training %.3f (dB),\nMSE value during testing %.3f (dB)', ...

training_time,testing_time,mitr,mits));

⛄ 运行结果

⛄ 参考文献

[1]周洁超. 基于贝叶斯网络的时间序列预测[D]. 大连海事大学, 2016.

⛄ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值