[mlpack-svn] r10495 - in mlpack/trunk/src/mlpack: methods/gmm methods/naive_bayes tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Dec 1 13:16:07 EST 2011


Author: mamidon
Date: 2011-12-01 13:16:07 -0500 (Thu, 01 Dec 2011)
New Revision: 10495

Modified:
   mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
   mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp
   mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.cpp
   mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.hpp
   mlpack/trunk/src/mlpack/tests/nbc_test.cpp
Log:
Ripped CLI out of nbc & gmm. Moved over to their respective mains. 


Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp	2011-12-01 17:57:02 UTC (rev 10494)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp	2011-12-01 18:16:07 UTC (rev 10495)
@@ -10,11 +10,6 @@
 
 #include <mlpack/core.hpp>
 
-PARAM_MODULE("gmm", "Parameters for the Gaussian mixture model.");
-
-PARAM_INT("gaussians", "The number of Gaussians in the mixture model (default "
-    "1).", "gmm", 1);
-
 namespace mlpack {
 namespace gmm {
 

Modified: mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp	2011-12-01 17:57:02 UTC (rev 10494)
+++ mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp	2011-12-01 18:16:07 UTC (rev 10495)
@@ -27,6 +27,8 @@
 
 #include "simple_nbc.hpp"
 
+PARAM_INT_REQ("classes", "The number of classes present in the data.", "nbc");
+
 PARAM_STRING_REQ("train", "A file containing the training set", "nbc");
 PARAM_STRING_REQ("test", "A file containing the test set", "nbc");
 PARAM_STRING("output", "The file in which the output of the test would "
@@ -56,9 +58,12 @@
   arma::mat testing_data;
   data::Load(testing_data_filename, testing_data, true);
 
+  size_t number_of_classes_ = CLI::GetParam<size_t>("nbc/classes");
+
   // Create and train the classifier.
   Timers::StartTimer("nbc/training");
-  SimpleNaiveBayesClassifier nbc = SimpleNaiveBayesClassifier(training_data);
+  SimpleNaiveBayesClassifier nbc = SimpleNaiveBayesClassifier(training_data,
+      number_of_classes_);
   Timers::StopTimer("nbc/training");
 
   // Timing the running of the Naive Bayes Classifier.

Modified: mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.cpp	2011-12-01 17:57:02 UTC (rev 10494)
+++ mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.cpp	2011-12-01 18:16:07 UTC (rev 10495)
@@ -13,7 +13,8 @@
 namespace mlpack {
 namespace naive_bayes {
 
-SimpleNaiveBayesClassifier::SimpleNaiveBayesClassifier(const arma::mat& data)
+SimpleNaiveBayesClassifier::SimpleNaiveBayesClassifier(const arma::mat& data, 
+    size_t classes) : number_of_classes_(classes)
 {
   size_t number_examples = data.n_cols;
   size_t number_features = data.n_rows - 1;
@@ -24,7 +25,6 @@
 
   // Update the variables, private and local, according to the number of
   // features and classes present in the data.
-  number_of_classes_ = mlpack::CLI::GetParam<int>("nbc/classes");
   class_probabilities_.set_size(number_of_classes_);
   means_.set_size(number_features,number_of_classes_);
   variances_.set_size(number_features,number_of_classes_);

Modified: mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.hpp	2011-12-01 17:57:02 UTC (rev 10494)
+++ mlpack/trunk/src/mlpack/methods/naive_bayes/simple_nbc.hpp	2011-12-01 18:16:07 UTC (rev 10495)
@@ -15,11 +15,6 @@
 namespace mlpack {
 namespace naive_bayes {
 
-PARAM_INT_REQ("classes", "The number of classes present in the data.", "nbc");
-
-PARAM_MODULE("nbc", "Trains the classifier using the training set "
-    "and outputs the results for the test set.");
-
 /**
  * A classification class. The class labels are assumed
  * to be positive integers - 0,1,2,....
@@ -77,7 +72,7 @@
    * SimpleNaiveBayesClassifier nbc(training_data, nbc_module);
    * @endcode
    */
-  SimpleNaiveBayesClassifier(const arma::mat& data);
+  SimpleNaiveBayesClassifier(const arma::mat& data, size_t classes);
 
   /**
    * Default constructor, you need to use the other one.

Modified: mlpack/trunk/src/mlpack/tests/nbc_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/nbc_test.cpp	2011-12-01 17:57:02 UTC (rev 10494)
+++ mlpack/trunk/src/mlpack/tests/nbc_test.cpp	2011-12-01 18:16:07 UTC (rev 10495)
@@ -25,8 +25,9 @@
   data::Load(filename_train_, train_data, true);
   data::Load(train_result_, train_res, true);
 
-  CLI::GetParam<int>("nbc/classes") = number_of_classes_;
-  SimpleNaiveBayesClassifier nbc_test_(train_data);
+  //Does not actually grab number_of_classes from the command line, as this
+  //is a boost unit test.
+  SimpleNaiveBayesClassifier nbc_test_(train_data, number_of_classes_);
 
   size_t number_of_features = nbc_test_.means_.n_rows;
   calc_mat.zeros(2 * number_of_features + 1, number_of_classes_);




More information about the mlpack-svn mailing list