Asked by PK
on 3 Jan 2017

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
님의 답변 5 Jan 2017

Rajat Kathuria
님이 편집함. 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.

PK
5 Jan 2017

Sign in to comment.

PK
님의 답변 4 Jan 2017

Greg, Sorry for posting insufficient data. The code for NARX generation is:

X = X1;

T = Y1;

trainFcn = 'trainlm';

inputDelays = 1:2;

feedbackDelays = 1:2;

hiddenLayerSize = 10;

net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);

[x,xi,ai,t] = preparets(net,X,{},T);

net.divideParam.trainRatio = 70/100;

net.divideParam.valRatio = 15/100;

net.divideParam.testRatio = 15/100;

[net,tr] = train(net,x,t,xi,ai);

y = net(x,xi,ai);

e = gsubtract(t,y);

performance = perform(net,t,y)

view(net)

netc = closeloop(net);

netc.name = [net.name ' - Closed Loop'];

view(netc)

[xc,xic,aic,tc] = preparets(netc,X,{},T);

yc = netc(xc,xic,aic);

closedLoopPerformance = perform(net,tc,yc)

nets = removedelay(net);

nets.name = [net.name ' - Predict One Step Ahead'];

view(nets)

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

ys = nets(xs,xis,ais);

TS = size(ts,2);

plot(1:TS,cell2mat(ts),'b',1:TS,cell2mat(ys),'r')

stepAheadPerformance = perform(nets,ts,ys)

X1 is the input and Y1 is the output. I attached the data. I need to predict the output for another set of inputs let's say X2. How can I change the code to predict the outputs for X2? Thank you.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Greg Heath (view profile)

## 이 댓글에 대한 바로 가기 링크

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

## Armin Niaki (view profile)

## 이 댓글에 대한 바로 가기 링크

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

Sign in to comment.