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

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jan 19 11:41:49 EST 2012


Author: rcurtin
Date: 2012-01-19 11:41:49 -0500 (Thu, 19 Jan 2012)
New Revision: 11166

Modified:
   mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp
Log:
Add --seed support for K-Means executable.


Modified: mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp	2012-01-19 16:39:39 UTC (rev 11165)
+++ mlpack/trunk/src/mlpack/methods/kmeans/kmeans_main.cpp	2012-01-19 16:41:49 UTC (rev 11166)
@@ -36,13 +36,17 @@
     "left.", "O", 1.0);
 PARAM_INT("max_iterations", "Maximum number of iterations before K-Means "
     "terminates.", "m", 1000);
+PARAM_INT("seed", "Random seed.  If 0, 'std::time(NULL)' is used.", "s", 0);
 
 int main(int argc, char** argv)
 {
   CLI::ParseCommandLine(argc, argv);
 
-  // Initialize random seed -- because that makes a difference.
-  srand(time(NULL));
+  // Initialize random seed.
+  if (CLI::GetParam<int>("seed") != 0)
+    math::RandomSeed((size_t) CLI::GetParam<int>("seed"));
+  else
+    math::RandomSeed((size_t) std::time(NULL));
 
   // Now do validation of options.
   string inputFile = CLI::GetParam<string>("inputFile");




More information about the mlpack-svn mailing list