-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsample_set.py
45 lines (30 loc) · 988 Bytes
/
sample_set.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
import os
import torch
import random
import torch.utils.data as data
from pandas.io.parsers import read_csv
def read_files(folder):
daily_data = []
for root, _, fnames in os.walk(folder):
for fname in fnames:
path = os.path.join(root, fname)
df = read_csv(path)
for i in range(0,len(df)):
if i % 48 == 0 :
if i != 0 :
daily_data.append(temp[:])
temp = [ df['price_change'][i] ]
else :
temp.append(df['price_change'][i])
return daily_data
class Sample_set(data.Dataset):
def __init__(self, folder):
data = read_files(folder)
print 'This set contains %d items.' % len(data)
self.data = data
def __getitem__(self, index):
item = torch.Tensor([self.data[index][:]]) # add one more dimension
target = torch.Tensor([self.data[index][:]]) # add one more dimension
return item,target
def __len__(self):
return len(self.data)