MATLAB: How does the routine newfftd work

Deep Learning Toolboxnewfftd

How does the routine newfftd work? (It's for time delay neural networks)
What does the vector ID represent?
net = newfftd(PR,ID,[S1 S2…SNl],{TF1 TF2…TFNl},BTF,BLF,PF)
PR-Rx2 matrix of min and max values for R input elements.
ID – Input delay vector.
In the example shown in the on-line help, the vector ID is [0 1]:
net = newfftd([0 1],[0 1],[5 1],{'tansig' 'purelin'});
Suppose that I have a time sequence P of N data, the instruction phase is
conducted on N/2 data assuming that the i-th data is predictable
considering the values at the time i-1,i-2,i-3 with one time delay.
My target vector is T and is generated from P by shifting back of three
position the vector P:
time* 1 2 3 4 5 6 7 8 9 10
data sequence a b c d e f g h i j
|
(*) numbers give the time sequence
(**) letters are real values between 0 and 1
In this case the input layer has 3 neurons while the output layer has only one.
My questions are:
1)How can I initialize the network assuming that all the data is normalized (i.e. min=0, max=1)?
2)How do I create vectors P and T for the training of the instruction net = train(net,P,T)?

Best Answer

In the NEWFFTD function, ID defines the vector of input delays. If you want the network to predict the target at time t given inputs at times t-1, t-2, and t-3 then ID would be [1 2 3].
If you want the target at time t to be predicted at times t, t-2, and t-4 then ID would be [0 2 4].
You can use PREMNMX, POSTMNMX, and TRAMNMX to normalize data to min and max of -1 and +1. They are described in their help comments and also on page 5-44 of the User's Guide.
Sequences are represented with row cell arrays. The following example may help you determine how to format your own prediction problem.
Let us say we have a sequence Z as defined below:
t = 0, Z(:,t+1) = [0; 1];
t = 1, Z(:,t+1) = [-1; 0];
t = 2, Z(:,t+1) = [-1; 1];
t = 3, Z(:,t+1) = [0; 0];
t = 4, Z(:,t+1) = [1; -1];
t = 5, Z(:,t+1) = [0; -1];
We would like the network to predict Z(t) given Z(t-1), Z(t-2) and Z(t-3).
We can define this problem with three row cell arrays. They are:
Pi - the initial inputs for which the network will not have a target
P - the inputs for which the network will have a target
T - the targets
In this case two initial inputs must be presented before the network can predict anything:
Pi= {Z(0) Z(1)} = {[0;1] [-1;0]} = Pi = con2seq(Z(:,1:2));
The network will then be presented with Z(2) through Z(4)...
P = {Z(2) Z(3) Z(4)} = {[-1; 1] [0;0] [1;-1]} = con2seq(Z(:,3:5));
...and will be expected to respond with Z(3) through Z(5).
T = {Z(3) Z(4) Z(5)} = {[0;0] [1;-1] [0;-1]} = T = con2seq(Z(:,4:6));
Note that we would like the network to predict Z(t) given Z(t-1)..Z(t-3). This is equivalent to predicting T{i} given P{i}, P{i-1}, and P{i-2} so ID will equal [0 1 2].
Here a network is created that can do that. It has a two-element input whose values range from -1 to 1. It has input delays of 0, 1, and
2. It has 5 hidden neurons and 1 output.
net = newfftd(minmax(Z),[0 1 2],[5 2]);
It is then trained with P, Pi, and T as follows:
net.trainparam.epochs=500;
net = train(net,P,T,Pi);
The complete code follows:
Z = [ 0 -1 -1 0 1 0 ;
1 0 1 0 -1 -1 ];
Pi = con2seq(Z(:,1:2));
P = con2seq(Z(:,3:5));
T = con2seq(Z(:,4:6));
net = newfftd(minmax(Z),[0 1 2],[5 2]);
net.trainparam.epochs=500;
net = train(net,P,T,Pi);
Y=sim(net,P,Pi);
[Y{:}]-[T{:}]
For more neural network examples, visit the MATLAB Central File Exchange at http://www.mathworks.com/matlabcentral/