[mlpack-git] master,mlpack-1.0.x: Fixed subvec calls. (a0b3a94)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:50:13 EST 2015


Repository : https://github.com/mlpack/mlpack

On branches: master,mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit a0b3a941743e86c5c9e405a970d120a76d20b302
Author: Udit Saxena <saxena.udit at gmail.com>
Date:   Mon Jun 30 18:13:50 2014 +0000

    Fixed subvec calls.


>---------------------------------------------------------------

a0b3a941743e86c5c9e405a970d120a76d20b302
 .../methods/decision_stump/decision_stump.hpp      |  5 +--
 .../methods/decision_stump/decision_stump_impl.hpp | 41 +++++-----------------
 2 files changed, 11 insertions(+), 35 deletions(-)

diff --git a/src/mlpack/methods/decision_stump/decision_stump.hpp b/src/mlpack/methods/decision_stump/decision_stump.hpp
index fb7515d..689d7d3 100644
--- a/src/mlpack/methods/decision_stump/decision_stump.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump.hpp
@@ -108,8 +108,9 @@ class DecisionStump
    * @param attribute The attribute of which we calculate the entropy.
    * @param labels Corresponding labels of the attribute.
    */
-  double CalculateEntropy(const arma::rowvec& attribute,
-                          const arma::rowvec& labels);
+  template <typename AttType, typename LabelType>
+  double CalculateEntropy(arma::subview_row<AttType> attribute,
+                          arma::subview_row<LabelType> labels);
 };
 
 }; // namespace decision_stump
diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
index 051d1da..19a9a86 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
@@ -145,9 +145,6 @@ double DecisionStump<MatType>::SetupSplitAttribute(
   for (i = 0; i < attribute.n_elem; i++)
     sortedLabels(i) = labels(sortedIndexAtt(i));
 
-  arma::rowvec subColLabels;
-  arma::rowvec subColAtts;
-
   i = 0;
   count = 0;
 
@@ -163,19 +160,8 @@ double DecisionStump<MatType>::SetupSplitAttribute(
       begin = i - count + 1;
       end = i;
 
-      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);
-
-      subColLabels = sortedLabels.cols(begin, end) + zSubColLabels; 
-              // arma::zeros<arma::rowvec>((sortedLabels.cols(begin, end)).n_elem);
-
-      subColAtts = sortedAtt.cols(begin, end) + zSubColAtts;
-              // arma::zeros<arma::rowvec>((sortedAtt.cols(begin, end)).n_elem);
-
-      entropy += CalculateEntropy(subColAtts, subColLabels);
+      entropy += CalculateEntropy<double,long unsigned int>(
+                 sortedAtt.subvec(begin,end),sortedLabels.subvec(begin,end));
       i++;
     }
     else if (sortedLabels(i) != sortedLabels(i + 1))
@@ -198,20 +184,8 @@ double DecisionStump<MatType>::SetupSplitAttribute(
         end = i;
       }
 
-      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);
-
-      subColLabels = sortedLabels.cols(begin, end) + zSubColLabels;
-              // arma::zeros<arma::rowvec>((sortedLabels.cols(begin, end)).n_elem);
-
-      subColAtts = sortedAtt.cols(begin, end) + zSubColAtts;
-              // arma::zeros<arma::rowvec>((sortedAtt.cols(begin, end)).n_elem);
-
-      // now using subColLabels and subColAtts to calculate entropuy
-      entropy += CalculateEntropy(subColAtts, subColLabels);
+      entropy += CalculateEntropy<double,long unsigned int>(
+                 sortedAtt.subvec(begin,end),sortedLabels.subvec(begin,end));
 
       i = end + 1;
       count = 0;
@@ -397,13 +371,14 @@ int DecisionStump<MatType>::isDistinct(const arma::Row<rType>& featureRow)
  * @param labels Corresponding labels of the attribute.
  */
 template<typename MatType>
-double DecisionStump<MatType>::CalculateEntropy(const arma::rowvec& attribute,
-                                                const arma::rowvec& labels)
+template<typename AttType, typename LabelType>
+double DecisionStump<MatType>::CalculateEntropy(arma::subview_row<AttType> attribute,
+                                                arma::subview_row<LabelType> labels)
 {
   double entropy = 0.0;
 
   arma::rowvec uniqueAtt = arma::unique(attribute);
-  arma::rowvec uniqueLabel = arma::unique(labels);
+  arma::Row<LabelType> uniqueLabel = arma::unique(labels);
   arma::Row<size_t> numElem(uniqueAtt.n_elem);
   numElem.fill(0);
   arma::Mat<size_t> entropyArray(uniqueAtt.n_elem,numClass);



More information about the mlpack-git mailing list