One step ahead prediction with Recursive Neural Net (RNN)

3 views (last 30 days)
Hello, I am trying to use MATLABS RNN function layrecnet to do one step ahead prediction. But it does not let me use "removedelay" as in other examples, resulting in an error.
There must be another way to do it, I am wondering how to get one-step ahead prediction working with the RNN?
neto = layrecnet(inputDelays,hiddenLayerSize);
[Xo,Xoi,Aoi,To] = preparets(neto,Xorig,Torig);
[ neto, tro, Yo, Eo, Xof, Aof ] = train(neto,Xo,To,Xoi,Aoi);
view(neto)
Yo = neto(Xo,Xoi,Aoi);
to = cell2mat(To);
MSE00o = mean(var(to',1)) % Normalization Referenc
NMSEo = mse(Eo)/MSE00o
R2o = 1 - NMSEo
yo = cell2mat(Yo);
nets = removedelay(neto);
>> nets = removedelay(neto); Error using removedelay (line 57) Removing 1 to input delays would result in a negative input weight delay.
The layrecnet help mentioned using removedelay to do prediction, but I think the help is wrong.
>> help layrecnet layrecnet Layered recurrent neural network.
Layer recurrent networks with two (or more) layers can learn to
predict any dynamic output from past inputs given enough hidden
neurons and enough recurrent layer delays.
layrecnet(layerDelays,hiddenSizes,trainFcn) takes a row vectors
of layers delays, a row vector of hidden layer sizes, and a
backpropagation training function, and returns a layer recurrent neural
network with N+1 layers.
Input, output and output layers sizes are set to 0. These sizes will
automatically be configured to match particular data by train. Or the
user can manually configure inputs and outputs with configure.
Defaults are used if layrecnet is called with fewer arguments.
The default arguments are (1:2,10,'trainlm').
Here a layer recurrent network is used to solve a time series problem.
[X,T] = simpleseries_dataset;
net = layrecnet(1:2,10);
[Xs,Xi,Ai,Ts] = preparets(net,X,T);
net = train(net,Xs,Ts,Xi,Ai);
view(net);
Y = net(Xs,Xi,Ai);
perf = perform(net,Y,Ts)
To predict the next output a step ahead of when it will occur:
net = removedelay(net);
[Xs,Xi,Ai,Ts] = preparets(net,X,T);
Y = net(Xs,Xi,Ai);
See also narxnet, timedelaynet, distdelaynet.
Reference page in Help browser
doc layrecnet

Accepted Answer

Greg Heath
Greg Heath on 25 Mar 2015
Edited: Greg Heath on 17 Jul 2016
The removedelay command reduces all delays by 1
However feedback delays must be positive
Therefore, removedelay will cause an error if the minimum feedback
delay of any net is 1.
This includes nar and narx.
Similarly, input delays must be nonnegative
Therefore, removedelay will cause an error if the minimum input
delay of any net is 0.
Hope this helps.
Thank you for formally accepting my answer
Greg
  2 Comments
Alexandra Sikinioti-Lock
Alexandra Sikinioti-Lock on 17 Jul 2016
So does this mean that RNNs (layrecnet) cannot be used for one step ahead predictions? The reason I am asking again is because the syntax for an ANN is layrecnet(layerDelays,hiddenSizes,trainFcn) and the input delay cannot be inserted, from what I understand it is always zero. Could you perhaps provide an alternative for one step ahead prediction with RNN, if it exists?
Greg Heath
Greg Heath on 17 Jul 2016
See the documentation:
help narxnet
doc narxnet
net = narxnet(ID,FD,H);
ID >=0, FD>=1, H = [] (for H = 0), or H >=1
DEFAULT VALUES
net = narxnet;
% ID = FD = 1:2 and H = 10
Hope this helps.
Greg

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!