-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
36 lines (29 loc) · 920 Bytes
/
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
class NotImplementedError(Exception):
pass
class Normalize():
def __init__(self, mn, mx, norm_type=None):
self.mn = mn
self.mx = mx
if norm_type is None:
norm_type = 'identity'
if norm_type.lower() not in ['identity', '-11']:
raise NotImplementedError('Only identity and -11 are implemented')
self.norm_type = norm_type.lower()
def fit(self, x):
mn, mx = self.mn, self.mx
if self.norm_type == '-11':
return 2*(x-mn)/(mx-mn)-1
else:
return x
def inverse(self, x):
mn, mx = self.mn, self.mx
if self.norm_type == '-11':
return (x+1)/2 * (mx-mn) + mn
else:
return x
def get_scale(self):
mn, mx = self.mn, self.mx
if self.norm_type == '-11':
return 2/(mx-mn)
else:
return 1