-
Notifications
You must be signed in to change notification settings - Fork 117
/
timeseries_batch_sequencing.py
49 lines (43 loc) · 1.68 KB
/
timeseries_batch_sequencing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
#
# File : examples/datasets/timeseries_batch_sequencing.py
# Description : Transform a timeseries to batches of sequence determined by a window size.
# Date : 21th of July, 2020
#
# This file is part of EchoTorch. EchoTorch is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Nils Schaetti <nils.schaetti@unine.ch>, <nils.schaetti@unige.ch>
# Imports
import echotorch.datasets as etds
from torch.utils.data.dataloader import DataLoader
import matplotlib.pyplot as plt
# A dataset of sine patterns
sine_dataset = etds.SinusoidalTimeseries(sample_len=1000, n_samples=1, period=9.3547)
# Timeseries batch sequence dataset
sine_sequence_dataset = etds.TimeseriesBatchSequencesDataset(
root_dataset=sine_dataset,
window_size=100,
stride=100,
data_indices=None,
dataset_in_memory=True
)
# Data loader
sine_dataset_loader = DataLoader(sine_dataset, batch_size=1, shuffle=False)
sine_sequence_loader = DataLoader(sine_sequence_dataset, batch_size=1, shuffle=False)
# For each sample
for data in sine_sequence_loader:
# Plot
plt.plot(data[0].numpy(), 'b')
plt.show()
# end for