28 views (last 30 days)

I am using Matlab 2016a on a 64-bit Windows 7 Professional Machine. I have 132 input data as: [61.17;341.5600] [65.4800;328.2080] [64.8800;355.4050] and ........ and 120 output data as: 62352 95856 89124....... I generated a Closed-Loop NARX to predict the output data for input vectors X1(121:128). However, I am only able to simulate 120 outputs for 120 inputs and I cannot predict the future outputs using the valid inputs X1(121:128). I used the following code to simulate the outputs:

u1 = X1(1:90); % X1 is the input data

y1 = Y1(1:90); % Y1 is the output data

[p1,Pi1,Ai1,t1] = preparets(net_closed,u1,{},y1);

yp1 = net_closed(p1,Pi1,Ai1);

TS = size(t1,2);

plot(1:TS,cell2mat(t1),'b',1:TS,cell2mat(yp1),'r')

the resulting graph is : How can I change my code to predict the outputs for inputs 120:128? Thank you in advance.

Rajat Kathuria
on 5 Jan 2017

Edited: Rajat Kathuria
on 5 Jan 2017

Though, it's still not clear what you intend to achieve from your script, I assume you want to predict time-series (T) WITHOUT an exogenous variable (X). In that case, you need to use narnet and not narXnet. The following script (from your original script) will give you one-step forecast in variable 'y'

u1 = num2cell(1:90);

feedbackDelays = 1:2;

hiddenLayerSize = 10;

net = narnet(feedbackDelays,hiddenLayerSize); %Note, I used narnet (not narXnet)

[X, Xi, Ai, T] = preparets(net,{},{},u1);

[net,tr] = train(net, X, T, Xi, Ai);

%for prediction

nets = removedelay(net);

X2 = num2cell(120:128); %length of input series is 9

[xs,xis,ais,ts] = preparets(nets,{},{},X2);

y = nets(xs,xis,ais)

%Note, since there are two predictor variables ('feedbackDelays'), %there will be 8 corresponding predictions for an input series of length 9. %e.g. first inputs, 120 and 121 yields first output, ~122. last inputs 127 and 128 yields final %output ~129. Results may slightly vary depending on your training but, network seems to have %learnt this trivial linear trend well.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/318965-how-to-use-a-narx-to-predict-future-using-valid-input-data#comment_417823

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/318965-how-to-use-a-narx-to-predict-future-using-valid-input-data#comment_417823

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/318965-how-to-use-a-narx-to-predict-future-using-valid-input-data#comment_418297

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/318965-how-to-use-a-narx-to-predict-future-using-valid-input-data#comment_418297

Sign in to comment.