-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·134 lines (127 loc) · 3.42 KB
/
run.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
#!/usr/bin/env bash
dataset=${DATASET:-adults}
build () {
echo "Building Mondrian"
rm -rf build
mkdir build
cd build && cmake .. && make && cd - > /dev/null
}
run () {
./build/mondrian -i datasets/${dataset}.csv -o ${dataset}_anonymized.csv \
&& echo -e "\nFile ${dataset}_anonymized.csv generated in current directory"
}
test_k () {
local lower
local upper
local step
if [ ! -z "$1" ]; then
lower=$1
else
lower=5
fi
if [ ! -z "$2" ]; then
upper=$2
else
upper=105
fi
if [ ! -z "$3" ]; then
step=$3
else
step=5
fi
echo "Running tests with variable K"
for k in $(seq $lower $step $upper); do
./build/mondrian -f datasets/${dataset}.csv -k $k -r
echo
done
}
test_qi () {
cp datasets/${dataset}.csv datasets/${dataset}.qi.csv
local qi="$(sed -n '2p' datasets/${dataset}.qi.csv)"
OLDIFS=$IFS
IFS=', ' read -ra parts <<< "$qi"
IFS=$OLDIFS
local output="${parts[0]}"
echo "Running tests with variable QIDs length"
for ((i=0; i<${#parts[@]}; i++)); do
if [ $i -eq 0 ]; then
output=${output}
else
output="${output},${parts[i]}"
fi
sed -i "2s/.*/$output/" datasets/${dataset}.qi.csv
echo "QIDs: $(( i + 1 ))"
./build/mondrian -f datasets/${dataset}.qi.csv -r
echo
done
rm datasets/${dataset}.qi.csv
}
test_data () {
local size="$(wc datasets/${dataset}.data.csv)"
local batch
local num_test
if [ ! -z "$1" ]; then
batch=$1
else
batch=5000
fi
if [ ! -z "$2" ]; then
num_test=$2
else
num_test=6
fi
echo "Running tests with variable dataset size"
for ((i=1; i<=$num_test; i++)); do
if [ $i -eq 1 ]; then
sed -n "1,$(( i * batch )) p" datasets/${dataset}.csv > datasets/${dataset}.data.csv
else
sed -n "$(( ( ($i - 1) * batch ) + 1 )),$(( i * batch )) p" datasets/${dataset}.csv >> datasets/${dataset}.data.csv
fi
echo "Dataset size: $(wc -l < datasets/${dataset}.data.csv)"
./build/mondrian -f datasets/${dataset}.data.csv -r
echo
done
rm datasets/${dataset}.data.csv
}
if [ "$1" = "build" ]; then
build
elif [ "$1" = "run" ]; then
run
elif [ "$1" = "test" ]; then
if [ ! -z "$2" ]; then
if [ "$2" = "k" ]; then
test_k $3 $4 $5
elif [ "$2" = "qi" ]; then
test_qi
elif [ "$2" = "data" ]; then
test_data $3 $4
fi
else
test_k
test_qi
test_data
fi
elif [ "$1" = "-h" ]; then
echo "Usage: ./run.sh CMD ARGS"
echo
echo "Optional commands:"
echo " build: build the project"
echo " run: run the project"
echo " test: run some tests"
echo " -h: show this help"
echo
echo "Optional arguments:"
echo " (run) -r: force build the project"
echo " (test) k [lower [upper [step]]]: test with variable K. Default: lower=5, upper=105, step=5"
echo " (test) qi: test with variable QIDs length"
echo " (test) data [batch [num_test]]: test with variable dataset size. Default: batch=5000, num_test=6"
echo
echo "Environment variables:"
echo " DATASET: dataset name. Default: adults. Example: DATASET=informs ./run.sh"
else
if [ ! -d "build" ] || [ "$1" = "-r" ]; then
build
echo
fi
run
fi