-
Notifications
You must be signed in to change notification settings - Fork 15
/
res_analyse.py
161 lines (127 loc) · 5.42 KB
/
res_analyse.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
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import json
import glob
import ast
#%% read all json files and write results to df
def json_to_df(path, ref=False):
allFiles = glob.glob(path)
df = pd.DataFrame()
for i, file_ in enumerate(allFiles):
print(file_)
with open(file_, 'r') as json_log_file:
# read all lines into list of strings / convert each liast item to a dict
content = [ast.literal_eval(line) for line in json_log_file.readlines()[:-1]]
# convert list of dicts in df
samples = []
for sample in content:
config = sample['config']
if ref:
dict_sample = {'test_iter': sample['test_iter'],
'val_acc': sample['val_acc'],
'val_precision': sample['val_precision'],
'val_recall': sample['val_recall']}
dict_sample.update(config)
else:
history_last_epoch = {k:v[-1] for k,v in sample['history'].items()}
dict_sample = {'test_iter': sample['test_iter']}
dict_sample.update(history_last_epoch)
dict_sample.update(config)
samples.append(dict_sample)
df_temp = pd.DataFrame.from_dict(samples)
cn0_pos_str = file_.find('cn0-')
df_temp['cn0'] = int(file_[cn0_pos_str+4:cn0_pos_str+6])
if i == 0:
df = df_temp.copy(deep=True)
else:
df = pd.concat([df, df_temp], axis=0)
df = df.reset_index(drop=True)
if ref:
df['model'] = 'ref'
else:
df['model'] = 'work'
return df
#%% work/ ref models comparison by unit tests
df_work = json_to_df("logs10_work/*.json")
df_ref = json_to_df("logs_ref/*.json", ref=True)
df = pd.concat([df_ref, df_work[df_ref.columns]], axis=0)
ax = sns.boxplot(x='cn0', y='val_acc', hue='model', data=df)
# Boxplot
for config_var in ['delta_phase', 'cn0']:
for metrics in ['val_acc', 'val_precision', 'val_recall']:
plt.figure()
sns_plot = sns.boxplot(x=config_var, y=metrics, hue='model', data=df)
plt.savefig("result_imgs/boxplot_var-{}_metrics-{}.png".format(config_var, metrics))
#%% work/ ref models comparison by unit tests
df_work_combin = json_to_df("logs10_combin_work/*.json")
df_ref = json_to_df("logs_ref/*.json", ref=True)
df = pd.concat([df_ref, df_work_combin[df_ref.columns]], axis=0)
ax = sns.boxplot(x='cn0', y='val_acc', hue='model', data=df)
# Boxplot
for config_var in ['delta_phase', 'cn0']:
for metrics in ['val_acc', 'val_precision', 'val_recall']:
plt.figure()
sns_plot = sns.boxplot(x=config_var, y=metrics, hue='model', data=df)
plt.savefig("result_imgs/boxplot_var-{}_metrics-{}_combin.png".format(config_var, metrics))
#%% work models comparison by discretization level
dfs = []
folders = glob.glob("logs*_work")[:-1]
discrs = []
for folder in folders:
df_temp = json_to_df(folder + "/*.json")
if folder[5] == '0':
discr_level = int(folder[4:6])
else:
discr_level = int(folder[4:5])
df_temp['discr'] = int(folder[4:5])
dfs.append(df_temp)
df = pd.concat(dfs, axis=0)
ax = sns.boxplot(x='cn0', y='val_acc', hue='discr', data=df)
# Boxplot
for config_var in ['delta_phase', 'cn0']:
for metrics in ['val_acc', 'val_precision', 'val_recall']:
plt.figure()
sns_plot = sns.boxplot(x=config_var, y=metrics, hue='discr', data=df)
plt.savefig("result_imgs/boxplot_var-{}_metrics-{}_combin.png".format(config_var, metrics))
#%% TI = 1 ms. work models comparison by discretization level
dfs = []
folders = glob.glob("logs_ti1/logs*")
discrs = []
for folder in folders:
df_temp = json_to_df(folder + "/*.json")
pos_substr = folder.find('\logs')
if folder[pos_substr+6 : pos_substr+7] == '0':
discr_level = int(folder[pos_substr+5 : pos_substr+7])
df_temp['discr'] = int(folder[pos_substr+5 : pos_substr+7])
else:
discr_level = int(folder[pos_substr+5 : pos_substr+6])
df_temp['discr'] = int(folder[pos_substr+5 : pos_substr+6])
dfs.append(df_temp)
df = pd.concat(dfs, axis=0)
df['val_acc'] = df['val_acc'] * 100
ax = sns.boxplot(x='cn0', y='val_acc', hue='discr', data=df)
# Boxplot
#for config_var in ['delta_phase', 'cn0']:
# for metrics in ['val_acc', 'val_precision', 'val_recall']:
# plt.figure()
# ax = sns.factorplot(x=config_var, y=metrics, hue='discr', data=df, kind="bar")
# plt.ylim(0.97, 1)
# #ax.set(yscale = "log")
# plt.savefig("result_imgs/imgs_ti1/discr/barplot_var-{}_metrics-{}_combin.png".format(config_var, metrics))
#%%
config_var = 'cn0'
metrics = 'val_acc'
plt.figure()
ax = sns.factorplot(x=config_var, y=metrics, hue='discr', data=df, kind="bar", palette="Paired")
plt.ylim(60, 100)
#ax.set(yscale = "log")
plt.savefig("result_imgs/imgs_ti1/barplot_var-{}_metrics-{}_combin.png".format(config_var, metrics))
config_var = 'delta_phase'
metrics = 'val_acc'
plt.figure()
ax = sns.factorplot(x=config_var, y=metrics, hue='discr', data=df, kind="bar", palette="Paired")
plt.ylim(70, 100)
#ax.set(yscale = "log")
plt.savefig("result_imgs/imgs_ti1/barplot_var-{}_metrics-{}_combin.png".format(config_var, metrics))