[mlpack] 40/58: New tests added for the AdaBoost classification function.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Tue Sep 9 13:19:42 UTC 2014


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

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

commit e53527ca036f74c2f8dbcd500efad18cc57643bd
Author: saxena.udit <saxena.udit at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Thu Aug 21 21:49:43 2014 +0000

    New tests added for the AdaBoost classification function.
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17095 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/methods/adaboost/adaboost_impl.hpp      |   6 +-
 src/mlpack/tests/adaboost_test.cpp                 | 144 +++++++++++++++++++++
 src/mlpack/tests/data/iris_labels.txt              |   2 +-
 src/mlpack/tests/data/iris_test.csv                |  63 +++++++++
 src/mlpack/tests/data/iris_test_labels.csv         |  63 +++++++++
 src/mlpack/tests/data/iris_train.csv               |  87 +++++++++++++
 .../{iris_labels.txt => iris_train_labels.csv}     |  63 ---------
 7 files changed, 361 insertions(+), 67 deletions(-)

diff --git a/src/mlpack/methods/adaboost/adaboost_impl.hpp b/src/mlpack/methods/adaboost/adaboost_impl.hpp
index 54da3bb..e05c098 100644
--- a/src/mlpack/methods/adaboost/adaboost_impl.hpp
+++ b/src/mlpack/methods/adaboost/adaboost_impl.hpp
@@ -222,13 +222,13 @@ void AdaBoost<MatType, WeakLearner>::Classify(
     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;
   }
diff --git a/src/mlpack/tests/adaboost_test.cpp b/src/mlpack/tests/adaboost_test.cpp
index 8769866..1d8074a 100644
--- a/src/mlpack/tests/adaboost_test.cpp
+++ b/src/mlpack/tests/adaboost_test.cpp
@@ -569,4 +569,148 @@ BOOST_AUTO_TEST_CASE(WeakLearnerErrorNonLinearSepData_DS)
   
   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
diff --git a/src/mlpack/tests/data/iris_labels.txt b/src/mlpack/tests/data/iris_labels.txt
index f040054..e7e64a8 100644
--- a/src/mlpack/tests/data/iris_labels.txt
+++ b/src/mlpack/tests/data/iris_labels.txt
@@ -147,4 +147,4 @@
 2
 2
 2
-2
\ No newline at end of file
+2
diff --git a/src/mlpack/tests/data/iris_test.csv b/src/mlpack/tests/data/iris_test.csv
new file mode 100644
index 0000000..5e8181b
--- /dev/null
+++ b/src/mlpack/tests/data/iris_test.csv
@@ -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
diff --git a/src/mlpack/tests/data/iris_test_labels.csv b/src/mlpack/tests/data/iris_test_labels.csv
new file mode 100644
index 0000000..c9f7f56
--- /dev/null
+++ b/src/mlpack/tests/data/iris_test_labels.csv
@@ -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
diff --git a/src/mlpack/tests/data/iris_train.csv b/src/mlpack/tests/data/iris_train.csv
new file mode 100644
index 0000000..f6d7b86
--- /dev/null
+++ b/src/mlpack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8
+6.5,3,5.8,2.2
+7.6,3,6.6,2.1
+4.9,2.5,4.5,1.7
+7.3,2.9,6.3,1.8
+6.7,2.5,5.8,1.8
+7.2,3.6,6.1,2.5
+6.5,3.2,5.1,2
+6.4,2.7,5.3,1.9
+6.8,3,5.5,2.1
+5.7,2.5,5,2
+5.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
diff --git a/src/mlpack/tests/data/iris_labels.txt b/src/mlpack/tests/data/iris_train_labels.csv
similarity index 58%
copy from src/mlpack/tests/data/iris_labels.txt
copy to src/mlpack/tests/data/iris_train_labels.csv
index f040054..3cb4bbf 100644
--- a/src/mlpack/tests/data/iris_labels.txt
+++ b/src/mlpack/tests/data/iris_train_labels.csv
@@ -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

-- 
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