How to make prediction from a trained NARX neural network?

7 次查看(过去 30 天)
I have got the following code from a research paper which implements a NARX Neural network which trains the network using one exogenous input:
% Anp – The input time series.
% Adtds – The feedback time series.
X = tonndata(Anp,true,false);
T = tonndata(Adtds,true,false);
% 'trainlm' training function is chosen
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Model creation
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% Training and simulation data preparation
[x,xi,ai,t] = preparets(net,X,{},T);
% Divide the data for training, validation and testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 0/100;
net.divideParam.testRatio = 30/100;
net.divideFcn = 'divideblock';
% Network training
[net,tr] = train(net,x,t,xi,ai);
% Network testing
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Network view
view(net)
% Plots
figure, plotperform(tr)
figure, plottrainstate(tr)
figure, ploterrhist(e)
figure, plotregression(t,y)
figure, plotresponse(t,y)
figure, ploterrcorr(e)
figure, plotinerrcorr(x,e)
% Closed Loop Network
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)
% Step-Ahead Prediction Network
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);
stepAheadPerformance = perform(nets,ts,ys)
I am able to understand that it is training the network. But i am not able to understand how to predict output for new input data which the network has never seen before. I tried using net(input_Series) but it gives me the error that inputs are not sufficient. Could anyone please help me out?

回答(1 个)

Greg Heath
Greg Heath 2020-8-17
You forgot to include the intial conditions:
yz = nets(xz,xiz,aiz);
Thank you for formally accepting my answer
Greg
  2 个评论
Lavnish Gupta
Lavnish Gupta 2020-8-17
Dear Greg,
I tried using the following (grtest is my input for which I want output):
yy=nets(num2cell(grtest'),xs,ais);
But again I am getting the error: "Number of inputs does not match net.numInputs."
What to use in place of xiz and aiz? xc,aic or xs,ais?
georg enyew
georg enyew 2021-2-5
编辑:georg enyew 2021-2-5
this problem happen to the same to me? how it could be? any one who help us i appreciated.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by