-
Notifications
You must be signed in to change notification settings - Fork 443
Add inter_batch_stride param to TimeSeriesGenerator #251
base: master
Are you sure you want to change the base?
Conversation
The original TimeSeriesGenerator emits batches where the first sample is a stride ahead of the previous batch's last sample. Many times more control is required (especially if feeding to a stateful RNN). The inter_batch_stride option allows user to explicitly specify the inter-batch stride relationships. If this option is None (or not supplied), the original behavior is maintained.
I suggest staying clear of import numpy as np
data = np.random.randn(240, 4) # (timesteps, channels)
length = 6
batch_size = 8
stride = 1
start_index, end_index, index = 6, 40, 0 i = start_index + batch_size * stride * index
rows = np.arange(i, min(i + batch_size * stride, end_index + 1), stride)
samples = np.array([data[row - length:row:sampling_rate] for row in rows])
print(samples.shape)
# (8, 6, 4) Batch dimension and a feature dimension (timesteps) are mixed, which is a big no-no and will obliterate training. The only workaround is if you feed data compatible with such a manipulation to begin with - good luck with that. There are other pitfalls I'll spare listing - bottom line, write your own timeseries generator. |
@OverLordGoldDragon I understand your concerns, but this is a well-respected library. If you feel strongly about it, help make it more understandable/extensible. |
@rjmccabe3701 Keras' PR page is piled with fine improvements or extensions of functionality that are never merged - TensorFlow's a lot less phobic to this end. If I were to make a PR, pretty sure it'd be rejected or left collecting electron dust - as it'd be a total overhaul of For your specific instance, you need not take my word for anything - just compare the data you feed in with that which it spits out and see if it makes sense. |
@OverLordGoldDragon Hello, "Batch dimension and a feature dimension (timesteps) are mixed" You could learn purely online in order to keep a potentially unbounded history, I tried something like that with the (experimental) Regards, TU |
@TanguyUrvoy Misleading information; mixing batch and features dimensions is never beneficial. What you describe for online learning is splitting the sequence into finite parts, then treating them as independent. This no longer qualifies for 'mixing' dimensions, as sequences are assumed independent to begin with. The problem arises when you have a single long sequence that is not to be treated as independent, but still needs to be split up - now mixing dimensions will treat a single, causally contiguous sequence as independent sequences, and will prohibit learning any time dependence. The one case that differs is one-step prediction, where one sequence is fed with varying lags in a single batch - but that already accounts for above in setting up data as independent sequences. OP's case concerns statefulness, for which I little-to-no use for |
@OverLordGoldDragon well I am happy that we both agree on the fact that, splitting long sequences into finite parts is a necessary evil as it crops the histories :) The (experimental) TU |
Summary
Grant explicit control for inter-batch sample ordering in TimeSeriesGenerator.
This change is backwards compatible.
Related Issues
See this stackoverflow question for background.
PR Overview
The original TimeSeriesGenerator emits batches where the first sample is
a stride ahead of the previous batch's last sample. Many times more
control is required (especially if feeding to a stateful RNN).
The inter_batch_stride option allows user to explicitly specify the
inter-batch stride relationships. If this option is None (or not
supplied), the original behavior is maintained.