-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot_PCA_parameters_CIFAR100.py
127 lines (89 loc) · 3.76 KB
/
plot_PCA_parameters_CIFAR100.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
import os
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
def create_results_array(values, channels):
mean = np.mean(values, axis=channels, keepdims=True)
std = np.std(values, axis=channels, keepdims=True)
x,y = mean.shape
results = np.zeros((x, 2*y))
for i in range(0, y):
results[:, 2*i] = mean[:,i]
results[:, 2*i+1] = std[:,i]
return results
P = range(5, 105, 5)
G = [1]
runs = [0,1,2]
embeddings = ['CLIP', 'IMAGEBIND']
EXPERIMENT_PATH = os.path.join('experiments', 'CIFAR100')
colors = {
'diag' : 'red',
'full' : 'blue'
}
labels = {
'diag' : 'SDGM-D',
'full' : 'SDGM-F'
}
idx = 0
plt.figure(figsize=(8,8))
#########
#SDGM
########
cov_types = ['full', 'diag']
'''for embedding in embeddings:
for cov_type in cov_types:
general_results = []
for g in G:
for p in P:
complete_results = []
for run in runs:
df_path = os.path.join(EXPERIMENT_PATH, embedding, 'SDGM','results', 'Features_P_{}_G_{}_cov_{}run_{}.csv'.format(p,g, cov_type, run))
df = pd.read_csv(df_path, sep=';')
values = df.values
d = values[0][2]
complete_results.append(d)
complete_results = np.stack(complete_results, axis=0)
general_results.append(complete_results)
general_results = np.stack(general_results, axis=0)
general_results = general_results.reshape((len(G), len(P), len(runs)), order = 'F')
means = np.mean(general_results, axis=2)
std = np.std(general_results, axis=2)
test_array = np.ravel([means,std],'F').reshape((len(G), 2*len(P)))
index = pd.MultiIndex.from_product([P,['avg','std']])
df = pd.DataFrame(test_array, index = G, columns = index)
print(df)
#df.to_csv(os.path.join('results', 'CIFAR100_SDGM_cov_{}.csv'.format(cov_type)), sep=';')
if embedding == 'CLIP':
plt.plot(P, means.squeeze(), color=colors[cov_type], marker='o',linewidth=2, markersize=8, label = '(C.) {}'.format(labels[cov_type]))
else:
plt.plot(P, means.squeeze(), color=colors[cov_type], linestyle='dashed', marker='o',linewidth=2, markersize=8, label = '(I.) {}'.format(labels[cov_type]))'''
for embedding in embeddings:
general_results = []
for g in G:
for p in P:
complete_results = []
for run in runs:
df_path = os.path.join(EXPERIMENT_PATH, embedding, 'DGMMC','results', 'Features_P_{}_G_{}_run_{}.csv'.format(p,g, run))
df = pd.read_csv(df_path, sep=';')
values = df.values
d = values[0][2]
complete_results.append(d)
complete_results = np.stack(complete_results, axis=0)
general_results.append(complete_results)
general_results = np.stack(general_results, axis=0)
general_results = general_results.reshape((len(G), len(P), len(runs)), order = 'F')
means = np.mean(general_results, axis=2)
std = np.std(general_results, axis=2)
test_array = np.ravel([means,std],'F').reshape((len(G), 2*len(P)))
index = pd.MultiIndex.from_product([P,['avg','std']])
df = pd.DataFrame(test_array, index = G, columns = index)
print(df)
#df.to_csv(os.path.join('results', 'CIFAR100_DGMMC.csv'), sep=';')
if embedding == 'CLIP':
plt.plot(P, means.squeeze(), color='black', marker='o',linewidth=2, markersize=8, label = embedding)
else:
plt.plot(P, means.squeeze(), color='black', linestyle='dashed', marker='o',linewidth=2, markersize=8, label = embedding)
plt.xlabel('Cumulative variance ratio (in %)')
plt.ylabel('Eigenvectors conserved (d)')
plt.legend()
plt.show()