-
Notifications
You must be signed in to change notification settings - Fork 0
/
E5_cov_real.py
152 lines (110 loc) · 3.99 KB
/
E5_cov_real.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
"""
E5 - experiment and presentation -- real-world streams
"""
import utils
import numpy as np
import matplotlib.pyplot as plt
indexes = utils.selected2_indexes
labels = utils.selected2_measure_names
real_streams = [
'covtypeNorm-1-2vsAll',
'electricity',
'poker-lsn-1-2vsAll',
'INSECTS-abrupt',
'INSECTS-gradual',
'INSECTS-incremental'
]
# Part 1
fig, axx = plt.subplots(2,3, figsize=(11,7.5), sharex=True, sharey=True)
axx[0,0].set_ylabel('ALL')
axx[1,0].set_ylabel('STD')
for f_id, f in enumerate(real_streams[:3]):
res = np.load('results/combined_real_%i.npy' % f_id)
X = res[indexes]
# cov entire dataset
X_all = np.copy(X)
for a in range(len(labels)):
X_all[a] -= np.mean(X_all[a])
X_all[a] /= np.std(X_all[a])
c = np.abs(np.cov(X_all))
ax = axx[0, f_id]
ax.set_title('%s' % (f))
# print(np.nanmin(c), np.nanmax(c))
im = ax.imshow(c, cmap='Greys', vmin=0, vmax=1)
ax.set_xticks(range(len(labels)), labels, rotation=90)
ax.set_yticks(range(len(labels)), labels)
cax_2 = axx[0,-1].inset_axes([1.04, 0.0, 0.05, 1.0])
fig.colorbar(im, ax=axx[0,0], cax=cax_2)
# calculate for metachunk
collected=[]
window = 25
for i in range(int(X.shape[-1]/window)):
# print(i*window,(i+1)*window)
X_w = X[:,i*window:(i+1)*window]
# print(X_w.shape)
for a in range(len(labels)):
m = np.mean(X_w[a])
X_w[a] -= m
s = np.std(X_w[a])
X_w[a] /= s
c = np.abs(np.cov(X_w))
collected.append(c)
std_collected = np.std(np.array(collected), axis=0)
# std_collected = np.mean(np.array(collected), axis=0)
ax = axx[1,f_id]
im = ax.imshow(std_collected, cmap='Greys',vmin=0,vmax=0.4)
ax.set_xlim(std_collected.shape[0]-.5,-.5)
ax.set_xticks(range(len(labels)), labels, rotation=90)
ax.set_yticks(range(len(labels)), labels)
cax_2 = axx[1,-1].inset_axes([1.04, 0.0, 0.05, 1.0])
fig.colorbar(im, ax=axx[0,0], cax=cax_2)
plt.tight_layout()
plt.savefig('figures/fig_clf/cov_real_1.png')
plt.savefig('figures/fig_clf/cov_real_1.eps')
# Part 2
fig, axx = plt.subplots(2,3, figsize=(11,7.5), sharex=True, sharey=True)
axx[0,0].set_ylabel('ALL')
axx[1,0].set_ylabel('STD')
for f_id, f in enumerate(real_streams[3:]):
res = np.load('results/combined_real_%i.npy' % f_id)
X = res[indexes]
# cov entire dataset
X_all = np.copy(X)
for a in range(len(labels)):
X_all[a] -= np.mean(X_all[a])
X_all[a] /= np.std(X_all[a])
c = np.abs(np.cov(X_all))
ax = axx[0, f_id]
ax.set_title('%s' % (f))
# print(np.nanmin(c), np.nanmax(c))
im = ax.imshow(c, cmap='Greys', vmin=0, vmax=1)
ax.set_xticks(range(len(labels)), labels, rotation=90)
ax.set_yticks(range(len(labels)), labels)
cax_2 = axx[0,-1].inset_axes([1.04, 0.0, 0.05, 1.0])
fig.colorbar(im, ax=axx[0,0], cax=cax_2)
# calculate for metachunk
collected=[]
window = 25
for i in range(int(X.shape[-1]/window)):
# print(i*window,(i+1)*window)
X_w = X[:,i*window:(i+1)*window]
# print(X_w.shape)
for a in range(len(labels)):
m = np.mean(X_w[a])
X_w[a] -= m
s = np.std(X_w[a])
X_w[a] /= s
c = np.abs(np.cov(X_w))
collected.append(c)
std_collected = np.std(np.array(collected), axis=0)
# std_collected = np.mean(np.array(collected), axis=0)
ax = axx[1,f_id]
im = ax.imshow(std_collected, cmap='Greys',vmin=0,vmax=0.4)
ax.set_xlim(std_collected.shape[0]-.5,-.5)
ax.set_xticks(range(len(labels)), labels, rotation=90)
ax.set_yticks(range(len(labels)), labels)
cax_2 = axx[1,-1].inset_axes([1.04, 0.0, 0.05, 1.0])
fig.colorbar(im, ax=axx[0,0], cax=cax_2)
plt.tight_layout()
plt.savefig('figures/fig_clf/cov_real_2.png')
plt.savefig('figures/fig_clf/cov_real_2.eps')