-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdataset.py
55 lines (38 loc) · 1.29 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
54
55
"""dataset.py"""
import os
import numpy as np
import scipy.io
import torch
from torch.utils.data import Dataset
class GroundTruthDataset(Dataset):
def __init__(self, root_dir):
# Load Ground Truth simulations from Matlab
self.mat_data = scipy.io.loadmat(root_dir)
# Load state variables
self.z = torch.from_numpy(self.mat_data['Z']).float()
# Extract relevant dimensions and lengths of the problem
self.dt = self.mat_data['dt'][0,0]
self.dim_t = self.z.shape[0]
self.dim_z = self.z.shape[1]
self.len = self.dim_t - 1
def __getitem__(self, snapshot):
z = self.z[snapshot,:]
return z
def __len__(self):
return self.len
def load_dataset(args):
# Dataset directory path
sys_name = args.sys_name
root_dir = os.path.join(args.dset_dir, 'database_' + sys_name)
# Create Dataset instance
dataset = GroundTruthDataset(root_dir)
return dataset
def split_dataset(total_snaps):
# Train and test snapshots
train_snaps = int(0.8*total_snaps)
# Random split
indices = np.arange(total_snaps)
np.random.shuffle(indices)
train_indices = indices[:train_snaps]
test_indices = indices[train_snaps:total_snaps]
return train_indices, test_indices