Batching data in sliding window fashion

Hi, all,

I would like to train an LSTM with neuron spikes. The data is a binary sequence, i.e., ‘10101011’.

I would like to use torch.utils.data.DataLoader to feed my training data, but I don’t know how can I sample the data for my batches in sliding window fashion.
Sliding window means I would like to sample my data sequentially, but only one step size each iteration.
Example :
batch1 : 000001
batch2 : 000010
batch3 : 000100

At present I do this manually, but I wonder if the
sampler = torch.utils.data.sampler.SequentialSampler()
can do this for me.
my code :

 for batch in np.arange(0, train_size, batch_size):
        input = np.concatenate((CA3_data[:,:,batch:batch + batch_size], CA1_data[:,:,batch:batch + batch_size]), axis = 1)
        target = np.concatenate((CA3_data[:,:,1 + batch: 1 + batch + batch_size], CA1_data[:, : , 1 + batch : 1 + batch + batch_size]), axis = 1)
   
        test_input = np.concatenate((CA3_data[: , : , batch + batch_size : batch + batch_size + test_size], CA1_data[:,:, batch + batch_size : batch + batch_size + test_size]), axis = 1)
        test_target = np.concatenate((CA3_data[ : , : , 1 + batch + batch_size : 1 + batch + batch_size + test_size], CA1_data[ : , : , 1 + batch + batch_size: 1 + batch + batch_size + test_size]), axis = 1)
1 Like