[mlpack] 29/37: Fix usage of log2(), which does not exist in C99.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Mon Feb 15 19:35:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to tag mlpack-1.0.10
in repository mlpack.
commit b5cdc90aa77c7d1cca5fd1706a082066415f9f97
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.
---
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
--
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