[mlpack] 257/324: Minor code cleanups.
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:22:16 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 4ace3ee4590169be94a0ee095f1ea164eadcb193
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Mon Aug 4 15:18:30 2014 +0000
Minor code cleanups.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16936 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../methods/decision_stump/decision_stump.hpp | 35 ++++++++++---------
.../methods/decision_stump/decision_stump_impl.hpp | 40 +++++++++++-----------
2 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/src/mlpack/methods/decision_stump/decision_stump.hpp b/src/mlpack/methods/decision_stump/decision_stump.hpp
index d4a7235..895fd4a 100644
--- a/src/mlpack/methods/decision_stump/decision_stump.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump.hpp
@@ -54,23 +54,21 @@ class DecisionStump
void Classify(const MatType& test, arma::Row<size_t>& predictedLabels);
/**
- * Alternate constructor which copies parameters bucketSize and numClass
- * from an already initiated decision stump, other. It appropriately
- * sets the Weight vector.
+ * Alternate constructor which copies parameters bucketSize and numClass from
+ * an already initiated decision stump, other. It appropriately sets the
+ * weight vector.
*
- * @param other The other initiated Decision Stump object from
- * which we copy the values from.
- * @param data The data on which to train this object on.
- * @param D Weight vector to use while training. For boosting purposes.
- * @param labels The labels of data.
+ * @param other The other initiated Decision Stump object from
+ * which we copy the values from.
+ * @param data The data on which to train this object on.
+ * @param D Weight vector to use while training. For boosting purposes.
+ * @param labels The labels of data.
*/
- DecisionStump(
- const DecisionStump<>& other,
- const MatType& data,
- const arma::rowvec& weights,
- const arma::Row<size_t>& labels
- );
-
+ DecisionStump(const DecisionStump<>& other,
+ const MatType& data,
+ const arma::rowvec& weights,
+ const arma::Row<size_t>& labels);
+
//! Access the splitting attribute.
int SplitAttribute() const { return splitAttribute; }
//! Modify the splitting attribute (be careful!).
@@ -134,7 +132,8 @@ class DecisionStump
* @param subCols The vector in which to find the most frequently
* occurring element.
*/
- template <typename rType> rType CountMostFreq(const arma::Row<rType>& subCols);
+ template <typename rType> rType CountMostFreq(const arma::Row<rType>&
+ subCols);
/**
* Returns 1 if all the values of featureRow are not same.
@@ -153,8 +152,10 @@ class DecisionStump
double CalculateEntropy(arma::subview_row<LabelType> labels, int begin);
/**
+ * Train the decision stump on the given data and labels.
*
- *
+ * @param data Dataset to train on.
+ * @param labels Labels for dataset.
*/
void Train(const MatType& data, const arma::Row<size_t>& labels);
diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
index 419abae..ee095ff 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
@@ -60,7 +60,6 @@ void DecisionStump<MatType>::Train(const MatType& data, const arma::Row<size_t>&
// splitting attribute and calculate entropy if split on it.
entropy = SetupSplitAttribute(data.row(i), labels);
- // Log::Debug << "Entropy for attribute " << i << " is " << entropy << ".\n";
gain = rootEntropy - entropy;
// Find the attribute with the best entropy so that the gain is
// maximized.
@@ -114,21 +113,21 @@ void DecisionStump<MatType>::Classify(const MatType& test,
}
/**
- * Alternate constructor which copies parameters bucketSize and numClass
- * from an already initiated decision stump, other. It appropriately
- * sets the Weight vector.
+ * Alternate constructor which copies parameters bucketSize and numClass
+ * from an already initiated decision stump, other. It appropriately
+ * sets the Weight vector.
*
- * @param other The other initiated Decision Stump object from
- * which we copy the values from.
- * @param data The data on which to train this object on.
- * @param D Weight vector to use while training. For boosting purposes.
- * @param labels The labels of data.
+ * @param other The other initiated Decision Stump object from
+ * which we copy the values from.
+ * @param data The data on which to train this object on.
+ * @param D Weight vector to use while training. For boosting purposes.
+ * @param labels The labels of data.
*/
template <typename MatType>
DecisionStump<MatType>::DecisionStump(
- const DecisionStump<>& other,
- const MatType& data,
- const arma::rowvec& weights,
+ const DecisionStump<>& other,
+ const MatType& data,
+ const arma::rowvec& weights,
const arma::Row<size_t>& labels
)
{
@@ -173,7 +172,7 @@ double DecisionStump<MatType>::SetupSplitAttribute(
sortedLabels(i) = labels(sortedIndexAtt(i));
tempD(i) = weightD(sortedIndexAtt(i));
}
-
+
i = 0;
count = 0;
@@ -411,7 +410,9 @@ int DecisionStump<MatType>::IsDistinct(const arma::Row<rType>& featureRow)
*/
template<typename MatType>
template<typename LabelType>
-double DecisionStump<MatType>::CalculateEntropy(arma::subview_row<LabelType> labels, int begin)
+double DecisionStump<MatType>::CalculateEntropy(
+ arma::subview_row<LabelType> labels,
+ int begin)
{
double entropy = 0.0;
size_t j;
@@ -419,21 +420,20 @@ double DecisionStump<MatType>::CalculateEntropy(arma::subview_row<LabelType> lab
arma::Row<size_t> numElem(numClass);
numElem.fill(0);
- // variable to accumulate the weight in this subview_row
+ // Variable to accumulate the weight in this subview_row.
double accWeight = 0.0;
- // Populate numElem; they are used as helpers to calculate
- // entropy.
-
+ // Populate numElem; they are used as helpers to calculate entropy.
+
for (j = 0; j < labels.n_elem; j++)
{
numElem(labels(j)) += tempD(j + begin);
accWeight += tempD(j + begin);
- }
+ }
// numElem(labels(j))++;
for (j = 0; j < numClass; j++)
{
- const double p1 = ((double) numElem(j) / accWeight);
+ const double p1 = ((double) numElem(j) / accWeight);
entropy += (p1 == 0) ? 0 : p1 * log2(p1);
}
--
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