[mlpack] 94/324: Fixed subvec calls.
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:21:59 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 c67420a9ae2b673ac0c3602970a2d2d79eb509cb
Author: saxena.udit <saxena.udit at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Mon Jun 30 18:13:50 2014 +0000
Fixed subvec calls.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16732 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../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);
--
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