The Understanding of the process of (Multi-step Forecasting using "NARX")

11 views (last 30 days)
Dears.. I am doing multi step foecasting for wind speed for my university project.. but I am stuck... so I used simple data "y=x^2" to check the output as I need to understand how multi step is done when I am using close loop..
read almost all post regarding narx, but still I did not reached to what I am looking for..
I want to undertand the multi step procedure so it will be easy for me to use it on my data..
I have wind speed data for 1.5 year and external inputs I am using " pressure, humidity, and temperature " I am getting the one step ahead prediction and its working with fine, but I need to know how I can get 30 mint ahead prediction which is 3 step ahead for my data as my data interval is for 10 mint.
however, I used simple data to check 1st how multi step is working so that I can use it for my data.. kindly check below codes when I used closed loop with delay I got the outputs (square) of the input ( for last step it was approximately 400 as square of 20) and when I used the remove delay function, then I got the last step output one step ahead ( for 20 I got square of 21 ) this what I wanted.. but how to get 3 step ahead, for example if last input is 20, I want to get output for 23 ??
please support//
x=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
y=[1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400];
inputSeries = con2seq(x);
targetSeries = con2seq(y);
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
figure, plotperform(tr)
figure;
plot (cell2mat (targets),'r');
hold
plot(cell2mat (outputs) ,'b');
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
yc = netc(xc,xic,aic);
perfc = perform(netc,tc,yc)
figure;
plot (cell2mat(tc),'r');
hold
plot(cell2mat (yc),'b');
nets = removedelay(net);
nets.name = [net.name ' - Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts] = preparets(nets,inputSeries,{},targetSeries);
ys = nets(xs,xis,ais);
earlyPredictPerformance = perform(nets,ts,ys)
figure;
plot (cell2mat (ts),'r');
hold
plot(cell2mat (ys),'b');
Many Many Thanks// BR// Saira AL Zadjali

Accepted Answer

Greg Heath
Greg Heath on 6 Feb 2018
Edited: Greg Heath on 6 Feb 2018
NARXNET requires an input. If you do not have a future input you can do the following
1. DESIGN 2 NARNETS: one for input and one for output
2. Then you can use the output NARNET to predict the
future output
3. IN ADDITION you can use the input NARNET to predict
the future input
4. THEN use the predicted future input with NARXNET to
also predict the future output.
HOWEVER, before you design any nets,
1. Obtain the autocorrelation functions of the input and
output
AND
2. Obtain the crosscorrelation function of the input and output.
THEN
3. Obtain the significant delays to determine what are
the most effective lags to use in NARNET and NARXNET.
I have written a sufficient number of explanatory posts in BOTH the NEWSGROUP (comp.soft-sys.matlab) and ANSWERS.
Thank you for formally accepting my answer
Greg
  2 Comments
Saira AlZadjali
Saira AlZadjali on 7 Feb 2018
Dear Greg,
I Modified the network according your advice :) and got 4 step ahead prediction..
X= [ 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];
Y= [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,60];
Y = con2seq(Y);
X = con2seq(X);
net = narnet(1:4,10);
net.trainParam.showWindow = false;
Xp = tonndata(X,false,true);
[Xsp,Xip,Aip,Tsp] = preparets(net,{},{},Xp);
net = closeloop(train(net,Xsp,Tsp,Xip,Aip));
Xpred = nan(30,1);
Xpred = tonndata(Xpred,false,false);
Xpred(1:26) = Xp(end-25:end);
[xcp,xicp,aicx,tcx] = preparets(net,{},{},Xpred);
Xpred = fromnndata(net(xcp,xicp,aicx),true,false,false);
net_2 = narnet(1:4,10);
net_2.trainParam.showWindow = false;
Yp = tonndata(Y,false,true);
[Xsp,Xip,Aip,Tsp] = preparets(net_2,{},{},Yp);
net_2 = closeloop(train(net_2,Xsp,Tsp,Xip,Aip));
Ypred = nan(30,1);
Ypred = tonndata(Ypred,false,false);
Ypred(1:26) = Yp(end-25:end);
[ycp,yicp,aicy,tcy] = preparets(net_2,{},{},Ypred);
Ypred = fromnndata(net_2(ycp,yicp,aicy),true,false,false);
Xpred= transpose (Xpred);
Ypred= transpose (Ypred);
Xpred = con2seq(Xpred);
Ypred = con2seq(Ypred);
net_3 = narxnet(1:4,10);
net_3.trainParam.showWindow = false;
T = tonndata(Y,false,true);
W = tonndata(X,false,true);
[Xs,Xi,Ai,Ts] = preparets(net_3,W,{},T);
net_3.divideParam.trainRatio = 70/100;
net_3.divideParam.valRatio = 15/100;
net_3.divideParam.testRatio = 15/100;
[net_3,tr] = train(net_3,Xs,Ts,Xi,Ai);
Yp_narx = net_3(Xs,Xi,Ai);
perf = perform(net_3,Ts,Yp_narx)
netc = closeloop(net_3);
netc.name = [net_3.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,Xpred,{},Ypred);
yc = netc(xc,xic,aic);
regarding "autocorrelation" function, I could not get you// I will try to read about it and come back to you//
Thank you// Saira Al Zadjali

Sign in to comment.

More Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!