I have a time series that has internet traffic rates. 14772 row value and 1 column. I use NARnet at NN Time Series Toolbox and train it with %70 and test with %30 of series. I need the MAPE, so I divided the TargetSeries(Actual Values from .xlsx) to two matrix: TrainSeries(first 10340) and TestSeries(last 4432 value). Calculating the MAPE with TestSeries and last 4432 values of TargetSeries. Finally, I need to predict the future values of time series which I want. For example, I want the NAR predict to 15000th value. But I am confused. I deactivated the close loop and predict section because dont how to use. How to predict the future values ? With Close Loop Network or Step Ahead Prediction Network or both ? I searched the internet and found a code piece by Greg Health. But dont now how to arrange the parameters for my problem(ex. Xf, Af, Xs, Xi etc.) :
[ net tr ] = train( net, Xs, Ts, Xi, Ai ); [ Ys Xf Af ] = net( Xs, Xi, Ai ); Es = gsubtract(net,Ts,Ys); Finally, to predict into the future M timesteps beyond the end of the target data Xic2 = Xf; Aic2 = Af; Ypred = netc2( cell(1,M), Xic2, Aic2);
%%%%%%%%%%%%%%%% Here is my code :
% Solve an Autoregression Time-Series Problem with a NAR Neural Network
% Script generated by Neural Time Series app
% Created 20-Feb-2016 15:46:59
input=xlsread('input.xlsx');TargetSeries=input.';%Transpose
TargetSeries=num2cell(TargetSeries);%convert
% Choose a Training Function
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network
feedbackDelays = 1:17;hiddenLayerSize = 5;net = narnet(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.
% Setup Division of Data for Training, Validation, Testing
net.trainParam.mu_max=1.00e+18;net.trainParam.epochs=50;net.trainParam.max_fail=1;net.performParam.normalization ='standard';net.divideFcn='divideind';%[trainInd,testInd] = divideind(14772,1:10340,10341:14772);
net.divideParam.trainInd = 1:10340;net.divideParam.valInd = 10340:10340;net.divideParam.testInd = 10341:14772;[x,xi,ai,t] = preparets(net,{},{},TargetSeries);for i=1:10340 TrainSeries(:,i)=TargetSeries(:,i);endTrainSeriess=cell2mat(TrainSeries);for i=1:4431 TestSeries(:,i)=TargetSeries(:,10341+i);end% Train the Network
[net,tr] = train(net,x,t,xi,ai);% Test the Network
y = net(TestSeries,xi,ai);performance = perform(net,TestSeries,y);% View the Network
view(net)E=cell2mat(TestSeries);M=cell2mat(y);%Plots
%plot(M,'b*');
%hold on
%plot(E,'r*');
%legend('PredictionValues','TargetValues');
%MAPE
MEAP=abs(M-E);MEAP2=abs(MEAP./E);MEAP3=sum(MEAP2);MEAP4=(MEAP3/length(M))*100;% 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);
% netc.name = [net.name ' - Closed Loop'];
% view(netc)
% [xc,xic,aic,tc] = preparets(netc,{},{},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);
% nets.name = [net.name ' - Predict One Step Ahead'];
% view(nets)
% [xs,xis,ais,ts] = preparets(nets,{},{},TargetSeries);
% ys = nets(xs,xis,ais);
% stepAheadPerformance = perform(nets,ts,ys);
Best Answer