【LMS时间序列预测】基于matlab LMS麦基玻璃时间序列预测【含Matlab源码 1443期】
【摘要】
一、获取代码方式
获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2: 完整代码已上传我的资源:【时间序列预测】基于matlab LMS麦基玻璃时间序...
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【时间序列预测】基于matlab LMS麦基玻璃时间序列预测【含Matlab源码 1443期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
%% Mackey Glass Time Series Prediction Using Least Mean Square (LMS)
%
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
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
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
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
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
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
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)
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
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
[3]周品.MATLAB 神经网络设计与应用[M].清华大学出版社,2013.
[4]陈明.MATLAB神经网络原理与实例精解[M].清华大学出版社,2013.
[5]方清城.MATLAB R2016a神经网络设计与应用28个案例分析[M].清华大学出版社,2018.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/120937902
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)