Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 8d2f1394 authored by Alexis Brenon's avatar Alexis Brenon
Browse files

Add script to extract and plot datas

parent b57fb08c
......@@ -101,7 +101,7 @@ local args = {
learn_start = 100,
update_freq = 3,
minibatch_size = %d,
minibatch_size = 16,
n_replay = 1,
rescale_r = false,
......@@ -117,7 +117,7 @@ local args = {
discount = 0.99,
clip_delta = 1,
target_q = %d,
target_q = 4096,
wc = 0,
},
},
......
#! /usr/bin/env python3.4
import re
import glob
RE_ARGS_TARGET = re.compile(
'\s*'+
'target_q = (?P<targetQ>[^,]*),'
)
RE_ARGS_BATCH = re.compile(
'\s*'+
'minibatch_size = (?P<batchSize>[^,]*),'
)
RE_GENERIC_METRICS = re.compile(
'(?:[^#]*##){3} Generic metrics value;'+
'(?P<step>[-\d.]*);'+
'(?P<totalTime>[-\d.]*);'+
'(?P<trainingTime>[-\d.]*);'+
'(?P<trainingRate>[-\d.]*);'+
'(?P<testingTime>[-\d.]*);'+
'(?P<testingRate>[-\d.]*)'
)
RE_RL_METRICS = re.compile(
'(?:[^#]*##){3} RL metrics value;'+
'(?P<totalReward>[-\d.]*);'+
'(?P<numEpisodes>[-\d.]*);'+
'(?P<rewardPerEp>[-\d.]*)'
)
RE_CLASS_METRICS = re.compile(
'(?:[^#]*##){3} Classification metrics value;'+
'(?P<accuracy>[-\d.]*);'+
'(?P<averageAccuracy>[-\d.]*);'+
'(?P<macroPrecision>[-\d.]*);'+
'(?P<macroRecall>[-\d.]*);'+
'(?P<macroF1>[-\d.]*)'
)
def main():
datas = parse_datas()
compute_convergence_metric(datas)
print_datas(datas)
def parse_datas():
datas = {}
for directory in glob.glob('????-??-??T??:??:??'):
targetQ = None
batchSize = None
with open(directory + "/args.lua") as args:
for line in args.readlines():
match = RE_ARGS_TARGET.match(line)
if match:
targetQ = int(match.group(1))
match = RE_ARGS_BATCH.match(line)
if match:
batchSize = int(match.group(1))
metrics = []
with open(directory + "/output.log") as output:
step = 0
for line in output.readlines():
match = RE_GENERIC_METRICS.match(line)
if match:
metrics.append({
"generic": match.groupdict()
})
continue
match = RE_RL_METRICS.match(line)
if match:
metrics[-1]['rl'] = match.groupdict()
continue
match = RE_CLASS_METRICS.match(line)
if match:
metrics[-1]['classification'] = match.groupdict()
continue
datas[(targetQ, batchSize)] = metrics
return datas
def compute_convergence_metric(datas):
for args, metrics in datas.items():
last_step = int(metrics[-1]['generic']['step'])
last_f1 = float(metrics[-1]['classification']['macroF1'])
convergence_time = last_step
for step_metrics in metrics[::-1]:
step_f1 = float(step_metrics['classification']['macroF1'])
if abs(step_f1 - last_f1) > 5:
break
else:
convergence_time = step_metrics['generic']['step']
metrics[-1]['convergence_time'] = convergence_time
def print_datas(datas):
print(
"#"+
"targetQ\t"+
"minibatch\t"+
"totalTime\t"+
"trainingRate\t"+
"convergenceTime\t"+
"rewardPerEp\t"+
"macroF1"
)
last_targetq = -1
for args, metrics in sorted(datas.items(), key = lambda e: e[0]):
if args[0] != last_targetq:
print('')
last_targetq = args[0]
print("{}\t{}\t{}\t{}\t{}\t{}\t{}".format(
args[0],
args[1],
metrics[-1]['generic']['totalTime'],
metrics[-1]['generic']['trainingRate'],
metrics[-1]['convergence_time'],
metrics[-1]['rl']['rewardPerEp'],
metrics[-1]['classification']['macroF1']
))
if __name__ == "__main__":
main()
#! /usr/bin/env gnuplot
set style line 1 lc rgb "#8DA0CB" pt 1 ps 1 lt 1 lw 2 # Blue
set style line 11 lc rgb '#808080' lt 1
set border 3 back ls 11
set tics nomirror
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid back ls 12
set terminal png size 1024,768
set output 'opt_param.png'
set xlabel 'target Q' rotate parallel offset -2,-1
set ylabel 'minibatch' rotate parallel offset 1,-1
set logscale xy 2
set xtics offset -0.2,-0.2 (2**8,2**9,2**10,2**11,2**12)
set ytics offset 0.2,-0.2
set ticslevel 0.1
set style data lines
set pm3d
set dgrid3d 32,32 gauss 0.75,0.75
set hidden3d
unset colorbox
set multiplot layout 2,2 rowsfirst title 'Hyperparameter optimization' font ',16'
#
set title 'Final F1-score'
set zlabel 'F1-score (%)' offset 2,0 rotate parallel
set zrange [20:70]
splot 'opt_params.dat' u 1:2:7 notitle
set xlabel
set ylabel
#
set title 'Total time'
set zlabel ''
set zrange [4000:20000]
set ztics ('01:06:40' 4000, '03:20:00' 12000, '05:33:20' 20000)
splot 'opt_params.dat' u 1:2:3 notitle
set ztics autofreq
#
set title 'Ratio score/time'
set zlabel 'ratio (%/1000s)'
set zrange [3:9]
splot 'opt_params.dat' u 1:2:(1000*$7/$3) notitle
#
set title 'Reward per episode'
set zlabel 'reward/ep'
set zrange [-10:2]
splot 'opt_params.dat' u 1:2:6 notitle
unset multiplot
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment