[mlpack-git] mlpack-1.0.x: Fix usage of log2(), which does not exist in C99. (bf3dbcd)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Jan 7 11:57:24 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/0000000000000000000000000000000000000000...904762495c039e345beba14c1142fd719b3bd50e
>---------------------------------------------------------------
commit bf3dbcd4e29c6a21213a8b223054f31db64b38a5
Author: Ryan Curtin <ryan at ratml.org>
Date: Fri Aug 29 14:40:20 2014 +0000
Fix usage of log2(), which does not exist in C99.
>---------------------------------------------------------------
bf3dbcd4e29c6a21213a8b223054f31db64b38a5
src/mlpack/methods/decision_stump/decision_stump_impl.hpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
index a042b21..7ed5130 100644
--- a/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
+++ b/src/mlpack/methods/decision_stump/decision_stump_impl.hpp
@@ -428,14 +428,17 @@ double DecisionStump<MatType>::CalculateEntropy(arma::subview_row<LabelType> lab
for (j = 0; j < labels.n_elem; j++)
numElem(labels(j))++;
+ // The equation for entropy uses log2(), but log2() is from C99 and thus
+ // Visual Studio will not have it. Therefore, we will use std::log(), and
+ // then apply the change-of-base formula at the end of the calculation.
for (j = 0; j < numClass; j++)
{
const double p1 = ((double) numElem(j) / labels.n_elem);
- entropy += (p1 == 0) ? 0 : p1 * log2(p1);
+ entropy += (p1 == 0) ? 0 : p1 * std::log(p1);
}
- return entropy;
+ return entropy / std::log(2.0);
}
}; // namespace decision_stump
More information about the mlpack-git
mailing list