[mlpack-git] master, mlpack-1.0.x: Use const double where possible instead of having a variable used throughout the function. This is only for clarity and consistency and is not likely to make any runtime difference. (0b56b07)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:49:37 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 0b56b07ad6caed286eb3596467f9e553b7fe8896
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Jun 24 23:29:08 2014 +0000
Use const double where possible instead of having a variable used throughout the
function. This is only for clarity and consistency and is not likely to make
any runtime difference.
>---------------------------------------------------------------
0b56b07ad6caed286eb3596467f9e553b7fe8896
.../methods/decision_stump/decision_stump_impl.hpp | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
index 9c387c7..2c757ca 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
@@ -38,7 +38,7 @@ DecisionStump<MatType>::DecisionStump(const MatType& data,
numClass = classes;
bucketSize = inpBucketSize;
- /* Check whether the input labels are not all identical. */
+ // Check whether the input labels are not all identical.
if (!isDistinct<size_t>(classLabels))
{
// If the classLabels are all identical, the default class is the only
@@ -46,7 +46,6 @@ DecisionStump<MatType>::DecisionStump(const MatType& data,
oneClass = true;
defaultClass = classLabels(0);
}
-
else
{
// If classLabels are not all identical, proceed with training.
@@ -96,34 +95,31 @@ template<typename MatType>
void DecisionStump<MatType>::Classify(const MatType& test,
arma::Row<size_t>& predictedLabels)
{
- bool flag;
- double val;
if (!oneClass)
{
for (int i = 0; i < test.n_cols; i++)
{
int j = 0;
- flag = false;
- val = test(splitCol,i);
- while ((j < split.n_rows) && (!flag))
+ const double val = test(splitCol, i);
+ while (j < split.n_rows)
{
if (val < split(j, 0) && (!j))
{
predictedLabels(i) = split(0, 1);
- flag = true;
+ break;
}
else if (val >= split(j, 0))
{
if (j == split.n_rows - 1)
{
predictedLabels(i) = split(split.n_rows - 1, 1);
- flag = true;
+ break;
}
else if (val < split(j + 1, 0))
{
predictedLabels(i) = split(j, 1);
- flag = true;
+ break;
}
}
j++;
@@ -392,7 +388,7 @@ int DecisionStump<MatType>::isDistinct(const arma::Row<rType>& featureRow)
}
/**
- * Calculating Entropy of attribute.
+ * Calculate entropy of attribute.
*
* @param attribute The attribute for which we calculate the entropy.
* @param labels Corresponding labels of the attribute.
More information about the mlpack-git
mailing list