[mlpack] 60/324: Fixed armadillo issues, along with removing uninitialized and unused variables

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:21:56 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 b4f6095268995b66779b0ffe2f8e5c61c0cd4871
Author: saxena.udit <saxena.udit at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Fri Jun 13 18:47:39 2014 +0000

    Fixed armadillo issues, along with removing uninitialized and unused variables
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16689 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 .../methods/decision_stump/decision_stump_impl.cpp | 59 ++++++++++++++--------
 src/mlpack/tests/decision_stump_test.cpp           |  2 +-
 2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.cpp b/src/mlpack/methods/decision_stump/decision_stump_impl.cpp
index 007a255..f216987 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.cpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.cpp
@@ -28,7 +28,9 @@ DecisionStump<MatType>::DecisionStump(const MatType& data,
                                       const size_t classes,
                                       size_t inpBucketSize)
 {
-  classLabels = labels + arma::zeros<arma::Row<size_t> >(labels.n_elem);
+  arma::Row<size_t> zLabels(labels.n_elem);
+  zLabels.fill(0);
+  classLabels = labels + zLabels;
   
   numClass = classes;
   bucketSize = inpBucketSize;
@@ -48,7 +50,7 @@ DecisionStump<MatType>::DecisionStump(const MatType& data,
     // proceed for training
 
     oneClass = 0;
-    int bestAtt=-1,i,j;
+    int bestAtt=-1,i;
     double entropy,bestEntropy=DBL_MAX; 
 
     // Set the default class to handle attribute values which are 
@@ -96,7 +98,7 @@ void DecisionStump<MatType>::Classify(const MatType& test,
                                       arma::Row<size_t>& predictedLabels)
 {
   int i,j,flag;
-  double val,testval;
+  double val;
   if ( !oneClass )
   {
     for (i = 0; i < test.n_cols; i++)
@@ -104,6 +106,7 @@ void DecisionStump<MatType>::Classify(const MatType& test,
       j = 0;
       flag = 0;
 
+      val = test(splitCol,i);
       while ((j < split.n_rows) && (!flag))
       {
         if(val < split(j,0) && (!j))
@@ -158,7 +161,8 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
   arma::uvec sortedIndexAtt = arma::stable_sort_index(attribute.t());
 
   // vector of sorted labels
-  arma::Row<size_t> sortedLabels(attribute.n_elem,arma::fill::zeros);
+  arma::Row<size_t> sortedLabels(attribute.n_elem);
+  sortedLabels.fill(0);
   
   for (i = 0; i < attribute.n_elem; i++)
     sortedLabels(i) = classLabels(sortedIndexAtt(i));
@@ -178,11 +182,15 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
       begin = i - count + 1;
       end = i;
 
-      subColLabels = sortedLabels.cols(begin, end) + 
-              arma::zeros<arma::rowvec>((sortedLabels.cols(begin, end)).n_elem);
+      arma::rowvec zSubColLabels((sortedLabels.cols(begin, end)).n_elem);
+      zSubColLabels.fill(0.0);
 
-      subColAtts = sortedAtt.cols(begin, end) + 
-              arma::zeros<arma::rowvec>((sortedAtt.cols(begin, end)).n_elem);
+      arma::rowvec zSubColAtts((sortedAtt.cols(begin, end)).n_elem);
+      zSubColAtts.fill(0.0);
+
+      subColLabels = sortedLabels.cols(begin, end) + zSubColLabels;
+
+      subColAtts = sortedAtt.cols(begin, end) + zSubColAtts;
 
       entropy += CalculateEntropy(subColAtts, subColLabels);
       i++;
@@ -203,11 +211,15 @@ double DecisionStump<MatType>::SetupSplitAttribute(const arma::rowvec& attribute
         end = i;
       }
 
-      subColLabels = sortedLabels.cols(begin, end) + 
-              arma::zeros<arma::rowvec>((sortedLabels.cols(begin, end)).n_elem);
+      arma::rowvec zSubColLabels((sortedLabels.cols(begin, end)).n_elem);
+      zSubColLabels.fill(0.0);
+
+      arma::rowvec zSubColAtts((sortedAtt.cols(begin, end)).n_elem);
+      zSubColAtts.fill(0.0);
 
-      subColAtts = sortedAtt.cols(begin, end) + 
-              arma::zeros<arma::rowvec>((sortedAtt.cols(begin, end)).n_elem);
+      subColLabels = sortedLabels.cols(begin, end) + zSubColLabels;
+
+      subColAtts = sortedAtt.cols(begin, end) + zSubColAtts;
 
       // now using subColLabels and subColAtts to calculate entropuy
       entropy += CalculateEntropy(subColAtts, subColLabels);
@@ -237,7 +249,8 @@ void DecisionStump<MatType>::TrainOnAtt(const arma::rowvec& attribute)
 
   arma::rowvec sortedSplitAtt = arma::sort(attribute);
   arma::uvec sortedSplitIndexAtt = arma::stable_sort_index(attribute.t());
-  arma::Row<size_t> sortedLabels(attribute.n_elem,arma::fill::zeros);
+  arma::Row<size_t> sortedLabels(attribute.n_elem);
+  sortedLabels.fill(0);
   arma::mat tempSplit;
 
   for (i = 0; i < attribute.n_elem; i++)
@@ -255,8 +268,10 @@ void DecisionStump<MatType>::TrainOnAtt(const arma::rowvec& attribute)
       begin = i - count + 1;
       end = i;
 
-      subCols = sortedLabels.cols(begin, end) + 
-              arma::zeros<arma::rowvec>((sortedLabels.cols(begin, end)).n_elem);
+      arma::rowvec zSubCols((sortedLabels.cols(begin, end)).n_elem);
+      zSubCols.fill(0.0);
+
+      subCols = sortedLabels.cols(begin, end) + zSubCols;
 
       mostFreq = CountMostFreq<double>(subCols);
 
@@ -280,8 +295,10 @@ void DecisionStump<MatType>::TrainOnAtt(const arma::rowvec& attribute)
         begin = i - count + 1;
         end = i;
       }
-      subCols = sortedLabels.cols(begin, end) + 
-              arma::zeros<arma::rowvec>((sortedLabels.cols(begin, end)).n_elem);
+      arma::rowvec zSubCols((sortedLabels.cols(begin, end)).n_elem);
+      zSubCols.fill(0.0);
+
+      subCols = sortedLabels.cols(begin, end) + zSubCols;
 
       // finding the most freq element in subCols so as to assign a label to the
       // bucket of subCols
@@ -391,13 +408,15 @@ template<typename MatType>
 double DecisionStump<MatType>::CalculateEntropy(const arma::rowvec& attribute,
                                                 const arma::rowvec& labels)
 {
-  int i,j,count;
+  int i,j;
   double entropy=0.0;
 
   arma::rowvec uniqueAtt = arma::unique(attribute);
   arma::rowvec uniqueLabel = arma::unique(labels);
-  arma::Row<size_t> numElem(uniqueAtt.n_elem,arma::fill::zeros); 
-  arma::Mat<size_t> entropyArray(uniqueAtt.n_elem,numClass,arma::fill::zeros); 
+  arma::Row<size_t> numElem(uniqueAtt.n_elem);
+  numElem.fill(0);
+  arma::Mat<size_t> entropyArray(uniqueAtt.n_elem,numClass);
+  entropyArray.fill(0);
   
   // populating entropyArray and numElem, they are to be used as 
   // helpers to calculate entropy
diff --git a/src/mlpack/tests/decision_stump_test.cpp b/src/mlpack/tests/decision_stump_test.cpp
index 310c93a..840b6f7 100644
--- a/src/mlpack/tests/decision_stump_test.cpp
+++ b/src/mlpack/tests/decision_stump_test.cpp
@@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(OneClass)
   Row<size_t> predictedLabels(testingData.n_cols);
   ds.Classify(testingData, predictedLabels);
 
-  for(int i = 0; i < predictedLabels.size(); i++ )
+  for(size_t i = 0; i < predictedLabels.size(); i++ )
     BOOST_CHECK_EQUAL(predictedLabels(i),1);  
 
 } 

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