-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterate_mlmethods.sh
executable file
·82 lines (65 loc) · 3.18 KB
/
iterate_mlmethods.sh
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
#!/bin/bash
function iterate_mlmethods() {
#$ML_FRAMEWORK_DIR/log.sh INFO "Running $0..."
#source $ML_FRAMEWORK_DIR/common.sh
#source $ML_FRAMEWORK_DIR/params.sh
#config_file=${params[RUN_DIR]}/config
###################################
mlmethod_list=${params[ML_METHOD_LIST]}
run_dir=${params[RUN_DIR]}
$ML_FRAMEWORK_DIR/log.sh DEBUG "Filtering the ML method list: $mlmethod_list => $run_dir/mlmethod_per_line.list"
cat $mlmethod_list | grep -v "^#" > $run_dir/mlmethod_per_line.list
if [ ${params[RANKING]}. == 1. ]; then
cat $run_dir/mlmethod_per_line.list | grep "ranking" > $run_dir/mlmethod_per_line.list.tmp
cp $run_dir/mlmethod_per_line.list.tmp $run_dir/mlmethod_per_line.list
rm $run_dir/mlmethod_per_line.list.tmp
fi
# $ML_FRAMEWORK_DIR/log.sh INFO "Preprocessing the data used in the experiments..."
# cat $run_dir/mlmethod_per_line.list | cut -f1 -d: | sort | uniq | while read ml_method; do
# make -s -f $ML_FRAMEWORK_DIR/makefile.train_test_eval preprocess CONFIG_FILE=$config_file ML_METHOD=$ml_method
# done
iter=000
# run an experiment for every ML method
cat $run_dir/mlmethod_per_line.list | while read ml_method_info; do
iter=`perl -e 'my $x = shift @ARGV; $x++; printf "%03s", $x;' $iter`
ml_method=`echo $ml_method_info | cut -s -f1 -d':'`
ml_method=${ml_method:-$ml_method_info}
ml_params=`echo $ml_method_info | cut -s -f2- -d':'`
ml_method_sha=`echo "$ml_method_info" | shasum | cut -c 1-5`
run_subdir=$run_dir/$iter.$ml_method_sha.mlmethod
#mkdir -p $run_subdir
#echo_err $run_subdir
$ML_FRAMEWORK_DIR/log.sh INFO "Running an experiment no. $iter using the ML method $ml_method with params ($ml_params)"
$ML_FRAMEWORK_DIR/log.sh DEBUG "Its running directory is: $run_subdir"
#data_dir=${params[DATA_DIR]-$run_dir/data}
#DATA_DIR=$data_dir \
run_in_parallel \
"$ML_FRAMEWORK_DIR/run_experiment.sh \
-f $config_file \
RUN_DIR=$run_subdir \
ML_METHOD_LIST= \
ML_METHOD=$ml_method \
ML_PARAMS='$ml_params'; \
touch $run_subdir/done;" \
"mlmethod_exper.$ml_method_sha" -5 $run_subdir/log 2
done
# wait until all experiments are acomplished
mlmethods_count=`cat $run_dir/mlmethod_per_line.list | wc -l`
wait_for_jobs "$run_dir/*.mlmethod/done" $mlmethods_count 5
# collect results
$ML_FRAMEWORK_DIR/log.sh INFO "Collecting results of the experiments to: $run_dir/stats"
i=0
for stats_part in $run_dir/*.mlmethod/stats; do
if [ $i -eq 0 ]; then
cat $stats_part | cut -f1 > $run_dir/stats
fi
cat $stats_part | cut -f1 --complement | paste $run_dir/stats - > $run_dir/stats.tmp
cp $run_dir/stats.tmp $run_dir/stats
rm $run_dir/stats.tmp
((i++))
done
sed -i 's/|$//' $run_dir/stats
# find best model
cat $run_dir/*.mlmethod/best_f.model | sort -k1,1 -n | tail -n1 > $run_dir/best_f.model
cat $run_dir/*.mlmethod/best_acc.model | sort -k1,1 -n | tail -n1 > $run_dir/best_acc.model
}