-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path15_icml_plot.py
More file actions
375 lines (316 loc) · 13.2 KB
/
15_icml_plot.py
File metadata and controls
375 lines (316 loc) · 13.2 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
import matplotlib
matplotlib.use('QT4Agg')
# change to type 1 fonts!
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
import matplotlib.pyplot as plt
import numpy as np
import pylab as pl
import scipy.io as io
def plot_icml_pgm_results():
files = [2.5,5,10,15,20,30]
# annotation results
rnames = ['SSVM (FS)','SSVM (Full)','HMAD (FS)','HMAD (Full)']
rscores = np.zeros((len(rnames),len(files)))
rvars = np.zeros((len(rnames),len(files)))
# anomaly detection results
anames = ['SSVM (FS)','SSVM (Full)','OcSvm Spectrum (1)','OcSvm Spectrum (2)','OcSvm Spectrum (3)', \
'OcSvm Spectrum (FS)','HMAD (FS)','HMAD (Full)']
ascores = np.zeros((len(anames),len(files)))
avars = np.zeros((len(anames),len(files)))
for f in range(len(files)):
data = io.loadmat('/home/nicococo/mnt/Documents/2015_icml/icml_pgm_d{0}'.format(str(files[f])))
res = data['res']
auc = data['auc']
for idx in range(len(rnames)):
m = np.mean(res[rnames[idx]][0][0][:,0])
v = np.std(res[rnames[idx]][0][0][:,0])
rscores[idx,f] = m
rvars[idx,f] = v
print (rnames[idx], m, v)
for idx in range(len(anames)):
m = np.mean(auc[anames[idx]][0][0])
v = np.std(auc[anames[idx]][0][0])
ascores[idx,f] = m
avars[idx,f] = v
print (anames[idx], m, v)
plt.figure(1)
cnt = 0
names = []
style = ['-','-','-','-','-','--','--','--']
marker = ['D','^','p','o','D','o','s','s']
colors = [[0.,0.5,0.],[0.,0.75,0.],[0.,1.,0.],'g','m','b','k']
for idx in [2,3,4,5,6,7]:
names.append(anames[idx])
if not idx==7 and not idx==6:
plt.errorbar(files, ascores[idx,:], yerr=avars[idx,:], \
fmt=style[cnt], color=colors[cnt], linewidth=4, alpha=0.7-(cnt*0.1), marker=marker[cnt], markersize=8)
else:
plt.errorbar(files, ascores[idx,:], yerr=avars[idx,:], \
fmt=style[cnt], color=colors[cnt], linewidth=idx-2, alpha=1.0, marker=marker[cnt], markersize=8)
plt.xticks(files, ['2.5%','5%','10%','15%','20%','30%'], fontsize=16)
plt.yticks([0.58,0.6,0.7,0.8,0.9,1.0,1.02], ['','0.6','0.7','0.8','0.9','1.0',''], fontsize=16)
cnt += 1
plt.ylabel('Detection accuracy [in AUC]',fontsize=18)
plt.xlabel('Percentage of anomalous data',fontsize=18)
#names[-2] = 'Hidden Markov Anomaly Detection (FS)'
#names[-1] = 'Hidden Markov Anomaly Detection'
names[-1] = 'HMAD'
legnames = []
for name in names:
if 'OcSvm' in name:
name = 'OC-SVM' + name[5:]
print name
legnames.append(name)
plt.legend(legnames,loc=3,fontsize=18,framealpha=0.7,fancybox=True)
plt.show()
print '.....................................................'
print np.array(rscores[[1,3],:]).T
print '.....................................................'
print np.array(rvars[[1,3],:]).T
print '.....................................................'
print ascores[[2,3,4,7],:]
print '.....................................................'
print('finished')
def plot_icml_wind_results():
files = [2.5,5.0,10.0,15.0,20.0,30.0]
# annotation results
rnames = ['SSVM','HMAD']
rnames = ['HMAD']
rscores = np.zeros((len(rnames),len(files)))
rvars = np.zeros((len(rnames),len(files)))
# anomaly detection results
anames = ['SSVM','OcSvm (Hist 4)','OcSvm (Hist 8)','OcSvm (Hist 12)','HMAD']
anames = ['OcSvm (Hist 4)','OcSvm (Hist 8)','OcSvm (Hist 16)','HMAD']
ascores = np.zeros((len(anames),len(files)))
avars = np.zeros((len(anames),len(files)))
for f in range(len(files)):
data = io.loadmat('/home/nicococo/mnt/Documents/2015_icml/15_icml_wind_c{0}'.format(str(files[f])))
res = data['res']
auc = data['auc']
for idx in range(len(rnames)):
m = np.mean(res[rnames[idx]][0][0][:,0])
v = np.std(res[rnames[idx]][0][0][:,0])
rscores[idx,f] = m
rvars[idx,f] = v
print (rnames[idx], m, v)
for idx in range(len(anames)):
m = np.mean(auc[anames[idx]][0][0])
v = np.std(auc[anames[idx]][0][0])
ascores[idx,f] = m
avars[idx,f] = v
print (anames[idx], m, v)
plt.figure(1)
cnt = 0
names = []
style = ['-','-','-','--','D','o','s']
marker = ['D','^','p','o','D','o','s']
colors = [[0.1,0.4,0.6],[0.1,0.5,0.8],[0.2,0.8,1.0],'b','m','y','k']
for idx in [0,1,2,3]:
names.append(anames[idx])
if not idx==3:
plt.errorbar(files, ascores[idx,:], yerr=avars[idx,:], \
fmt=style[cnt], color=colors[cnt], elinewidth=1, linewidth=2+idx*2, alpha=0.7-(cnt*0.2), marker=marker[cnt], markersize=8)
else:
plt.errorbar(files, ascores[idx,:], yerr=avars[idx,:], \
fmt=style[cnt], color=colors[cnt], elinewidth=1, linewidth=5, alpha=0.9, marker=marker[cnt], markersize=8)
plt.xticks(files, ['2.5%','5%','10%','15%','20%','30%'], fontsize=16)
plt.yticks([0.58,0.6,0.7,0.8,0.9,1.0,1.02], ['','0.6','0.7','0.8','0.9','1.0',''], fontsize=16)
cnt += 1
plt.ylabel('Detection accuracy [in AUC]',fontsize=18)
plt.xlabel('Percentage of anomalous data',fontsize=18)
names[:3] = ['OC-SVM (Hist 4)','OC-SVM (Hist 8)','OC-SVM (Hist 16)']
#names[-1] = 'Hidden Markov Anomaly Detection'
plt.legend(names,loc=4, fontsize=18, fancybox=True, framealpha=0.7)
plt.show()
print('finished')
def plot_icml_toy_results():
filename = '/home/nicococo/mnt/Documents/2015_icml/15_icml_toy_runtime_b0'
# filename = '/home/nicococo/mnt/Documents/2015_icml/15_icml_toy_ad_b0'
# filename = '/home/nicococo/mnt/Documents/2015_icml/15_icml_toy_adfrac_b0'
# anomaly detection results
data = io.loadmat('{0}'.format(filename))
blocks = data['BLOCKS'][0][::-1]
blocks = data['BLOCKS'][0] # for ad experiment
if 'adfrac' in filename:
blocks = [0.025, 0.05, 0.1, 0.15, 0.2, 0.3] # for adfrac experiment
print blocks
lens = len(data['BLOCKS'][0])
reps = float(data['REPS'][0][0])
print reps
names = data['names']
print names
if 'runtime' in filename:
aucs = data['times']
else:
aucs = data['aucs']
stds = data['stds']
varis = data['varis']
print aucs
plt.figure(1)
style = ['-','--','-','.-','--','-','-','-','-','--']
marker = ['D','o','^','D','s','^','D','s','s','o']
colors = ['r','b','m','m','m','c','c','c','g','g']
alphas = [1. ,0.9,.8 ,.6 ,.4 ,.8 ,.6 ,.4 ,1. ,.6 ]
widths = [2 ,4 ,1 ,4 ,8 ,1 ,4 ,8 ,1 ,8 ]
remain_idx = [0,1,3,6,8]
for i in range(len(names)):
if not i in remain_idx:
continue
if i<len(names)-2:
names[i] = names[i][:len(names[i])-5]
plt.errorbar(blocks, aucs[i,:], yerr=stds[i,:], \
fmt=style[i], color=colors[i], linewidth=widths[i], alpha=alphas[i], marker=marker[i], markersize=10)
#plt.title('Anomaly Detection', fontsize=28)
if '_ad_' in filename:
plt.xscale('log')
plt.xticks(blocks, ['0%','2%','5%','10%','20%','40%','60%','100%'], fontsize=18)
plt.xlabel('Percentage of disorganization',fontsize=22)
plt.yticks([0.0,0.2,0.4,0.6,0.8,1.0,1.02], ['','0.2','0.4','0.6','0.8','1.0',''], fontsize=18)
plt.ylabel('Detection accuracy [in AUC]',fontsize=22)
if 'adfrac' in filename:
plt.xticks(blocks, ['2.5%','5%','10%','15%','20%','30%'], fontsize=18)
plt.xlim((0.025,0.3))
plt.xlabel('Percentage of anomalous data',fontsize=22)
plt.yticks([0.0,0.2,0.4,0.6,0.8,1.0,1.02], ['','0.2','0.4','0.6','0.8','1.0',''], fontsize=18)
plt.ylabel('Detection accuracy [in AUC]',fontsize=22)
if 'runtime' in filename:
plt.yscale('log')
plt.xticks(blocks, fontsize=18)
plt.xlabel('Number of training examples',fontsize=22)
plt.yticks([0.00001,0.001,0.01,1.0,1000.], fontsize=18)
plt.ylabel('Time in [sec]',fontsize=22)
names[1] = 'HMAD'
names[4] += ')'
names = names[remain_idx]
legnames = []
for name in names:
if 'OcSvm' in name:
name = 'OC-SVM' + name[5:]
if 'Linear' in name:
name = name[:len(name)-6]
print name
legnames.append(name)
plt.legend(legnames,loc=4, fancybox=True, framealpha=0.7, fontsize=20)
plt.show()
def plot_icml_toy_fisher_results():
filename = '15_icml_toy_ad_c0'
# filename = '15_icml_toy_adfrac_c0'
# anomaly detection results
data = io.loadmat('{0}'.format(filename))
blocks = data['BLOCKS'][0][::-1]
blocks = data['BLOCKS'][0] # for ad experiment
if 'adfrac' in filename:
blocks = [0.025, 0.05, 0.1, 0.15, 0.2, 0.3] # for adfrac experiment
print blocks
lens = len(data['BLOCKS'][0])
reps = float(data['REPS'][0][0])
print reps
names = data['names']
print names
if 'runtime' in filename:
aucs = data['times']
else:
aucs = data['aucs']
stds = data['stds']
varis = data['varis']
print aucs
plt.figure(1)
style = ['-','--','-','.-']
marker = ['D','o','D','D']
colors = ['r','b','r','m']
alphas = [1. ,0.9, .6 ,.6 ]
widths = [2 ,4 ,1 ,1 ]
plt.fill_between(blocks, aucs[2, :], aucs[3, :], color=[0.7, 0.7, 0.7], alpha=0.5)
remain_idx = [2, 3, 1]
for i in range(len(names)):
if not i in remain_idx:
continue
plt.errorbar(blocks, aucs[i, :], yerr=stds[i, :], \
fmt=style[i], color=colors[i], linewidth=widths[i], alpha=alphas[i], marker=marker[i], markersize=10)
if '_ad_' in filename:
plt.xscale('log')
plt.xticks(blocks, ['0%','2%','5%','10%','20%','40%','60%','100%'], fontsize=18)
plt.xlabel('Percentage of disorganization',fontsize=22)
plt.yticks([0.4,0.6,0.8,1.0,1.02], ['0.4','0.6','0.8','1.0',''], fontsize=18)
plt.ylabel('Detection accuracy [in AUC]',fontsize=22)
if 'adfrac' in filename:
plt.xticks(blocks, ['2.5%','5%','10%','15%','20%','30%'], fontsize=18)
plt.xlim((0.025,0.3))
plt.xlabel('Percentage of anomalous data',fontsize=22)
plt.yticks([0.0,0.2,0.4,0.6,0.8,1.0,1.02], ['','0.2','0.4','0.6','0.8','1.0',''], fontsize=18)
plt.ylabel('Detection accuracy [in AUC]',fontsize=22)
names = list()
names.append('HMAD')
names.append('Fisher Kernel Upper Bound')
names.append('Fisher Kernel Lower Bound')
plt.legend(names, loc=3, fancybox=True, framealpha=0.7, fontsize=20)
plt.show()
def plot_icml_toy_states_results():
filename = '15_icml_toy_states_c0'
# anomaly detection results
data = io.loadmat('{0}'.format(filename))
blocks = data['BLOCKS'][0][::-1]
blocks = data['BLOCKS'][0] # for ad experiment
print blocks
lens = len(data['BLOCKS'][0])
reps = float(data['REPS'][0][0])
print reps
names = data['names']
print names
if 'runtime' in filename:
aucs = data['times']
else:
aucs = data['aucs']
stds = data['stds']
varis = data['varis']
print aucs
plt.figure(1)
style = ['--']
marker = ['o']
colors = ['b']
alphas = [0.9]
widths = [4]
for i in range(len(names)):
plt.errorbar(blocks, aucs[i, :], yerr=stds[i, :], \
fmt=style[i], color=colors[i], linewidth=widths[i], alpha=alphas[i], marker=marker[i], markersize=10)
plt.xticks(blocks, fontsize=18)
plt.xlabel('Number of hidden states', fontsize=22)
plt.yticks([0.4, 0.6, 0.8, 1.0, 1.02], ['0.4','0.6','0.8','1.0',''], fontsize=18)
plt.ylabel('Detection accuracy [in AUC]', fontsize=22)
names = list()
names.append('HMAD')
plt.legend(names, loc=3, fancybox=True, framealpha=0.7, fontsize=20)
plt.show()
def plot_icml_toy_seqs():
from toydata import ToyData
lens = 600
blocks = [1,2,5,10,20,40,60,100]
data = []
lbl = []
for i in blocks:
(exm, label, marker) = ToyData.get_2state_anom_seq(lens, 120, anom_prob=1.0, num_blocks=i)
data.append(exm)
lbl.append(label)
plt.figure(1)
style = ['-','--','-','.-','--','-','-','-','-','--']
marker = ['D','o','^','D','s','^','D','s','s','o']
colors = ['r','b','m','m','m','c','c','c','g','g']
alphas = [1. ,0.9,.8 ,.6 ,.4 ,.8 ,.6 ,.4 ,1. ,.6 ]
widths = [2 ,4 ,1 ,4 ,8 ,1 ,4 ,8 ,1 ,8 ]
ys = []
for i in [0,-1]:
ys.append(i*10)
plt.plot(range(lens), np.array(data[i]).T + ys[-1], \
color='r', linewidth=2, alpha=0.6, marker='')
plt.plot(range(lens), np.array(lbl[i]).T + ys[-1], \
color='k', linewidth=2, alpha=0.8, marker='')
#plt.yscale('log')
plt.xticks([0,300,600], ['0','300','600'], fontsize=16)
plt.yticks(ys, ['0%','100%'], fontsize=16)
plt.ylabel('Percentage of disorganization',fontsize=18)
plt.xlabel('Sequence position',fontsize=18)
plt.legend(['Noisy observations','True state sequence'], fontsize=18, fancybox=True, framealpha=0.7)
plt.show()
if __name__ == '__main__':
plot_icml_toy_results()