-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore_stats.py
40 lines (25 loc) · 1.31 KB
/
store_stats.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
import pickle
def save_obj(obj, name ):
with open('obj/'+ name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def store_stats(S,n,settings,F_n,config_log_likelihood_n,stateSeq_n,dist_struct_n,theta_n,hyperparams_n):
if n%settings['storeEvery']==0 & n>=settings['saveMin']:
storeCount = n % settings['saveEvery']
try:
storeCount
except NameError:
storeCount = settings.saveEvery
S['storeCount']['stateSeq'] = stateSeq_n
S['storeCount']['dist_struct'] = dist_struct_n
S['storeCount']['F'] = F_n
S['storeCount']['config_log_likelihood'] = config_log_likelihood_n
S['storeCount']['theta'] = theta_n
S['storeCount']['hyperparams'] = hyperparams_n
if n% settings.saveEvery==0:
# Save stats:
if 'filename' in settings.keys():
filename = settings['saveDir']+'/'+settings['filename']+'iter'+str(n)+'trial'+str(settings['trial']) # create filename for current iteration
else:
filename = settings['saveDir']+'/IBPHMMstats'+'iter'+str(n)+'trial'+str(settings['trial']) # create filename for current iteration
save_obj(S,filename) # save current statistics
print('Iteration: '+ str(n))