[mlpack-svn] r15498 - mlpack/trunk/src/mlpack/methods/kmeans

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jul 18 13:11:57 EDT 2013


Author: marcus
Date: Thu Jul 18 13:11:56 2013
New Revision: 15498

Log:
Add opportunity to set initial centroids.

Modified:
   mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp

Modified: mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp	(original)
+++ mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp	Thu Jul 18 13:11:56 2013
@@ -28,12 +28,7 @@
     " random samples of the dataset; to specify the number of samples, the "
     "--samples parameter is used, and to specify the percentage of the dataset "
     "to be used in each sample, the --percentage parameter is used (it should "
-    "be a value between 0.0 and 1.0)."
-    "\n\n"
-    "If you want to specify your own initial cluster assignments or initial "
-    "cluster centroids, this functionality is available in the C++ interface. "
-    "Alternately, file a bug (well, a feature request) on the mlpack bug "
-    "tracker.");
+    "be a value between 0.0 and 1.0).\n");
 
 // Required options.
 PARAM_STRING_REQ("inputFile", "Input dataset to perform clustering on.", "i");
@@ -119,6 +114,14 @@
   // it gets a little weird...
   arma::Col<size_t> assignments;
   arma::mat centroids;
+  
+  bool initialCentroidGuess = CLI::HasParam("initial_centroid");
+  // Load initial centroids if the user asked for it.
+  if (initialCentroidGuess)
+  {
+    string initialCentroidsFile = CLI::GetParam<string>("initial_centroid");
+    data::Load(initialCentroidsFile.c_str(), centroids, true);
+  }
 
   if (CLI::HasParam("allow_empty_clusters"))
   {
@@ -154,7 +157,8 @@
 //      if (CLI::HasParam("fast_kmeans"))
 //        k.FastCluster(dataset, clusters, assignments);
 //      else
-        k.Cluster(dataset, clusters, assignments, centroids);
+        k.Cluster(dataset, clusters, assignments, centroids, false,
+            initialCentroidGuess);
       Timer::Stop("clustering");
     }
   }
@@ -191,7 +195,8 @@
 //      if (CLI::HasParam("fast_kmeans"))
 //        k.FastCluster(dataset, clusters, assignments);
 //      else
-        k.Cluster(dataset, clusters, assignments, centroids);
+        k.Cluster(dataset, clusters, assignments, centroids, false,
+            initialCentroidGuess);
       Timer::Stop("clustering");
     }
   }



More information about the mlpack-svn mailing list