-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_dataset.py
224 lines (168 loc) · 7.58 KB
/
plot_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 10 06:08:38 2018
@author: mimbres
"""
q=np.ascontiguousarray(dt_mm[:, 4:8]).view(np.uint32).flatten()
total_cnt = 0
for file_count, fpath in enumerate(glob.glob(os.path.join(TR_LOG_DATA_ROOT, "*.csv"))):
with open(fpath) as f:
cnt_this = (sum(1 for line in f)) - 1
total_cnt += cnt_this
print(file_count)
if total_cnt>=1715392750:
nth_line = total_cnt - 1715392750
print('FOUND!!! in file {} line {}'.format(fpath, nth_line))
break
#FOUND!!! in file /mnt/ssd2/SeqSkip/training_set/log_6_20180918_000000000000.csv line 1195205
df = pd.read_csv('/mnt/ssd2/SeqSkip/training_set/log_6_20180918_000000000000.csv', index_col=False, header=0)
total_cnt = 1715392735 - 1 +1195221
#%% stats from test data
import pandas as pd
import glob
TS_LOG_DATA_ROOT = '/mnt/ssd3/test_set/'
for fpath in glob.glob(os.path.join(TS_LOG_DATA_ROOT, "*.csv")):
#print("Collecting data from" + fpath)
df = pd.read_csv(fpath, index_col=False, header=0) # usecols=[0] takes only track_ids
#하다맘. 총 19개라치면 9개가 support, 10개가 query인거 확인해서 더안봐도됨
#%%
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from tqdm import tqdm
from utils.save_load_config import load_config
config_fpath = "./config_init_dataset.json"
config = load_config(config_fpath)
TR_LOG_MEMMAP_DAT_PATH = config.output_data_root + "tr_log_memmap.dat"
TR_LOG_DATA_SHAPE = (2072002577, 23)
dt_mm = np.memmap(TR_LOG_MEMMAP_DAT_PATH, dtype='uint8', mode='r', shape=TR_LOG_DATA_SHAPE)
#%% bar-graph of date
date_all = np.ascontiguousarray(dt_mm[:, 4:8]).view(np.uint32).flatten()
dates, play_counts = np.unique(date_all, return_counts=True)
del date_all
fig = plt.figure
plt.bar(np.arange(len(play_counts)), play_counts)
x_index = np.arange(len(play_counts), step=50)
plt.xticks(x_index, dates.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title('date')
#%% Bar-graph: stats of skip/nskip
TR_SESSION_SPLIT_IDX_PATH = config.output_data_root + "tr_session_split_idx.npy"
_sess_split = np.load(TR_SESSION_SPLIT_IDX_PATH)
session_start_end_idx = np.empty(shape=(len(_sess_split), 2), dtype=np.uint32)
session_start_end_idx[:,0] = _sess_split
session_start_end_idx[:,1] = np.r_[_sess_split[1:], len(dt_mm)-1]
_total_sess_len=0
for i in range(len(session_start_end_idx)):
_total_sess_len += (session_start_end_idx[i,1] - session_start_end_idx[i,0])
avg_sess_len = _total_sess_len / len(session_start_end_idx)
total_skip = 0; total_notskip = 0; total = 0
min_skip = 20; max_skip = 0; avg_skip = 0
min_sess_len = 20; max_sess_len = 0
for i, si in enumerate(tqdm(session_start_end_idx)):
sum_skip_insess = sum(dt_mm[si[0]:si[1], 12])
sub_total = len(dt_mm[si[0]:si[1], 12])
total_skip += sum_skip_insess
total_notskip += (sub_total - sum__skip_insess)
total += sub_total
if sum_skip_insess < min_skip:
min_skip = sum_skip_insess
if sum_skip_insess > max_skip:
max_skip = sum_skip_insess
if sub_total < min_sess_len:
min_sess_len = sub_total
if sub_total > max_sess_len:
max_sess_len = sub_total
avg_skip = total_skip/len(session_start_end_idx)
print('\n total_skip:{},\n total_notskip:{},\n total:{},\n min_skip:{},\n max_skip:{},\n avg_skip:{},\n min_sess_len:{},\n max_sess_len:{}'.format(
total_skip, total_notskip, total, min_skip, max_skip, avg_skip, min_sess_len, max_sess_len))
# total skip, notskip
plt.figure()
labels = ['skip', 'notskip']
ax = plt.bar(labels,[total_skip, total_notskip])
plt.text(0-.25,200000, str(total_skip), fontsize=14,verticalalignment='bottom')
plt.text(1-.25,1, str(total_notskip), fontsize=14,verticalalignment='bottom')
plt.title('total = {}'.format(total))
# min max avg skip
plt.figure()
labels = ['min\nskip', 'avgerage\nskip', 'max\nskip', 'min\nsession\nlength','average\nsession\nlength','max\nsession\nlength']
plt.bar(labels, [min_skip, avg_skip, max_skip, min_sess_len, avg_sess_len, max_sess_len])
plt.yticks(np.arange(0,21,2))
plt.grid(linestyle='--', axis='y')
plt.title('number of skips in sessions')
#%% histogram of n_seekfwd, n_seekback
import matplotlib.pyplot as plt
import numpy as np
# n_seekfwd
n_seekfwd, cnt = np.unique(mtrain_loader.dataset.dt_mm[:,9], return_counts=True)
plt.figure(); plt.bar(np.arange(len(cnt)), cnt)
x_index = np.arange(len(cnt), step=50)
plt.xticks(x_index, n_seekfwd.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title("histogram of n_seekfwd(all)")
n_seekfwd = n_seekfwd[1:]; cnt = cnt[1:]
plt.figure(); plt.bar(np.arange(len(cnt)), cnt)
x_index = np.arange(len(cnt), step=50)
plt.xticks(x_index, n_seekfwd.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title("histogram of n_seekfwd(NOT 0)")
n_seekfwd = n_seekfwd[5:]; cnt = cnt[5:]
plt.figure(); plt.bar(np.arange(len(cnt)), cnt)
x_index = np.arange(len(cnt), step=50)
plt.xticks(x_index, n_seekfwd.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title("histogram of n_seekfwd(>5)")
# n_seekback
n_seekback, cnt = np.unique(mtrain_loader.dataset.dt_mm[:,10], return_counts=True)
plt.figure(); plt.bar(np.arange(len(cnt)), cnt)
x_index = np.arange(len(cnt), step=50)
plt.xticks(x_index, n_seekback.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title("histogram of n_seekback(all)")
n_seekback = n_seekback[1:]; cnt = cnt[1:]
plt.figure(); plt.bar(np.arange(len(cnt)), cnt)
x_index = np.arange(len(cnt), step=50)
plt.xticks(x_index, n_seekback.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title("histogram of n_seekback(NOT 0)")
n_seekback = n_seekback[5:]; cnt = cnt[5:]
plt.figure(); plt.bar(np.arange(len(cnt)), cnt)
x_index = np.arange(len(cnt), step=50)
plt.xticks(x_index, n_seekback.astype(str)[x_index], fontsize=12, rotation=45)
plt.ylabel('play count'); plt.title("histogram of n_seekback(>5)")
#%% Distillation plot
target = SMT_Enc(x_feat_T)
target2 = SMT_EncFeat(x_feat_T)
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(3,4,1)
plt.plot(target.detach().cpu().numpy()[1,:,8])
plt.title('dilated_conv_Encoder output: S8(skip=0)')
plt.subplot(3,4,2)
plt.plot(target2.detach().cpu().numpy()[1,:,8])
plt.title('(L-1) layer of classifier output S8(skip=0)')
plt.subplot(3,4,5)
plt.plot(target.detach().cpu().numpy()[1,:,7])
plt.title('dilated_conv_Encoder output: S7(skip=0)')
plt.subplot(3,4,6)
plt.plot(target2.detach().cpu().numpy()[1,:,7])
plt.title('(L-1) layer of classifier output S7(skip=0)')
plt.subplot(3,4,9)
plt.plot(target.detach().cpu().numpy()[1,:,9])
plt.title('dilated_conv_Encoder output: S9(skip=1)')
plt.subplot(3,4,10)
plt.plot(target2.detach().cpu().numpy()[1,:,9])
plt.title('(L-1) layer of classifier output S9(skip=1)')
plt.subplot(3,4,3)
plt.plot(target.detach().cpu().numpy()[1,:,12])
plt.title('dilated_conv_Encoder output: Q3(skip=0)')
plt.subplot(3,4,4)
plt.plot(target2.detach().cpu().numpy()[1,:,12])
plt.title('(L-1) layer of classifier output Q3(skip=0)')
plt.subplot(3,4,7)
plt.plot(target.detach().cpu().numpy()[1,:,11])
plt.title('dilated_conv_Encoder output: Q2(skip=1)')
plt.subplot(3,4,8)
plt.plot(target2.detach().cpu().numpy()[1,:,11])
plt.title('(L-1) layer of classifier output Q2(skip=1)')
plt.subplot(3,4,11)
plt.plot(target.detach().cpu().numpy()[1,:,10])
plt.title('dilated_conv_Encoder output: Q1(skip=1)')
plt.subplot(3,4,12)
plt.plot(target2.detach().cpu().numpy()[1,:,10])
plt.title('(L-1) layer of classifier output Q1(skip=1)')