MATLAB時間序列預測Prediction of time series with NAR neural network


具體請參考:http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn05_narnet/

神經網絡預測時間序列數據,有三種模型,

這里是給出的是第二種NAR,即只有時間序列數據y(t),沒有x(t)。具體訓練和預測matlab代碼如下:  

 

format compact

% data settings
N  = 249; % number of samples
Nu = 224; % number of learning samples

y = Data;% Input your data
% prepare training data
yt = con2seq(y(1:Nu)');

% prepare test data
yv = con2seq(y(Nu+1:end)');

% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. NTSTOOL falls back to this in low memory situations.
trainFcn = 'trainlm';  % Levenberg-Marquardt

% Create a Nonlinear Autoregressive Network
feedbackDelays = 1:5;
hiddenLayerSize = 40;
net = narnet(feedbackDelays,hiddenLayerSize,'open',trainFcn);

[Xs,Xi,Ai,Ts] = preparets(net,{},{},yt);

% train net with prepared training data
net = train(net,Xs,Ts,Xi,Ai);
% view trained net
% close feedback for recursive prediction
net = closeloop(net);
% view closeloop version of a net
view(net);

%%%Recursive prediction on test data
% prepare test data for network simulation
yini = yt(end-max(feedbackDelays)+1:end); % initial values from training data
% combine initial values and test data 'yv'
[Xs,Xi,Ai] = preparets(net,{},{},[yini yv]);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM