-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats.bash
executable file
·188 lines (149 loc) · 4.36 KB
/
stats.bash
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
. ./utils/functions.bash
cdIntoFirstArg $@
STAT_FILE=$($XML sel -t -m "/xml/default_stat_file" -v @value rules.xml)
Y_MIN=$($XML sel -t -m "/xml/default_stat_file" -v @ymin rules.xml)
Y_MAX=$($XML sel -t -m "/xml/default_stat_file" -v @ymax rules.xml)
X_MAX=$($XML sel -t -m "/xml/default_stat_file" -v @xmax rules.xml)
PLOT_ARGS="--persist --no-gui -q"
plot=0
if [ "$Y_MIN" == "" ] ; then
Y_MIN=0
fi
if [ "$Y_MAX" == "" ] ; then
Y_MAX=500
fi
if [ "$X_MAX" == "" ] ; then
X_MAX=0
fi
if [ ! -e rules.out ] ; then
echo "Please run parsing_rules first"
exit 1
fi
echoerr() { echo "$@" 1>&2; }
function read_input_until {
init=""
declare -a list=("${!1}")
while [ 1 ] ; do
read -s -n 1 init
if [[ ${list[@]} =~ $init || $init == "" ]] ; then
break
fi
done
if [[ $init == "" ]] ; then
init=${list[0]}
fi
echo $init
}
function ask_save_best(){
echoerr "Save best ? (0 : no/1 : yes/2 : moving max)"
arg=(0 1 2)
read_input_until arg[@]
}
function ask_dimension(){
echoerr "Which dimension ? (0-9)"
arg=$(seq 0 9)
read_input_until arg[@]
}
function ask_higher_better(){
echoerr "Is higher value better on this dimension ? (0/1)"
arg=(0 1)
read_input_until arg[@]
}
function handler(){
exit 0
}
repeat=1
#trap handler SIGINT
#cause problems when trap on read
echo "Want do you want to do ?"
echo " -- single parameter - mean over all (s) [default]"
echo " -- multiple parameters - mean over one (m)"
echo " -- plot one parameter from id (o)"
echo " -- analyse implication of one parameter (a)"
arg=("s" "m" "o" "a")
multiple=`read_input_until arg[@]`
if [[ $multiple == "m" ]] ; then
echo "Want to plot ? (0/1)"
arg=(0 1)
plot=`read_input_until arg[@]`
dimension=`ask_dimension`
save_best=`ask_save_best`
higher_better=`ask_higher_better`
COMMAND="best_param.m $STAT_FILE $plot $dimension $save_best $higher_better $Y_MIN $Y_MAX $X_MAX"
elif [[ $multiple == "s" ]] ; then
echo "Want do you want to do? only one dimension (s) / plot all dimension (a) : [s]"
arg=("s" "a")
multiple=`read_input_until arg[@]`
plot=1
if [[ $multiple == "s" ]] ; then
dimension=`ask_dimension`
save_best=`ask_save_best`
higher_better=`ask_higher_better`
COMMAND="one_by_one.m $STAT_FILE $dimension $save_best $higher_better $Y_MIN $Y_MAX $X_MAX"
else
save_best=`ask_save_best`
higher_better=`ask_higher_better`
COMMAND="one_by_one.m $STAT_FILE $save_best $higher_better $Y_MIN $Y_MAX $X_MAX"
fi
elif [[ $multiple == "o" ]] ; then
dimension=`ask_dimension`
save_best=`ask_save_best`
if [ $save_best -ge 1 ] ; then
higher_better=`ask_higher_better`
else
higher_better=1
fi
plot=1
echo "Give id number ?"
read -s id
COMMAND="best_param_plot.m $STAT_FILE $plot $dimension $save_best $higher_better $id $Y_MIN $Y_MAX $X_MAX"
repeat=2
elif [[ $multiple == "a" ]] ; then
dimension=`ask_dimension`
save_best=`ask_save_best`
if [ $save_best -ge 1 ] ; then
higher_better=`ask_higher_better`
else
higher_better=1
fi
echo "Give parameter name ?"
read name
COMMAND_BASE="analyse_param.m $STAT_FILE $dimension $save_best $higher_better"
repeat=2
fi
while [ $repeat -ge 1 ] ; do
directories=`cat rules.out`
for dir in $directories ; do
if [[ $multiple == "a" ]] ; then
val=`$XML sel -t -m "/xml/fold[@name='$dir']/param[@name='$name']" -v @values -n rules.xml`
mm=`$XML sel -t -m "/xml/fold[@name='$dir']/param" -v @values -n rules.xml | wc -l`
mm=`expr $mm - 1`
rank=`$XML sel -t -m "/xml/fold[@name='$dir']/param" -v @name -n rules.xml | grep -n $name | sed -e 's/:.*//'`
COMMAND="$COMMAND_BASE $name $val $mm $rank $Y_MIN $Y_MAX $X_MAX"
fi
echo "############################ $dir #####################################"
tmp1=`mktemp`
#review sort
#head -n 1 $dir/rules.out > $tmp1
#cat $dir/rules.out | sed '1d' | grep -v '^$' | sort -n >> $tmp1
#mv $tmp1 $dir/rules.out
cd $dir
if [ $plot -eq 0 ] ; then
PLOT_ARGS=""
fi
echo "OCTAVE_PATH=$LHPO_PATH/utils octave $PLOT_ARGS $LHPO_PATH/utils/$COMMAND"
OCTAVE_PATH=$LHPO_PATH/utils octave $PLOT_ARGS $LHPO_PATH/utils/$COMMAND
cd ..
done
if [[ $repeat -eq 2 && $multiple == "o" ]] ; then
echo "Give id number ?"
read -s id
COMMAND="best_param_plot.m $STAT_FILE $plot $dimension $save_best $higher_better $id $Y_MIN $Y_MAX $X_MAX"
elif [[ $repeat -eq 2 && $multiple == "a" ]] ; then
echo "Give parameter name ?"
read name
else
repeat=0
fi
done