-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiments.py
148 lines (120 loc) · 3.55 KB
/
experiments.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
# %%
import numpy as np
import matplotlib.pyplot as plt
from data import get_centers,get_data
from dataset_similarity_tensor import principal_angles_tensors,tensorize_kr,tensorize_thirdordermoment
# %% [markdown]
# ## Tensorization using Kronecker product
# %% [markdown]
# ### Making the variance (of datasets) vary
# %%
n_cluster = 5
n_runs = 10
list_angles = []
list_angles_median = []
for var in range(0,40):
print(var)
pa = []
for _ in range(n_runs):
centers = get_centers(n_cluster=n_cluster)
V = get_data(centers,n_data=5000,var=var)
W = get_data(centers,n_data=5000,var=var)
VV = tensorize_kr(V)
WW = tensorize_kr(W)
pa.append(principal_angles_tensors(VV,WW)[0])
list_angles.append(np.mean(pa))
list_angles_median.append(np.median(pa))
# %%
plt.plot(list_angles,label='mean')
plt.plot(list_angles_median,label='median')
plt.xlabel("Variance of datasets")
plt.ylabel("Principal Angles")
plt.legend()
plt.show()
# %% [markdown]
# ### Making distance between centroids vary
# %%
n_runs = 30
dists = []
list_angles= []
list_angles_median = []
for i in np.linspace(0,1,10):
print(i)
pa = []
dist = 0
for _ in range(n_runs):
centers = get_centers()
centers_w = centers + centers*i
V = get_data(centers,n_data=5000,var=2)
W = get_data(centers_w,n_data=5000,var=2)
VV = tensorize_kr(V)
WW = tensorize_kr(W)
pa.append(principal_angles_tensors(VV,WW)[0])
dist += np.sqrt(np.sum((centers-centers_w)**2))
dists.append(np.mean(dist))
list_angles.append(np.mean(pa))
list_angles_median.append(np.median(pa))
# %%
plt.plot(dists,list_angles,label='mean')
plt.plot(dists,list_angles_median,label='median')
plt.xlabel("Distance")
plt.ylabel("Principal Angles")
plt.legend()
plt.show()
# %% [markdown]
# ## Tensorization via Third order moment
# %%
n_cluster = 5
n_runs = 30
list_angles = []
list_angles_median = []
for var in range(0,40):
print(var)
pa = []
for _ in range(n_runs):
centers = get_centers(n_cluster=n_cluster)
# centers_w = get_centers(n_cluster=n_cluster)
V = get_data(centers,n_data=10000,var=var)
W = get_data(centers,n_data=10000,var=var)
VV = tensorize_thirdordermoment(V).reshape(V.shape[1],-1)
WW = tensorize_thirdordermoment(W).reshape(V.shape[1],-1)
pa.append(principal_angles_tensors(VV.T,WW.T)[0])
list_angles.append(np.mean(pa))
list_angles_median.append(np.median(pa))
# %%
plt.plot(list_angles,label='mean')
plt.plot(list_angles_median,label='median')
plt.xlabel("Variance of datasets")
plt.ylabel("Principal Angles")
plt.legend()
plt.show()
# %%
# %%
n_runs = 10
dists = []
list_angles= []
list_angles_median = []
for i in np.linspace(0,10,11):
print(i)
pa = []
dist = 0
for _ in range(n_runs):
centers = get_centers()
centers_w = centers + centers*i
V = get_data(centers,n_data=100000,var=2)
W = get_data(centers_w,n_data=100000,var=2)
VV = tensorize_thirdordermoment(V).reshape(V.shape[1],-1)
WW = tensorize_thirdordermoment(W).reshape(V.shape[1],-1)
pa.append(principal_angles_tensors(VV.T,WW.T)[0])
dist += np.sqrt(np.sum((centers-centers_w)**2))
dists.append(np.mean(dist))
list_angles.append(np.mean(pa))
list_angles_median.append(np.median(pa))
# %%
plt.plot(dists,list_angles,label='mean')
plt.plot(dists,list_angles_median,label='median')
plt.xlabel("Distance")
plt.ylabel("Principal Angles")
plt.legend()
plt.show()
# %%