-
Notifications
You must be signed in to change notification settings - Fork 0
/
E5_cov_syn.py
91 lines (63 loc) · 2.33 KB
/
E5_cov_syn.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
"""
E5 - experiment and presentation -- synthetic streams
"""
import utils
import numpy as np
import matplotlib.pyplot as plt
indexes = utils.selected2_indexes
labels = utils.selected2_measure_names
res = np.load('results/combined_syn.npy')
print(res.shape) # features+label, drifts, reps, chunks
X = res[indexes]
print(X.shape)# f, drifts, reps, chunks
drifts = ['Sudden', 'Gradual', 'Incremental']
fig, axx = plt.subplots(2,3, figsize=(11,7), sharex=True, sharey=True)
axx[0,0].set_ylabel('MEAN ALL')
axx[1,0].set_ylabel('STD')
# cov entire dataset
for drift in range(3):
covs = []
for rep in range(5):
X_all = X[:,drift,rep]
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,drift]
ax.set_title('%s' % (drifts[drift]))
im = ax.imshow(c, cmap='Greys', vmin=0, vmax=1)
# print(np.nanmin(c), np.nanmax(c))
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 drift in range(3):
collected=[]
for i in range(int(X.shape[-1]/window)):
X_w = X[:,:,:,i*window:(i+1)*window]
covs = []
for rep in range(5):
X_temp = X_w[:,drift,rep]
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,drift]
im = ax.imshow(collected_std, cmap='Greys', vmin=0, vmax=0.1)
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_syn.png')
plt.savefig('figures/fig_clf/cov_syn.eps')