Added README.md
[clueless-kmeans.git] / test.sh
1 #!/bin/bash
2
3 # clueless-kmeans is a variant of k-means which enforces balanced
4 # distribution of classes in every cluster
5 #
6 # Copyright (c) 2013 Idiap Research Institute, http://www.idiap.ch/
7 # Written by Francois Fleuret <francois.fleuret@idiap.ch>
8 #
9 # This file is part of clueless-kmeans.
10 #
11 # clueless-kmeans is free software: you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # version 3 as published by the Free Software Foundation.
14 #
15 # clueless-kmeans is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with selector.  If not, see <http://www.gnu.org/licenses/>.
22
23 set -e
24
25 function make_graph () {
26     CLUSTER1=($(grep ^0 clusters.dat))
27     CLUSTER2=($(grep ^1 clusters.dat))
28     CLUSTER3=($(grep ^2 clusters.dat))
29
30     gnuplot <<EOF
31 set terminal pngcairo truecolor size 1024,768
32 set output "$1"
33 set size ratio 1
34 set key out vert
35 set key left top
36 set object 1 ellipse center ${CLUSTER1[1]}, ${CLUSTER1[2]} size ${CLUSTER1[3]}, ${CLUSTER1[4]} angle 0 front fs empty bo 0 lw 1
37 set object 2 ellipse center ${CLUSTER2[1]}, ${CLUSTER2[2]} size ${CLUSTER2[3]}, ${CLUSTER2[4]} angle 0 front fs empty bo 0 lw 1
38 set object 3 ellipse center ${CLUSTER3[1]}, ${CLUSTER3[2]} size ${CLUSTER3[3]}, ${CLUSTER3[4]} angle 0 front fs empty bo 0 lw 1
39 plot [-1.2:1.2][-1.2:1.2] "< grep ^0 associated_clusters.dat" using 2:3 w p lc rgb "#e00000" pt 6      ps 2.0 title "Cluster 1", \
40                           "< grep ^1 associated_clusters.dat" using 2:3 w p lc rgb "#00c000" pt 6      ps 2.0 title "Cluster 2", \
41                           "< grep ^2 associated_clusters.dat" using 2:3 w p lc rgb "#0000c0" pt 6      ps 2.0 title "Cluster 3", \
42                           "< grep ^0 points.dat"              using 2:3 w p lc rgb "#e00000" pt 7      ps 1.0 title "Class 1", \
43                           "< grep ^1 points.dat"              using 2:3 w p lc rgb "#00c000" pt 7      ps 1.0 title "Class 2", \
44                           "< grep ^0 clusters.dat"            using 2:3 w p lc rgb "#ffffff" pt 2 lw 9 ps 4.0 notitle, \
45                           "< grep ^0 clusters.dat"            using 2:3 w p lc rgb "#e00000" pt 2 lw 4 ps 4.0 title "Centroid 1", \
46                           "< grep ^1 clusters.dat"            using 2:3 w p lc rgb "#ffffff" pt 2 lw 9 ps 4.0 notitle, \
47                           "< grep ^1 clusters.dat"            using 2:3 w p lc rgb "#00c000" pt 2 lw 4 ps 4.0 title "Centroid 2", \
48                           "< grep ^2 clusters.dat"            using 2:3 w p lc rgb "#ffffff" pt 2 lw 9 ps 4.0 notitle, \
49                           "< grep ^2 clusters.dat"            using 2:3 w p lc rgb "#0000c0" pt 2 lw 4 ps 4.0 title "Centroid 3"
50 EOF
51 }
52
53 make -j -k
54
55 echo "Baseline k-mean"
56 ./clueless-kmeans standard
57 make_graph result-standard.png
58
59 echo "Clueless k-mean"
60 ./clueless-kmeans clueless
61 make_graph result-clueless.png
62
63 echo "Clueless-absolute k-mean"
64 ./clueless-kmeans clueless-absolute
65 make_graph result-clueless-absolute.png