[mlpack] 30/149: Refactor input arguments so --algorithm is an accepted parameter, which provides more flexibility as I add more LloydItreationTypes.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 7d92dbe843d4ea8efe8d90fa68f650dfd68df63d
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Fri Oct 10 20:08:54 2014 +0000

    Refactor input arguments so --algorithm is an accepted parameter, which provides
    more flexibility as I add more LloydItreationTypes.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17236 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/kmeans/kmeans_main.cpp | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/mlpack/methods/kmeans/kmeans_main.cpp b/src/mlpack/methods/kmeans/kmeans_main.cpp
index 15003da..9c911c1 100644
--- a/src/mlpack/methods/kmeans/kmeans_main.cpp
+++ b/src/mlpack/methods/kmeans/kmeans_main.cpp
@@ -10,6 +10,7 @@
 #include "allow_empty_clusters.hpp"
 #include "refined_start.hpp"
 #include "elkan_kmeans.hpp"
+#include "hamerly_kmeans.hpp"
 
 using namespace mlpack;
 using namespace mlpack::kmeans;
@@ -64,7 +65,9 @@ PARAM_INT("samplings", "Number of samplings to perform for refined start (use "
     "when --refined_start is specified).", "S", 100);
 PARAM_DOUBLE("percentage", "Percentage of dataset to use for each refined start"
     " sampling (use when --refined_start is specified).", "p", 0.02);
-PARAM_FLAG("elkan", "Use Elkan's algorithm.", "E");
+
+PARAM_STRING("algorithm", "Algorithm to use for the Lloyd iteration ('naive', "
+    "'elkan', or 'hamerly').", "a", "naive");
 
 // Given the type of initial partition policy, figure out the empty cluster
 // policy and run k-means.
@@ -131,10 +134,16 @@ void FindEmptyClusterPolicy(const InitialPartitionPolicy& ipp)
 template<typename InitialPartitionPolicy, typename EmptyClusterPolicy>
 void FindLloydStepType(const InitialPartitionPolicy& ipp)
 {
-  if (CLI::HasParam("elkan"))
+  const string algorithm = CLI::GetParam<string>("algorithm");
+  if (algorithm == "elkan")
     RunKMeans<InitialPartitionPolicy, EmptyClusterPolicy, ElkanKMeans>(ipp);
-  else
+  else if (algorithm == "hamerly")
+    RunKMeans<InitialPartitionPolicy, EmptyClusterPolicy, HamerlyKMeans>(ipp);
+  else if (algorithm == "naive")
     RunKMeans<InitialPartitionPolicy, EmptyClusterPolicy, NaiveKMeans>(ipp);
+  else
+    Log::Fatal << "Unknown algorithm: '" << algorithm << "'.  Supported options"
+        << " are 'naive', 'elkan', and 'hamerly'." << endl;
 }
 
 // Given the template parameters, sanitize/load input and run k-means.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list