[mlpack-svn] r16732 - mlpack/trunk/src/mlpack/methods/decision_stump
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jun 30 14:13:50 EDT 2014
Author: saxena.udit
Date: Mon Jun 30 14:13:50 2014
New Revision: 16732
Log:
Fixed subvec calls.
Modified:
mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp
mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
Modified: mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump.hpp Mon Jun 30 14:13:50 2014
@@ -108,8 +108,9 @@
* @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
Modified: mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/decision_stump/decision_stump_impl.hpp Mon Jun 30 14:13:50 2014
@@ -145,9 +145,6 @@
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 @@
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 @@
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 @@
* @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-svn
mailing list