Neural Network - Multi Step Ahead Prediction
이전 댓글 표시
Hi all, please I need your help !
I've read all the posts here about Time Series Forecasting but still can't figure it out ! I'm drained.. *:-(*
I've a NARX neural network with 10 hidden neurons and 2 delays. As input I have a 510x5 (called Inputx) and as output I have a 510x1 (called Target).
I want to forecast 10 days ahead but it's really not working...
I tried the following code but I'm stuck now. *:-(*
Would you mind to help me ? *Some code will be awesome. :-(*
***////////////////////////////////////////////******** ***/////////////////////////////////////////// ******
inputSeries = tonndata(Inputx,false,false);
targetSeries = tonndata(Target,false,false);
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
[xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
yc = netc(xc,xic,aic);
***////////////////////////////////////////////******** ***/////////////////////////////////////////// ******
댓글 수: 2
Oleg Komarov
2011년 9월 2일
Two things,please change the title of your post in something useful and format the code: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099
Constantine
2014년 11월 21일
with respect to the accepted answer by Lucas Garcia, I find the predicted data only agrees with the actual data as well as his every once in a while.
1. It's important, before running the fit, to clear the variables, eg. 'clear all.' Re-running without clearing the variables leads to much worse fits.
2. much better fits result from using a bigger delay, like 5, instead of the delay of 2 in his example. Or by adding additional training data, such as the time derivative or 2nd time derivatives of the training data. Of course, doing this makes the fit considerably slower.
채택된 답변
추가 답변 (5개)
Mark Hudson Beale
2011년 9월 9일
Here is an example that may help. A NARX network is trained on series inputs X and targets T, then the simulation is picked up at the end of X using continuation input data X2 with a closed loop network. The final states after open loop simulation with X are used as the initial states for closed loop simulation with X2.
% DESIGN NETWORK
[x,t] = simplenarx_dataset;
net = narxnet;
[X,Xi,Ai,T] = preparets(net,x,{},t);
net = train(net,X,T,Xi,Ai);
view(net)
% SIMULATE NETWORK FOR ORIGINAL SERIES
[Y,Xf,Af] = sim(net,X,Xi,Ai);
% CONTINUE SIMULATION FROM FINAL STATES XF & AF WITH ADDITIONAL
% INPUT DATA USING CLOSED LOOP NETWORK.
% Closed Loop Network
netc = closeloop(net);
view(netc)
% 10 More Steps for the first (now only) input
X2 = num2cell(rand(1,10));
% Initial input states for closed loop continuation will be the
% first input's final states.
Xi2 = Xf(1,:);
% Initial 2nd layer states for closed loop contination will be the
% processed second input's final states. Initial 1st layer states
% will be zeros, as they have no delays associated with them.
Ai2 = cell2mat(Xf(2,:));
for i=1:length(net.inputs{1}.processFcns)
fcn = net.inputs{i}.processFcns{i};
settings = net.inputs{i}.processSettings{i};
Ai2 = feval(fcn,'apply',Ai2,settings);
end
Ai2 = mat2cell([zeros(10,2); Ai2],[10 1],ones(1,2));
% Closed loop simulation on X2 continues from open loop state after X.
Y2 = sim(netc,X2,Xi2,Ai2);
댓글 수: 4
Jack
2011년 9월 12일
Elma
2014년 2월 18일
I have tried this code, and it is great, but when I try to apply it for my problem, I get really bad results. I tried with changing input and feedback delays, as well as number of hidden neurons, but the results are always bad (figure) (green line is multi step predistion)

The code is given below:
% DESIGN NETWORK
ID=1:2;
HL=6
FD=1:2;
net = narxnet(ID,FD,HL);
[X,Xi,Ai,T] = preparets(net,x,{},WS);
net.divideFcn = 'divideblock';
net = train(net,X,T,Xi,Ai);
% SIMULATE NETWORK FOR ORIGINAL SERIES
[Y,Xf,Af] = sim(net,X,Xi,Ai);
% CONTINUE SIMULATION FROM FINAL STATES XF & AF WITH ADDITIONAL
% INPUT DATA USING CLOSED LOOP NETWORK.
% Closed Loop Network
netc = closeloop(net);
Xi2 = Xf(1,:);
Ai2 = cell2mat(Xf(2,:));
for i=1:length(net.inputs{1}.processFcns)
fcn = net.inputs{i}.processFcns{i};
settings = net.inputs{i}.processSettings{i};
Ai2 = feval(fcn,'apply',Ai2,settings);
end
Ai2 = mat2cell([zeros(10,2); Ai2],[10 1],ones(1,2));
Y2 = sim(netc,X2,Xi2,Ai2);
plot(1:length(WS),cell2mat(WS))
hold on
plot(1:length(Y),cell2mat(Y),'r')
plot(length(WS):length(WS)+length(Y2)-1,cell2mat(Y2),'g')
legend('Input data - target series','One-step ahead prediction','Multi-step prediction beyond target series');
WT
2015년 3월 1일
May I know what this "Ai2 = mat2cell([zeros(10,2); Ai2],[10 1],ones(1,2));" means?
Thank You
IOANNIS4
2015년 8월 5일
Please can someone exlpain little bit more this part
% Xi2 = Xf(1,:); Ai2 = cell2mat(Xf(2,:)); for i=1:length(net.inputs{1}.processFcns) fcn = net.inputs{i}.processFcns{i}; settings = net.inputs{i}.processSettings{i}; Ai2 = feval(fcn,'apply',Ai2,settings); end Ai2 = mat2cell([zeros(10,2); Ai2],[10 1],ones(1,2)); Y2 = sim(netc,X2,Xi2,Ai2);
Please you would really help us, Kind regards, Ioannis
Greg Heath
2014년 3월 25일
1 개 추천
When the loop is closed, the net should be retrained with the original data and initial weights the same as the final weights of the openloop configuration.
댓글 수: 1
Mario Viola
2021년 2월 26일
Just one question, How can i access the final weights from the open loop configuration ? ANd how to set them in the new closed configuration ?
mladen
2013년 10월 25일
0 개 추천
Be aware that predicting outputs this way (similar to cascade relaization of linear system) has great sensitivity to parametar estimation errors because they propagate in the process Mark Hudson Beale mentioned. This is highlighted in hard, multiple steps ahead problems.
Parallel realizations (simoltanoius output estimation...for instance 10 outputs of neural network for next 10 time steps) tend to be less sensitive to this errors. I have implemented this with my code which is alway prone to error :) So my subquestion is:
Is there some specific way to prepare my data for training with some matlab function?
Murat Akdag
2015년 3월 28일
0 개 추천
I'm trying to understand this narnet but still can't solve. Looking for help in matlab help section in this page: http://www.mathworks.com/help/nnet/ug/multistep-neural-network-prediction.html?searchHighlight=narnet%20multistep i try same codes but there is an error in >> [netc,xi,ai] = closeloop(net,xf,af); too many arguments. I just need one working sample about narnet which can predict 12 steps ahead prediction. I try to do with GUI in matlab NN section. But it has predict just 1 step ahead with removedelay command. I need 12 steps ahead. Thanks for help.
댓글 수: 4
Greg Heath
2015년 9월 17일
Your error message is because you are using an obsolete version. Try
netc = closeloop(net,xf,af);
Then find xi and ai from preparets
Hope this helps.
Greg
Charles
2017년 7월 10일
Thank you for the NARX code. I am somewhat new to NARX and wish to leverage it to predict trend and next day value on a currency pair. I have used opening price and closing price as inputs X and T. i have reduced the delay to 5. For now I have kept rest of script the same. What is a good source on how to interpret the output? I believe the goal is to have the smallest MSE as possible. What are epochs?
Greg Heath
2017년 7월 11일
epochs are the number of loops the training goes through to trying to minimize the objective function ...
but you knew that already because you have GOOGLE & WIKIPEDIA
RIGHT?
Did you find this
https://www.quora.com/What-is-epochs-in-machine-learning
?
hugo kuribayashi
2015년 4월 15일
0 개 추천
Considering all this examples.. How can i calculate MAPE error instead MSE?
댓글 수: 1
Greg Heath
2017년 7월 11일
편집: Greg Heath
2017년 7월 12일
You mean "in addition to" ?
1. Learn with MSE or MSEREG
2. Report your findings with whatever floats your boat.
3. I prefer NMSE [0 1] for regression and time series
and
PCTERR [ 0 1 ]
for classification and pattern recognition
(;>)
Greg
P.S. Be aware of the shortcomings of MAPE and it's attempted modifications
https://en.wikipedia.org/wiki/Mean_absolute_percentage_error
Hope this helps.
Greg
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
