-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
47 lines (33 loc) · 885 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
37
38
39
40
41
42
43
44
45
46
47
"""Miscellaneous Code."""
import pickle
def save_pickle(data, path):
"""Save a dict to file."""
with open(path, 'wb') as f:
pickle.dump(data, f)
return None
def load_pickle(path):
"""Load a pickle file."""
with open(path, 'rb') as f:
loaded_dict = pickle.load(f)
return loaded_dict
class AverageMeter:
"""AverageMeter."""
def __init__(self):
"""Set zero value."""
self.reset()
def reset(self):
"""Reset."""
self.avg = 0
self.sum = 0
self.count = 0
return None
def update(self, val, n=1):
"""Update value."""
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
return None
def mapping_func(mode='convex'):
"""Returnt he Mapping func."""
if mode == 'convex':
return lambda x: x / (2 - x)