clueless-kmean now takes as parameter in which mode to work, and test.sh generate...
authorFrancois Fleuret <francois@fleuret.org>
Sat, 18 May 2013 22:02:59 +0000 (00:02 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sat, 18 May 2013 22:02:59 +0000 (00:02 +0200)
clueless-kmean.cc
clusterer.h
test.sh

index e3d4f93..557f0d8 100644 (file)
@@ -76,8 +76,23 @@ int main(int argc, char **argv) {
 
   glp_term_out(0);
 
-  clusterer.train(Clusterer::UNINFORMATIVE_LP_ASSOCIATION,
-                  // Clusterer::STANDARD_LP_ASSOCIATION,
+  int mode;
+
+  if(argc == 2) {
+    if(strcmp(argv[1], "standard") == 0) {
+      mode = Clusterer::STANDARD_LP_ASSOCIATION;
+    } else if(strcmp(argv[1], "clueless") == 0) {
+      mode = Clusterer::UNINFORMATIVE_LP_ASSOCIATION;
+    } else {
+      cerr << "Unknown association mode " << argv[1] << endl;
+      exit(EXIT_FAILURE);
+    }
+  } else {
+    cerr << "Usage: " << argv[0] << " standard|clueless" << endl;
+    exit(EXIT_FAILURE);
+  }
+
+  clusterer.train(mode,
                   nb_clusters,
                   sample_set.dim,
                   sample_set.nb_points, sample_set.points,
index ad0c58f..a0a29f9 100644 (file)
@@ -42,6 +42,7 @@ public:
 
   int _nb_clusters;
   int _dim;
+
   scalar_t **_cluster_means, **_cluster_var;
 
   scalar_t distance_to_centroid(scalar_t *x, int k);
diff --git a/test.sh b/test.sh
index d89deb1..51735ee 100755 (executable)
--- a/test.sh
+++ b/test.sh
 
 set -e
 
-make -j -k
-
-./clueless-kmean
+function make_graph () {
+    CLUSTER1=($(grep ^0 clusters.dat))
+    CLUSTER2=($(grep ^1 clusters.dat))
+    CLUSTER3=($(grep ^2 clusters.dat))
 
-CLUSTER1=($(grep ^0 clusters.dat))
-CLUSTER2=($(grep ^1 clusters.dat))
-CLUSTER3=($(grep ^2 clusters.dat))
-
-gnuplot <<EOF
+    gnuplot <<EOF
 set terminal pngcairo truecolor size 1024,768
-set output "result.png"
+set output "$1"
 set size ratio 1
 set key out vert
 set key left top
@@ -52,3 +49,12 @@ plot [-1.2:1.2][-1.2:1.2] "< grep ^0 associated_clusters.dat" using 2:3 w p lc r
                           "< grep ^2 clusters.dat"            using 2:3 w p lc rgb "#ffffff" pt 2 lw 9 ps 4.0 notitle, \
                           "< grep ^2 clusters.dat"            using 2:3 w p lc rgb "#0000c0" pt 2 lw 4 ps 4.0 title "Centroid 3"
 EOF
+}
+
+make -j -k
+
+./clueless-kmean standard
+make_graph result-standard.png
+
+./clueless-kmean clueless
+make_graph result-clueless.png