I would like to train a time-series data using GatedRecurrentLayer
. The data consists of k scalar features mapping to a scalar number at every time step: i.e.
{#1, #2, ..., #k}[[t]]->target[[t]]
, where t
designates the time-step. I would like to create n recurrent neuron layer, such that an input sequence from time (t-n)
to (t)
is fed into the network to produce a predicted value for time t using both the current values of the features, as well as past history.
I created a [m,k]
array (named featureset
below) consisting of k
columns corresponding to each feature and m
rows (length of the total training series), as well as a [m, 1]
target vector. I defined the training set and the netchain as:
trainset=Table[featureset[[i, All]]->target[[i]], {i, 1, Length[target]}];
net=NetChain[{GatedRecurrentLayer[n], SequenceLastLayer[], 1}];
When I try training this using NetTrain
, I get the following error message:
NetTrain::nettinf2: Could not automatically find way to encode training data, which consists of length-16 vectors, to be compatible with port "Input", which expects n*[DottedSquare] matrices. Please specify shapes for the input and/or output ports of the net before calling NetTrain.
I think GatedRecurrentLayer[n]
does not do what I want since n refers to the output vector size, but not the sequence length. And also, seems like I don't really understand sequences.
I have a similar problem with one of the examples in the NetTrain
help document. The following code works:
seqs = Table[RandomReal[1, RandomInteger[{2, 5}]], 10000];
net = NetChain[{GatedRecurrentLayer[10], SequenceLastLayer[], 10,
Ramp, 1}];
trained = NetTrain[net, Map[# -> Max[#] &, seqs]]
but if you replace the first line with:
seqs = Table[RandomReal[1, 5], 10000];
it gives the same error message. As far as I can tell, all I have done is make the sequence length fixed as opposed to variable.
In any case, I am pretty new to all of this, so any help you can provide would be appreciated.