[mlpack-git] master: Fix #745: set scale correctly when the dataset size is 0. (20d8f45)
gitdub at mlpack.org
gitdub at mlpack.org
Sat Aug 6 00:47:17 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/53a028176c72c8f695a51881e993a84a225d738e...20d8f45a841071e83d501794da6f7092cbf1dee7
>---------------------------------------------------------------
commit 20d8f45a841071e83d501794da6f7092cbf1dee7
Author: Ryan Curtin <ryan at ratml.org>
Date: Sat Aug 6 00:47:17 2016 -0400
Fix #745: set scale correctly when the dataset size is 0.
>---------------------------------------------------------------
20d8f45a841071e83d501794da6f7092cbf1dee7
.../core/tree/cover_tree/cover_tree_impl.hpp | 32 +++++++++++++++++++---
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp b/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
index 3d3b012..7c6de7f 100644
--- a/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
+++ b/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
@@ -46,7 +46,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// If there is only one point or zero points in the dataset... uh, we're done.
// Technically, if the dataset has zero points, our node is not correct...
if (dataset.n_cols <= 1)
+ {
+ scale = INT_MIN;
return;
+ }
// Kick off the building. Create the indices array and the distances array.
arma::Col<size_t> indices = arma::linspace<arma::Col<size_t> >(1,
@@ -96,7 +99,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// Use the furthest descendant distance to determine the scale of the root
// node.
- scale = (int) ceil(log(furthestDescendantDistance) / log(base));
+ if (furthestDescendantDistance == 0.0)
+ scale = INT_MIN;
+ else
+ scale = (int) ceil(log(furthestDescendantDistance) / log(base));
// Initialize statistic.
stat = StatisticType(*this);
@@ -131,7 +137,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// If there is only one point or zero points in the dataset... uh, we're done.
// Technically, if the dataset has zero points, our node is not correct...
if (dataset.n_cols <= 1)
+ {
+ scale = INT_MIN;
return;
+ }
// Kick off the building. Create the indices array and the distances array.
arma::Col<size_t> indices = arma::linspace<arma::Col<size_t> >(1,
@@ -182,7 +191,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// Use the furthest descendant distance to determine the scale of the root
// node.
- scale = (int) ceil(log(furthestDescendantDistance) / log(base));
+ if (furthestDescendantDistance == 0.0)
+ scale = INT_MIN;
+ else
+ scale = (int) ceil(log(furthestDescendantDistance) / log(base));
// Initialize statistic.
stat = StatisticType(*this);
@@ -218,7 +230,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// If there is only one point or zero points in the dataset... uh, we're done.
// Technically, if the dataset has zero points, our node is not correct...
if (dataset->n_cols <= 1)
+ {
+ scale = INT_MIN;
return;
+ }
// Kick off the building. Create the indices array and the distances array.
arma::Col<size_t> indices = arma::linspace<arma::Col<size_t> >(1,
@@ -268,7 +283,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// Use the furthest descendant distance to determine the scale of the root
// node.
- scale = (int) ceil(log(furthestDescendantDistance) / log(base));
+ if (furthestDescendantDistance == 0.0)
+ scale = INT_MIN;
+ else
+ scale = (int) ceil(log(furthestDescendantDistance) / log(base));
// Initialize statistic.
stat = StatisticType(*this);
@@ -303,7 +321,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// If there is only one point or zero points in the dataset... uh, we're done.
// Technically, if the dataset has zero points, our node is not correct...
if (dataset->n_cols <= 1)
+ {
+ scale = INT_MIN;
return;
+ }
// Kick off the building. Create the indices array and the distances array.
arma::Col<size_t> indices = arma::linspace<arma::Col<size_t> >(1,
@@ -353,7 +374,10 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
// Use the furthest descendant distance to determine the scale of the root
// node.
- scale = (int) ceil(log(furthestDescendantDistance) / log(base));
+ if (furthestDescendantDistance == 0.0)
+ scale = INT_MIN;
+ else
+ scale = (int) ceil(log(furthestDescendantDistance) / log(base));
// Initialize statistic.
stat = StatisticType(*this);
More information about the mlpack-git
mailing list