[mlpack-svn] r16689 - in mlpack/trunk/src/mlpack: methods/decision_stump tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Jun 13 14:47:39 EDT 2014


Author: saxena.udit
Date: Fri Jun 13 14:47:39 2014
New Revision: 16689

Log:
Fixed armadillo issues, along with removing uninitialized and unused variables

Modified:
   mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.cpp
   mlpack/trunk/src/mlpack/tests/decision_stump_test.cpp

Modified: mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.cpp	(original)
+++ mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.cpp	Fri Jun 13 14:47:39 2014
@@ -28,7 +28,9 @@
                                       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 @@
     // 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 @@
                                       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 @@
       j = 0;
       flag = 0;
 
+      val = test(splitCol,i);
       while ((j < split.n_rows) && (!flag))
       {
         if(val < split(j,0) && (!j))
@@ -158,7 +161,8 @@
   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 @@
       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 @@
         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 @@
 
   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 @@
       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 @@
         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 @@
 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

Modified: mlpack/trunk/src/mlpack/tests/decision_stump_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/decision_stump_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/decision_stump_test.cpp	Fri Jun 13 14:47:39 2014
@@ -44,7 +44,7 @@
   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);  
 
 } 



More information about the mlpack-svn mailing list