[mlpack-git] master: Handle dimensions with no variance better (i.e. ignore them). (4e069ab)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Feb 18 11:37:47 EST 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/50629c1d76780dc0c37c24b1dedb7794f4aa5447...4e069ab995e165f1f8c2a707120698cf74cf2f6f
>---------------------------------------------------------------
commit 4e069ab995e165f1f8c2a707120698cf74cf2f6f
Author: Ryan Curtin <ryan at ratml.org>
Date: Thu Feb 18 08:37:47 2016 -0800
Handle dimensions with no variance better (i.e. ignore them).
>---------------------------------------------------------------
4e069ab995e165f1f8c2a707120698cf74cf2f6f
src/mlpack/methods/det/dtree.cpp | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/mlpack/methods/det/dtree.cpp b/src/mlpack/methods/det/dtree.cpp
index ef27704..44e0f68 100644
--- a/src/mlpack/methods/det/dtree.cpp
+++ b/src/mlpack/methods/det/dtree.cpp
@@ -148,9 +148,18 @@ DTree::~DTree()
double DTree::LogNegativeError(const size_t totalPoints) const
{
// log(-|t|^2 / (N^2 V_t)) = log(-1) + 2 log(|t|) - 2 log(N) - log(V_t).
- return 2 * std::log((double) (end - start)) -
- 2 * std::log((double) totalPoints) -
- arma::accu(arma::log(maxVals - minVals));
+ double err = 2 * std::log((double) (end - start)) -
+ 2 * std::log((double) totalPoints);
+
+ arma::vec valDiffs = maxVals - minVals;
+ for (size_t i = 0; i < maxVals.n_elem; ++i)
+ {
+ // Ignore very small dimensions to prevent overflow.
+ if (valDiffs[i] > 1e-50)
+ err -= std::log(valDiffs[i]);
+ }
+
+ return err;
}
// This function finds the best split with respect to the L2-error, by trying
More information about the mlpack-git
mailing list