-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript_plot_enc_study_graph.py
155 lines (123 loc) · 4.18 KB
/
script_plot_enc_study_graph.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
from utils.results_perser_utils import file_parser
from utils.dynamic_plot_lib_v3 import dynamic_plot
import argparse
import os
import numpy as np
class plots():
def __init__(self,title,grid_on = True):
SIZE = 12
fontsize = {'text':15,
'xtick':SIZE,
'xtick':15,
'title':15,
'axis':SIZE,
'legend':15,
'labels':SIZE,
'figure':SIZE}
self.plot = dynamic_plot(title,'#Encoder Layers','F1',fontsize = fontsize)
self.grid_on = grid_on
def update(self,**arg):
key = arg['label']
f1 = np.array(arg['f1'])
layers = np.array(arg['layers'])
color = 'g'
karg = {'linestyle':'-'}
if 'color' in arg:
color = arg['color']
if 'linestyle' in arg:
karg['linestyle'] = arg['linestyle']
idx = np.argmax(f1)
m_max,f1_max = layers[idx],f1[idx]
self.axis_limit = {'xmin':min(layers),'xmax':max(layers),'ymin':0,'ymax':1}
self.plot.add_plot( key,
color=color,
save=True,
scale = 5,
window = 1,
label = key + " (best layer = %s)"%(m_max),
**karg)
self.plot.add_plot('scatter',
color=color,
save=True,
window = 1,
scale= 70,
framework='scatter'
)
# Add line data
self.plot.update_plot(key,layers,f1)
# Add best point
self.plot.update_plot('scatter',m_max,f1_max,color = color)
# Add fill area on the graph
if 'fill' in arg:
self.plot.addon(key, fill = arg['fill'])
self.plot.show(grid_on =self.grid_on,axis= self.axis_limit)
def save_data_file(self,root):
self.plot.save_data_file(root)
def hold(self):
self.plot.hold_fig()
def compt_sequence_stats(results,seq,field):
networks = range(1,6)
layer = 0
sessions = 'cross_val_' + '%02d'%(seq)
net_values = {}
values = {'mean':[],'std':[],'layers':[]}
for net in networks:
#for layer in layers:
encoder = results[(results.session == sessions) & (results.modelB == net)][field]
mean_value = round(np.mean(encoder[encoder!=-1]),3)
std_value = round(np.std(encoder[encoder!=-1]),3)
values['mean'].append(mean_value)
values['std'].append(std_value)
values['layers'].append(net)
return(values)
def compt_stats(results,field):
networks = range(1,6)
layer = 0
net_values = {}
values = {'mean':[],'std':[],'layers':[]}
for net in networks:
#for layer in layers:
encoder = results[(results.modelA == layer) & (results.modelB == net)][field]
mean_value = round(np.mean(encoder[encoder!=-1]),3)
std_value = round(np.std(encoder[encoder!=-1]),3)
values['mean'].append(mean_value)
values['std'].append(std_value)
values['layers'].append(net)
return(values)
if __name__ == '__main__':
parser = argparse.ArgumentParser("./infer.py")
parser.add_argument(
'--file', '-f',
type=str,
default = "results_paper/encoder_study.txt",
required=False,
help='Dataset to train with. No Default',
)
FLAGS, unparsed = parser.parse_known_args()
# Get File
file_to_parse = FLAGS.file
# Parse file
results = file_parser(file_to_parse)
# Demo: get all data belonging to cross_val_00
f1_scores = compt_stats(results,'F1')
print("Mean F1: {}".format(f1_scores['mean']))
sequences = [0,2,5,6,8]
for seq in sequences:
f1_scores_08 = compt_sequence_stats(results,seq,'F1')
print("Seq {} F1: {}".format(seq,f1_scores_08['mean']))
fig = plots('',grid_on=False)
fig.update(color = 'k',
label='mean',
f1 = f1_scores['mean'],
layers=f1_scores['layers'],
fill = f1_scores['std'],
linestyle='--'
)
fig.update(color = 'k',
label='08',
f1 = f1_scores_08['mean'],
layers=f1_scores_08['layers'],
fill = f1_scores_08['std'],
linestyle='-'
)
fig.hold()