-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.sh
328 lines (279 loc) · 7.24 KB
/
runner.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
# Author: Vaux Gomes
# Contact: vauxgomes@gmail.com
# Reference
# ---------
# [1] Loïc Cerf, Jérémy Besson, Céline Robardet,
# and Jean-François Boulicaut. Data-Peeler: Constraint-Based
# Closed Pattern Mining in n-ary Relations.
#
# [2] Loïc Cerf and Wagner Meira Jr. Complete
# Discovery of High-Quality Patterns in Large
# Numerical Tensors.
#
# [3] Takeaki Uno, Masashi Kiyomi, Hiroki Arimura,
# LCM ver.3: Collaboration of Array, Bitmap and
# Prefix Tree for Frequent Itemset Mining
# Usage Info
function show_help {
echo -e "\033[1mBoostlac Main Script\033[0m"
cat << EOF
Version: 0.1
Usage: [-hemZADCS] [-s FILES] [-t FILES] [-b NUM] [-p ARGS]
Arguments:
-h Displays help
-s Training Files (Required)
-t Testing files (Required)
-z MINER: Minimum support size (default: 1)
-m MINER: Use Multidupehack to mine the itemsets (default: D-peeler)
-l MINER: Use LCM to mine the itemsets (default: D-peeler)
-e BOOSTER: Activates Eager Mode
-Z BOOSTER: Deactivates ZERO classifier
-A BOOSTER: Deactivates Associative Classifier
-D BOOSTER: Activates Discrete Adaboost
-C BOOSTER: Activates Confidence-rated Adaboost
-S BOOSTER: Activates SLIPPER Boost
-c BOOSTER: Activates Internal Cross Validation
-o BOOSTER: Activates use of original train size
-j BOOSTER: Activates use of Jaccard\'s index
-b BOOSTER: Maximum number of rounds
-f BOOSTER: Uses only free itemsets
NOTE: This code works only for luccskdd files.
EOF
exit
}
# Easy color print function
function cerr {
echo -e "\033[95m$1\033[0m" 1>&2
}
# Header of the files
function header {
echo -n "# Mode: "
if $3; then echo "Eager"
else echo "Lazy"; fi
echo -n "# Miner: "
if $4; then echo "Multidupehack"
elif $5; then echo "Lcm"
else echo "D-peeler"; fi
echo "# Train:" ${1##*/}
echo "# Test:" ${2##*/}
echo "#"
echo "# Date:" `date`
echo "# Host:" `hostname`
echo ""
}
# Safety
if [ -z "$1" ]; then show_help; fi
# Pre-set variables
e=false # Eager mode (false = Lazy)
m=false # Multidupehack switch (false = D-peeler)
l=false # LCM switch (false = D-peeler)
Z=true # ZERO classifier
A=true # Associative classifier {LAC, EAC}
D=false # Discrete Adaboost
C=false # Conf-rated Adaboost
S=false # SLIPPER
c=false
o=false # Sizes
j=false # Jaccard's index
f=false # Free itemsets
# Minimum support size for D-peeler / Multidupehack
MSIZE=1
# Parsing options
while getopts ":hs:t:z:mleZADCScojb:f" opt
do
case $opt in
h) show_help ;;
s)
OPTARG="$(ls $OPTARG)" # POG
for file in $OPTARG
do
TRAIN+=($file)
done ;;
t)
OPTARG="$(ls $OPTARG)" # POG
for file in $OPTARG
do
TEST+=($file)
done ;;
z) MSIZE=$OPTARG ;;
m) m=true ;;
l) l=true ;;
e) e=true ;;
Z) Z=false ;;
A) A=false ;;
D) D=true ;;
C) C=true ;;
S) S=true ;;
c) c=true ;;
o) o=true ;;
j) j=true ;;
b) b=$OPTARG ;;
f) f=true ;;
:)
cerr "Option -$OPTARG requires an argument." >&2
exit 1
;;
\?)
cerr "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Safety: Checking presence of arrays
if [ ${#TRAIN[@]} -eq 0 ]
then
cerr "Required option: -s"
exit 1
elif [ ${#TEST[@]} -eq 0 ]
then
cerr "Required option: -t"
exit 1
fi
# Safety: Checking size equality of arrays
if [ ${#TRAIN[@]} -ne ${#TEST[@]} ]
then
cerr "Sizes of Train and Test arrays are uneven"
exit 1
fi
# Building boosting initial options
if $Z || $A || $D || $C || $S
then
BOPTIONS="-"
if $Z; then BOPTIONS+="Z"; fi
if $A; then BOPTIONS+="A"; fi
if $D; then BOPTIONS+="D"; fi
if $C; then BOPTIONS+="C"; fi
if $S; then BOPTIONS+="S"; fi
fi
# Internal Cross Validation
if $c; then BOPTIONS+="c"; fi
# Rounds
if [ -n "$b" ]; then BOPTIONS+=" -b $b";fi
# Free itemsets
if $f; then BOPTIONS+=" --free";fi
#
TMP=`mktemp -t runner.sh.XXXXXX`
trap "rm $TMP* 2>/dev/null" 0
# Jaccard's index
if $j; then
BOPTIONS+=" -j $TMP.jc";
jaccard="use jaccard" # Just an unempty string
fi
# Variable for awk projection, if necessary
if $m; then form="use multidupehack"; fi # Just an unempty string
# Learning Stage
length=${#TRAIN[@]}
for ((i = 0; i < length; i++))
do
# Printing header
header ${TRAIN[i]} ${TEST[i]} $e $m $l
# Eager Mode
if $e
then
# Creating class files
awk -v prefix=$TMP '{print NR >> prefix ".class." $NF}' ${TRAIN[i]}
# Preparing train file + Running miner + Calling booster
if $m
then
# multidupehack
awk 'BEGIN { OFS = "," } { --NF; print NR " " $0 " " 1 }' ${TRAIN[i]} | \
multidupehack -u 1 -s "$MSIZE 0" /dev/stdin -o /dev/stdout | \
./boost/main.py -s $TMP.class* -t ${TEST[i]} -i /dev/stdin $BOPTIONS || break
elif $l
then
# lcm
awk 'BEGIN { OFS = "," } { --NF; print NR " " $0 }' ${TRAIN[i]} | \
lcm IF_ ${TRAIN[i]} 1 - 2> /dev/null
else
# d-peeler
awk 'BEGIN { OFS = "," } { --NF; print NR " " $0 }' ${TRAIN[i]} | \
d-peeler -s "$MSIZE 0" /dev/stdin -o /dev/stdout | \
./boost/main.py -s $TMP.class* -t ${TEST[i]} -i /dev/stdin $BOPTIONS || break
fi
# Deleting remanescent files
rm $TMP*
# Lazy Mode
else
# Train sizes
if $o; then
SIZES=`mktemp -t runner.sh.XXXXXX`
trap "rm $SIZE 2>/dev/null" 0
awk '{++size[$NF]}END{for (i in size) { print i, size[i]}}' ${TRAIN[i]} > $SIZES
BOPTIONS+=" -o $SIZES"
fi
row=0 # Row for deletion
while read -r example
do
# Row for deletion from projection
row=$((row + 1))
# Wrinting the test file
echo $example > $TMP.testset
# Features to project
fts=`expr "$example" : '\(.*\) .*'`
# Preparing projected train + Creating the class files
sed $((row))d ${TRAIN[i]} | awk -v prefix=$TMP -v object="$fts" -v form="$form" -v jaccard="$jaccard" '
BEGIN {
n = split(object, tmp);
for (i = 1; i <= n; ++i)
attributes[tmp[i]] = ""
}{
empty = "t";
intersection = 0
#
for (i = 1; i != NF; ++i) {
if ($i in attributes) {
if (empty == "")
printf "," $i >> prefix;
else {
empty = "";
printf NR " " $i >> prefix
}
intersection++
}
};
if (empty == "") {
# For multidupehack
if (form) {
# If FORM is a non-empty string AWK understands it as true value
# And so it prints the projection in the multidupehack format
print " 1" >> prefix;
print "0 " NR >> prefix ".class." $NF
# For d-peeler
} else {
print "" >> prefix;
print NR >> prefix ".class." $NF
}
# Jaccard
if (jaccard) {
union = n + NF - intersection - 1 # Class counts in NF
print NR " " intersection/union >> prefix ".jc"
}
}
}'
# Safety: Avoiding empty projection
if [ ! -s $TMP ]; then continue; fi
# Running Miner and + Calling booster
if $m
then
# multidupehack
multidupehack -s '$MSIZE 0' -u 1 -o /dev/stdout $TMP | \
./boost/main.py -s $TMP.class* -t $TMP.testset -i /dev/stdin $BOPTIONS || break
elif $l
then
# lcm
cut -f 2 -d " " $TMP > $TMP.lcm; lcm IC_ $TMP.lcm 0 - 2> /dev/null | \
./boost/main.py -s $TMP.class* -t $TMP.testset -i /dev/stdin $BOPTIONS --rmode lcm || break
else
# d-peeler
d-peeler -s "$MSIZE 0" -o /dev/stdout $TMP 2> /dev/null | \
./boost/main.py -s $TMP.class* -t $TMP.testset -i /dev/stdin $BOPTIONS || break
fi
# Deleting remanescent files
rm $TMP*
# exit 1
done < ${TEST[i]}
fi
# Printing footer
echo ""
done