2
$\begingroup$

Assuming we have a time-series dataset whose window_size = 30 and the batch_size = 4, which makes the overall input = 4*30 (2D). But as RNN expects 3D input, tf.expand_dims is used to make it a 3D input (as per the lecture, new inut becomes 4*30*1, where the last dimension is 1 as the example deals with a univariate time-series). What I don't get is that what does adding a dimension mean? Eg. what will be the element [0,0,0] of the input?

Also in keras, the typical format for fitting is

model.fit(input, output, epochs=400)

But in an RNN sample code for time-series data, I found

model.fit(dataset, epochs=400)

where dataset is a tf object containing the time-series data. Why is the input and output not given explicit for the model to train in case of the first code? The timestamp is already included in the input in a way(in the 4*30*1 input, the 2nd dimension is supposed to be time-stamps), but how does the keras know against what output labels the input has to be trained?

$\endgroup$
0
1
$\begingroup$

I think you’re confused about what a “batch” is. A batch has a very specific definition in machine learning.

In my experience:

  • Dimension 1 = number of bins or number of data points per each time step
  • Dimension 2 = window size, the number of time steps
  • Dimension 3 = batch size, the total number of examples which you’ll feed the network per training batch

Looks like this for [4,3,2]:

[[[0,1,4,3],[0,8,6,9],[9,6,7,4]],[[6,8,7,0],[1,7,7,9],[1,3,5,8]]]

4 values per time step, 3 total time steps per example, 2 examples in the batch.

Where [0,0,0] returns 0, [3,1,1] returns 9.

Also, one friendly piece of advice - don’t think in terms of time stamps. You’re not dealing with time in an RNN. You’re dealing with steps in a sequence. The sequence can be related to time.

Edit: With respect to the tensorflow stuff, a tf.dataset object can contain both the input data and the labels for each example. The point is to make writing code easier, managing data easier etc.

The process for training/testing is the same.

$\endgroup$
4
  • $\begingroup$ So in time series scenarios (I am guessing this applies to LSTMs as well), the absolute value of time has no meaning as whatever has been provided is taken to be a form of sequence. In such a case, is it right to say the granularity of the sequence, i.e. the interval (e.g. 2 time series with same values but the interval being 1 sec for one and 2 second for the other) is not important? Both the series would have the same predicted values? $\endgroup$ – user3656142 Aug 6 '19 at 15:53
  • $\begingroup$ To the first part: LSTMs are a type of RNN. Two sequences could, for example, be ABCDEF and CDEFGH. There’s no time in these examples where we want to predict G and I. $\endgroup$ – dijksterhuis Aug 6 '19 at 17:13
  • $\begingroup$ To the second part: you’ve got to remember what an RNN actually is. Each sequence step is a copy of the same neural network from the step before. It’s not a single network, it’s many of the same joined together recurrently (hence the name). With the above examples, you’d have to teach the copied network to be able to deal with inputs of A and CD for 1 sec, 2 sec where t=0 respectively (t refers to the sequence step we are observing). It’s probably possible, but overly complex. $\endgroup$ – dijksterhuis Aug 6 '19 at 17:19
  • 1
    $\begingroup$ Furthermore, with time series data, the values for 1 sec and 2 sec intervals will likely be different. The 2 sec interval will likely have to contain an aggregate of 2 of the steps of the 1 sec series. So you may not necessarily get the same predictions - as the input data is different. $\endgroup$ – dijksterhuis Aug 6 '19 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.