[mlpack-git] master: Refactor input arguments so --algorithm is an accepted parameter, which provides more flexibility as I add more LloydItreationTypes. (0034275)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:01:02 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 0034275d32ebab8dd5c788d23a28d35b1a419a1e
Author: Ryan Curtin <ryan at ratml.org>
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.


>---------------------------------------------------------------

0034275d32ebab8dd5c788d23a28d35b1a419a1e
 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.



More information about the mlpack-git mailing list