using timedelaynet neural network to predict values of time series

Hi,
I am having trouble figuring out how to use timedelaynet for prediction of unknown time series values.
From the Matlab documentation example with laser data and other questions I found on Matlab central:
y = laser_dataset;
y = y(1:600);
d = 8; % input delay 8
s = 1; % predict next single value in series
Pi = y(1:d);
p = y(d+1:end-s); % inputs
t = y(d+1+s:end); % targets
ftdnn_net = timedelaynet([1:d],10);
ftdnn_net.trainParam.epochs = 1000;
ftdnn_net.divideFcn = '';
ftdnn_net = train(ftdnn_net,p,t,Pi);
yp = ftdnn_net(p,Pi);
rmse = sqrt(mse(gsubtract(yp,t)));
so let's say I am happy with rmse and now would like to predict for example 601st or 650th unknown value of series, how would I do that?
To predict 601st value of the series, do I need to know values indexed 10:600 of the series (in other words all series values up to that point) that I can put back into yp_601 = ftdnn_net(p_10_to_600, Pi) and if that's the case if I wanted to predict a series value far out like 650th, and only had 600 known values available, would I calculate 601st, then 602nd, then 603rd, ..., 650th using the network above? Or is there a better approach?
Thank you for your help.

 Accepted Answer

You only have one time series.
Therefore you should be using narnet; not timedelaynet.
help/doc narnet
help/doc preparets
Find the significant autocorrelation lags. You can use
N = length(y)
zy = zscore(y,1);
autocorry = nncorr(zy,zy,N-1,'unbiased');
or
autocorry = ifft( abs(fft(zy)).^2 )/N
Determine the threshold for significant lags by finding the autocorrelation of randn(1,N). Then sort the positive lag values and find the value at floor(0.95*N).
To try to predict S timesteps beyond N, use
netc = closeloop(net).
help/doc closeloop
However, this will not work well if S is too large.
Hope this helps.
Thank you for formally accepting my answer!
Greg

3 Comments

Dear Greg,
Thank you so much for your answer. It gave me a lot of food for thought and now I have more questions. I am inexperienced with time series so please bear with me.
1. I was using laser_dataset and timedelaynet because that's the dataset Matlab's neural network tutorial uses at http://www.mathworks.com/help/pdf_doc/nnet/nnet_ug.pdf. According to your comment narnet could be a better fit. What is the difference between the 2 or in which case one is better than the other if I have a sequence of datapoints and would like to predict next one? Both timedelaynet and narnet involve input delays and looking at them via view(net), they look the same.
2. Next I tried using narnet and closeloop as per your suggestion above for simplenar_dataset and predicting series for more than one timestep ahead. (I have not looked at autocorrelation lags yet to determine input delays and did not standardize data for this one).
T = simplenar_dataset; % 100 data points
T_1_80 = T(1:80); % get 1st 80 points for training and prediction of 81st
net = narnet(1:2,10); % initialize narnet, input delay = 2, hidden n = 10
net.trainParam.epochs = 1000;
net.divideFcn = '';
[Xs,Xi,Ai,Ts] = preparets(net,{},{},T_1_80);
net = train(net,Xs,Ts,Xi,Ai);
% here I am not sure what to use for 1st argument in net(), it seems
% all that matters is that I use appropriate feedback delays
Y_81 = net(T_1_80(80), T(79:80)); % find 81st dp = 0.7249 vs act = 0.7252
net_c = closeloop(net); % close open-loop feedback to predict next 20 %points
T_78_100 = T(78:100);
[Xs1,Xi1,Ai1,Ts1] = preparets(net_c,{},{},T_78_100);
now I run into a problem, preparets returns Xs1 and Xi1 of dimensions 0x..., so they are empty arrays. This does not happen with narxnet example given in the tutorial which I have run through. What am I doing wrong?
3. After going through the motions described in question 2 above now I am curious, if I need to predict series small amount of steps ahead like 10 (given a big data set to train with), am I better of just using open-loop narnet (for accuracy purposes) to predict series 1 step ahead and just use Ynext = net(Ycurr, {Yprev:Ycurr}) 10 times plugging just gotten value of the series for Ycurr or is close-loop network more accurate for this purpose?
Again thank you so much for your help and if this is too much for one entry tell me. I can probably take question 1 and make a separate post out it with tag narnet vs. timedelaynet or something like that.
Victoria
TIMEDELAYNET is ONLY used with current and/or delayed inputs (NO delayed outputs)
NARNET is ONLY used with delayed outputs (NO current and/or delayed inputs)
NARXNET is used with current and/or delayed inputs and/or delayed outputs.
TIMEDELAYNET and NARNET are special cases of NARXNET. Therefore, it is only necessary to learn how to use NARXNET.
NARXNET and NARNET can be used in the CLOSED LOOP configuration where delayed predicted outputs are fedback to the input to continue predictions beyond where target data is available.
2. I run into a problem, preparets returns Xs1 and Xi1 of dimensions 0x..., so they are empty arrays. This does not happen with narxnet example given in the tutorial which I have run through. What am I doing wrong?
Nothing wrong. CLOSELOOP NARNET has no signals from inputs. Only delayed feedback signals from the output.
3. Must use CLOSEDLOOP for predicting ahead when exact past target info is unavailable.

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!