-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.py
55 lines (39 loc) · 1.01 KB
/
utils.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
"""
Stefania Fresca, MOX Laboratory, Politecnico di Milano
February 2019
"""
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import numpy as np
import scipy.io as sio
import h5py
def read_data(mat):
data = sio.loadmat(mat)
S = data['S'].squeeze()
S = np.transpose(S)
return S
def read_large_data(mat):
file = h5py.File(mat, 'r')
S = file['S'][:]
return S
def read_params(mat):
params = sio.loadmat(mat)
params = params['I'].squeeze()
return params
def max_min(S_train, n_train):
S_max = np.max(np.max(S_train[:n_train], axis = 1), axis = 0)
S_min = np.min(np.min(S_train[:n_train], axis = 1), axis = 0)
return S_max, S_min
def scaling(S, S_max, S_min):
S[ : ] = (S - S_min)/(S_max - S_min)
def inverse_scaling(S, S_max, S_min):
S[ : ] = (S_max - S_min) * S + S_min
def zero_pad(S, n):
paddings = np.zeros((S.shape[0], n))
S = np.hstack((S, paddings))
return S
def safe_mkdir(path):
try:
os.mkdir(path)
except OSError:
pass