[mlpack-svn] r17095 - in mlpack/trunk/src/mlpack: methods/adaboost tests tests/data

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Aug 21 17:49:44 EDT 2014


Author: saxena.udit
Date: Thu Aug 21 17:49:43 2014
New Revision: 17095

Log:
New tests added for the AdaBoost classification function.

Added:
   mlpack/trunk/src/mlpack/tests/data/iris_test.csv
   mlpack/trunk/src/mlpack/tests/data/iris_test_labels.csv
   mlpack/trunk/src/mlpack/tests/data/iris_train.csv
   mlpack/trunk/src/mlpack/tests/data/iris_train_labels.csv
      - copied, changed from r17093, /mlpack/trunk/src/mlpack/tests/data/iris_labels.txt
Modified:
   mlpack/trunk/src/mlpack/methods/adaboost/adaboost_impl.hpp
   mlpack/trunk/src/mlpack/tests/adaboost_test.cpp
   mlpack/trunk/src/mlpack/tests/data/iris_labels.txt

Modified: mlpack/trunk/src/mlpack/methods/adaboost/adaboost_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/adaboost/adaboost_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/adaboost/adaboost_impl.hpp	Thu Aug 21 17:49:43 2014
@@ -222,13 +222,13 @@
     for (int j = 0; j < tempPredictedLabels.n_cols; j++)
       cMatrix(tempPredictedLabels(j), j) += (alpha[i] * tempPredictedLabels(j));
   }
-
-  arma::rowvec cMRow;
+  // std::cout<<"Not working here ?\n";
+  arma::colvec cMRow;
   arma::uword max_index;
 
   for (int i = 0; i < predictedLabels.n_cols; i++)
   {
-    cMRow = cMatrix.row(i);
+    cMRow = cMatrix.col(i);
     cMRow.max(max_index);
     predictedLabels(i) = max_index;
   }

Modified: mlpack/trunk/src/mlpack/tests/adaboost_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/adaboost_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/adaboost_test.cpp	Thu Aug 21 17:49:43 2014
@@ -569,4 +569,148 @@
   
   BOOST_REQUIRE(error <= weakLearnerErrorRate);
 }
+
+/**
+ *  This test case runs the AdaBoost.mh algorithm on the UCI Vertebral 
+ *  Column dataset.
+ *  It tests the Classify function and checks if the error returned by 
+ *  running the boosted weak learner using adaboost is comparable to the 
+ *  error returned by running Classify() on the same function.
+ */
+BOOST_AUTO_TEST_CASE(ClassifyTest_VERTEBRALCOL)
+{
+  arma::mat inputData;
+
+  if (!data::Load("vc2.txt", inputData))
+    BOOST_FAIL("Cannot load test dataset vc2.txt!");
+
+  arma::Mat<size_t> labels;
+
+  if (!data::Load("vc2_labels.txt",labels))
+    BOOST_FAIL("Cannot load labels for vc2_labels.txt");
+  
+  // no need to map the labels here
+
+  // Define your own weak learner, perceptron in this case.
+  // Run the perceptron for perceptron_iter iterations.
+  int perceptron_iter = 800;
+
+  arma::Row<size_t> perceptronPrediction(labels.n_cols);
+  perceptron::Perceptron<> p(inputData, labels.row(0), perceptron_iter);
+  p.Classify(inputData, perceptronPrediction);
+  
+  // Define parameters for the adaboost
+  int iterations = 50;
+  double tolerance = 1e-10;
+  AdaBoost<> a(inputData, labels.row(0), iterations, tolerance, p);
+  
+  arma::Row<size_t> predictedLabels(inputData.n_cols);
+  a.Classify(inputData, predictedLabels);
+
+  int localError = 0;
+
+  for (size_t i = 0; i < labels.n_cols; i++)
+    if(labels(i) != predictedLabels(i))
+      localError++;
+  double lError = (double) localError / labels.n_cols;
+  
+  BOOST_REQUIRE(lError <= 0.30);
+}
+
+/**
+ *  This test case runs the AdaBoost.mh algorithm on a non linearly 
+ *  separable dataset.
+ *  It tests the Classify function and checks if the error returned by 
+ *  running the boosted weak learner using adaboost is comparable to the 
+ *  error returned by running Classify() on the same function.
+ */
+BOOST_AUTO_TEST_CASE(ClassifyTest_NONLINSEP)
+{
+  arma::mat inputData;
+
+  if (!data::Load("nonlinsepdata.txt", inputData))
+    BOOST_FAIL("Cannot load test dataset nonlinsepdata.txt!");
+
+  arma::Mat<size_t> labels;
+
+  if (!data::Load("nonlinsepdata_labels.txt",labels))
+    BOOST_FAIL("Cannot load labels for nonlinsepdata_labels.txt");
+  
+  // no need to map the labels here
+
+  // Define your own weak learner, perceptron in this case.
+  // Run the perceptron for perceptron_iter iterations.
+  
+  const size_t numClasses = 2;
+  const size_t inpBucketSize = 3;
+
+  arma::Row<size_t> dsPrediction(labels.n_cols);
+
+  decision_stump::DecisionStump<> ds(inputData, labels.row(0), 
+                                     numClasses, inpBucketSize);
+  
+  // Define parameters for the adaboost
+  int iterations = 50;
+  double tolerance = 1e-10;
+  AdaBoost<arma::mat, mlpack::decision_stump::DecisionStump<> > a(
+           inputData, labels.row(0), iterations, tolerance, ds);
+
+  arma::Row<size_t> predictedLabels(inputData.n_cols);
+  a.Classify(inputData, predictedLabels);
+
+  int localError = 0;
+  for (size_t i = 0; i < labels.n_cols; i++)
+    if(labels(i) != predictedLabels(i))
+      localError++;
+  double lError = (double) localError / labels.n_cols;
+  
+  BOOST_REQUIRE(lError <= 0.30);
+}
+
+BOOST_AUTO_TEST_CASE(ClassifyTest_IRIS)
+{
+  arma::mat inputData;
+
+  if (!data::Load("iris_train.csv", inputData))
+    BOOST_FAIL("Cannot load test dataset iris_train.csv!");
+
+  arma::Mat<size_t> labels;
+
+  if (!data::Load("iris_train_labels.csv",labels))
+    BOOST_FAIL("Cannot load labels for iris_train_labels.csv");
+  
+  // no need to map the labels here
+
+  // Define your own weak learner, perceptron in this case.
+  // Run the perceptron for perceptron_iter iterations.
+  int perceptron_iter = 800;
+
+  perceptron::Perceptron<> p(inputData, labels.row(0), perceptron_iter);
+
+  // Define parameters for the adaboost
+  int iterations = 50;
+  double tolerance = 1e-10;
+  AdaBoost<> a(inputData, labels.row(0), iterations, tolerance, p);
+  
+  arma::mat testData;
+  if (!data::Load("iris_test.csv", inputData))
+    BOOST_FAIL("Cannot load test dataset iris_test.csv!");
+
+  arma::Row<size_t> predictedLabels(testData.n_cols);
+
+  a.Classify(testData, predictedLabels);
+
+  arma::Row<size_t> trueTestLabels;
+  if (!data::Load("iris_test_labels.csv", inputData))
+    BOOST_FAIL("Cannot load test dataset iris_test_labels.csv!");
+
+  int localError = 0;
+  for (size_t i = 0; i < trueTestLabels.n_cols; i++)
+    if(trueTestLabels(i) != predictedLabels(i))
+      localError++;
+  double lError = (double) localError / labels.n_cols;
+
+  BOOST_REQUIRE(lError <= 0.30);
+}
+
 BOOST_AUTO_TEST_SUITE_END();
\ No newline at end of file

Modified: mlpack/trunk/src/mlpack/tests/data/iris_labels.txt
==============================================================================
--- mlpack/trunk/src/mlpack/tests/data/iris_labels.txt	(original)
+++ mlpack/trunk/src/mlpack/tests/data/iris_labels.txt	Thu Aug 21 17:49:43 2014
@@ -147,4 +147,4 @@
 2
 2
 2
-2
\ No newline at end of file
+2

Added: mlpack/trunk/src/mlpack/tests/data/iris_test.csv
==============================================================================
--- (empty file)
+++ mlpack/trunk/src/mlpack/tests/data/iris_test.csv	Thu Aug 21 17:49:43 2014
@@ -0,0 +1,63 @@
+4.7,3.2,1.6,0.2
+4.8,3.1,1.6,0.2
+5.4,3.4,1.5,0.4
+5.2,4.1,1.5,0.1
+5.5,4.2,1.4,0.2
+4.9,3.1,1.5,0.1
+5,3.2,1.2,0.2
+5.5,3.5,1.3,0.2
+4.9,3.1,1.5,0.1
+4.4,3,1.3,0.2
+5.1,3.4,1.5,0.2
+5,3.5,1.3,0.3
+4.5,2.3,1.3,0.3
+4.4,3.2,1.3,0.2
+5,3.5,1.6,0.6
+5.1,3.8,1.9,0.4
+4.8,3,1.4,0.3
+5.1,3.8,1.6,0.2
+4.6,3.2,1.4,0.2
+5.3,3.7,1.5,0.2
+5,3.3,1.4,0.2
+5.7,2.6,3.5,1
+5.5,2.4,3.8,1.1
+5.5,2.4,3.7,1
+5.8,2.7,3.9,1.2
+6,2.7,5.1,1.6
+5.4,3,4.5,1.5
+6,3.4,4.5,1.6
+6.7,3.1,4.7,1.5
+6.3,2.3,4.4,1.3
+5.6,3,4.1,1.3
+5.5,2.5,4,1.3
+5.5,2.6,4.4,1.2
+6.1,3,4.6,1.4
+5.8,2.6,4,1.2
+5,2.3,3.3,1
+5.6,2.7,4.2,1.3
+5.7,3,4.2,1.2
+5.7,2.9,4.2,1.3
+6.2,2.9,4.3,1.3
+5.1,2.5,3,1.1
+5.7,2.8,4.1,1.3
+7.2,3,5.8,1.6
+7.4,2.8,6.1,1.9
+7.9,3.8,6.4,2
+6.4,2.8,5.6,2.2
+6.3,2.8,5.1,1.5
+6.1,2.6,5.6,1.4
+7.7,3,6.1,2.3
+6.3,3.4,5.6,2.4
+6.4,3.1,5.5,1.8
+6,3,4.8,1.8
+6.9,3.1,5.4,2.1
+6.7,3.1,5.6,2.4
+6.9,3.1,5.1,2.3
+5.8,2.7,5.1,1.9
+6.8,3.2,5.9,2.3
+6.7,3.3,5.7,2.5
+6.7,3,5.2,2.3
+6.3,2.5,5,1.9
+6.5,3,5.2,2
+6.2,3.4,5.4,2.3
+5.9,3,5.1,1.8

Added: mlpack/trunk/src/mlpack/tests/data/iris_test_labels.csv
==============================================================================
--- (empty file)
+++ mlpack/trunk/src/mlpack/tests/data/iris_test_labels.csv	Thu Aug 21 17:49:43 2014
@@ -0,0 +1,63 @@
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2
+2

Added: mlpack/trunk/src/mlpack/tests/data/iris_train.csv
==============================================================================
--- (empty file)
+++ mlpack/trunk/src/mlpack/tests/data/iris_train.csv	Thu Aug 21 17:49:43 2014
@@ -0,0 +1,87 @@
+5.1,3.5,1.4,0.2
+4.9,3,1.4,0.2
+4.7,3.2,1.3,0.2
+4.6,3.1,1.5,0.2
+5,3.6,1.4,0.2
+5.4,3.9,1.7,0.4
+4.6,3.4,1.4,0.3
+5,3.4,1.5,0.2
+4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.8,2.8,5.1,2.4
+6.4,3.2,5.3,2.3
+6.5,3,5.5,1.8
+7.7,3.8,6.7,2.2
+7.7,2.6,6.9,2.3
+6,2.2,5,1.5
+6.9,3.2,5.7,2.3
+5.6,2.8,4.9,2
+7.7,2.8,6.7,2
+6.3,2.7,4.9,1.8
+6.7,3.3,5.7,2.1
+7.2,3.2,6,1.8
+6.2,2.8,4.8,1.8
+6.1,3,4.9,1.8
+6.4,2.8,5.6,2.1

Copied: mlpack/trunk/src/mlpack/tests/data/iris_train_labels.csv (from r17093, /mlpack/trunk/src/mlpack/tests/data/iris_labels.txt)
==============================================================================
--- /mlpack/trunk/src/mlpack/tests/data/iris_labels.txt	(original)
+++ mlpack/trunk/src/mlpack/tests/data/iris_train_labels.csv	Thu Aug 21 17:49:43 2014
@@ -27,37 +27,6 @@
 0
 0
 0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
 1
 1
 1
@@ -87,37 +56,6 @@
 1
 1
 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
 2
 2
 2
@@ -147,4 +85,3 @@
 2
 2
 2
-2
\ No newline at end of file



More information about the mlpack-svn mailing list