MATLAB Answers

Where is output for this net ??

10 views (last 30 days)
briget spaniel
briget spaniel on 12 May 2016
Edited: Staffan on 12 May 2016
Im new in matlab now is day 2 i use matlab..
i use input 100 time series data on this.
i want get output from net at time 96 97 98 99 100 & predicted data 101 102 103 104 **4 before and 4 after 100
here the code
% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 12-May-2016 20:10:18
% This script assumes these variables are defined:
% TestIn - input time series.
% TestOut - feedback time series.
load TestIn.csv;
load TestOut.csv;
X = tonndata(TestIn,false,false);
T = tonndata(TestOut,false,false);
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer
% states. Using PREPARETS allows you to keep your original time series data
% unchanged, while easily customizing it for networks with differing
% numbers of delays, with open loop or closed loop feedback modes.
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y);
% View the Network
% Plots
% Uncomment these lines to enable various 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
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the outout layer.
netc = closeloop(net); = [ ' - Closed Loop'];
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc);
% Step-Ahead Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is
% given y(t+1). For some applications such as decision making, it would
% help to have predicted y(t+1) once y(t) is available, but before the
% actual y(t+1) occurs. The network can be made to return its output a
% timestep early by removing one delay so that its minimal tap delay is now
% 0 instead of 1. The new network returns the same outputs as the original
% network, but outputs are shifted left one timestep.
nets = removedelay(net); = [ ' - Predict One Step Ahead'];
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys);
please help me , i really need your help. what code to get output as i describe before and write it to external output csv file ?
thank you.


Sign in to comment.

Answers (1)

Staffan on 12 May 2016
Dear Bridget,
Have you only used Matlab for two days? Impressive!
I am also working with predictions using narxnet and narnet, I can't solve your question completely but I would like to advice you to have a look at the following newsgroup threads:
Wish you the best, (if you have the time,) please share your progress. I have a few of my own questions in progress, this one might be interesting for you to follow:

  1 Comment

Staffan on 12 May 2016
When you have created the vector with the predicted values, just use write to file.

Sign in to comment.

Translated by