-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset.py
53 lines (40 loc) · 1.65 KB
/
dataset.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
50
51
52
53
from torch.utils.data import Dataset
import torch
import pandas as pd
from sklearn.preprocessing import MinMaxScaler, StandardScaler
class Rossler(Dataset):
def __init__(self, df, window=200, pred_window=1, normalise=False):
"""
Args:
csv_file (string): Path to the csv file with annotations.
root_dir (string): Directory with all the images.
transform (callable, optional): Optional transform to be applied
on a sample.
"""
self.window = window
self.pred_window = pred_window
self.length = int(len(df) / (window+pred_window))
self.sample_len = (window+pred_window)
self.df = df.iloc[:self.length*(window+pred_window)]
self.normalise = normalise
def __len__(self):
return self.length
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
features = self.df.iloc[idx*self.window:idx*self.window+self.window].values
#print(idx*self.sample_len, idx*self.sample_len+self.window)
target = self.df.iloc[idx*self.window+self.window:idx*self.window+self.window+self.pred_window].values
if self.normalise == True:
mean = self.df.mean()
std = self.df.std()
features = (features-mean)/std
return torch.tensor(features), torch.tensor(target)
if __name__ == "__main__":
df = pd.read_csv('data.csv')
scaler = MinMaxScaler
y_data = df["y"]
data = Rossler(df=y_data, window=200,pred_window=1, normalise=False)
print(data[1])
data = Rossler(df=y_data, window=200,pred_window=1, normalise=True)
print(data[1])