-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE5_cov_semi.py
181 lines (127 loc) · 4.6 KB
/
E5_cov_semi.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
"""
E5 - experiment and presentation -- semi-synthetic streams
"""
import utils
import numpy as np
import matplotlib.pyplot as plt
indexes = utils.selected2_indexes
labels = utils.selected2_measure_names
streams = ['australian',
'banknote',
'diabetes',
'german',
'vowel0',
'wisconsin'
]
# Part 1
fig, axx = plt.subplots(2,3, figsize=(11,7.5), sharex=True, sharey=True)
axx[0,0].set_ylabel('MEAN ALL')
axx[1,0].set_ylabel('STD')
res = np.load('results/combined_semi.npy')
print(res.shape) # features+label, drifts, reps, chunks
X = res[indexes]
print(X.shape)
# cov entire dataset
for rep in range(3):
covs = []
for drift in range(2):
X_all = X[:,rep,drift]
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))
covs.append(c)
covs = np.mean(np.array(covs),axis=0)
ax = axx[0,rep]
ax.set_title('%s' % (streams[rep]))
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
window = 25
for rep in range(3):
collected=[]
for i in range(int(X.shape[-1]/window)):
X_w = X[:,:,:,i*window:(i+1)*window]
covs = []
for drift in range(2):
X_temp = X_w[:,rep,drift]
for a in range(len(labels)):
X_temp[a] -= np.mean(X_temp[a])
X_temp[a] /= np.std(X_temp[a])
c = np.abs(np.cov(X_temp))
covs.append(c)
covs = np.mean(np.array(covs),axis=0)
collected.append(covs)
collected = np.array(collected)
collected_std = np.std(collected, axis=0)
ax = axx[1,rep]
# print(np.nanmin(collected_std), np.nanmax(collected_std))
im = ax.imshow(collected_std, cmap='Greys', vmin=0, vmax=0.2)
ax.set_xlim(collected_std.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_semi_1.png')
plt.savefig('figures/fig_clf/cov_semi_1.eps')
# Part 2
fig, axx = plt.subplots(2,3, figsize=(11,7.5), sharex=True, sharey=True)
axx[0,0].set_ylabel('MEAN ALL')
axx[1,0].set_ylabel('STD')
res = np.load('results/combined_semi.npy')
print(res.shape) # features+label, drifts, reps, chunks
X = res[indexes]
print(X.shape)
# cov entire dataset
for rep in range(3,6):
covs = []
for drift in range(2):
X_all = X[:,rep,drift]
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))
covs.append(c)
covs = np.mean(np.array(covs),axis=0)
ax = axx[0,rep-3]
ax.set_title('%s' % (streams[rep]))
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
window = 25
for rep in range(3,6):
collected=[]
for i in range(int(X.shape[-1]/window)):
X_w = X[:,:,:,i*window:(i+1)*window]
covs = []
for drift in range(2):
X_temp = X_w[:,rep,drift]
for a in range(len(labels)):
X_temp[a] -= np.mean(X_temp[a])
X_temp[a] /= np.std(X_temp[a])
c = np.abs(np.cov(X_temp))
covs.append(c)
covs = np.mean(np.array(covs),axis=0)
collected.append(covs)
collected = np.array(collected)
collected_std = np.std(collected, axis=0)
ax = axx[1,rep-3]
# print(np.nanmin(collected_std), np.nanmax(collected_std))
im = ax.imshow(collected_std, cmap='Greys', vmin=0, vmax=0.2)
ax.set_xlim(collected_std.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_semi_2.png')
plt.savefig('figures/fig_clf/cov_semi_2.eps')