[mlpack] 168/324: Add MinimumBoundDistance(). This represents the minimum distance between the center of a node and any edge of the bound. Note that for ball bounds, this is equivalent to the furthest descendant distance.
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:22:07 UTC 2014
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit 94745c0043e564998d8b370fe44f0119c3530853
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Thu Jul 10 14:02:09 2014 +0000
Add MinimumBoundDistance().
This represents the minimum distance between the center of a node and any edge
of the bound. Note that for ball bounds, this is equivalent to the furthest
descendant distance.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16807 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../tree/binary_space_tree/binary_space_tree.hpp | 8 +++++-
.../binary_space_tree/binary_space_tree_impl.hpp | 30 ++++++++++++++++++++++
src/mlpack/core/tree/cover_tree/cover_tree.hpp | 4 +++
.../core/tree/rectangle_tree/rectangle_tree.hpp | 7 ++++-
4 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
index 0356f8e..eadd300 100644
--- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
@@ -66,8 +66,11 @@ class BinarySpaceTree
size_t splitDimension;
//! The distance from the centroid of this node to the centroid of the parent.
double parentDistance;
- //! The worst possible distance to the furthest descendant, cached to speed things up.
+ //! The worst possible distance to the furthest descendant, cached to speed
+ //! things up.
double furthestDescendantDistance;
+ //! The minimum distance from the center to any edge of the bound.
+ double minimumBoundDistance;
//! The dataset.
MatType& dataset;
@@ -308,6 +311,9 @@ class BinarySpaceTree
*/
double FurthestDescendantDistance() const;
+ //! Return the minimum distance from the center of the node to any bound edge.
+ double MinimumBoundDistance() const;
+
//! Return the distance from the center of this node to the center of the
//! parent node.
double ParentDistance() const { return parentDistance; }
diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
index 77d949b..f8eb5cf 100644
--- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
@@ -238,6 +238,7 @@ BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::BinarySpaceTree(
splitDimension(other.splitDimension),
parentDistance(other.parentDistance),
furthestDescendantDistance(other.furthestDescendantDistance),
+ minimumBoundDistance(other.minimumBoundDistance),
dataset(other.dataset)
{
// Create left and right children (if any).
@@ -462,6 +463,17 @@ inline double BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::
return furthestDescendantDistance;
}
+//! Return the minimum distance from the center to any bound edge.
+template<typename BoundType,
+ typename StatisticType,
+ typename MatType,
+ typename SplitType>
+inline double BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::
+ MinimumBoundDistance() const
+{
+ return minimumBoundDistance;
+}
+
/**
* Return the specified child.
*/
@@ -560,6 +572,15 @@ void BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::SplitNode(
// Calculate the furthest descendant distance.
furthestDescendantDistance = 0.5 * bound.Diameter();
+ // Find the minimum distance to any bound edge.
+ minimumBoundDistance = DBL_MAX;
+ for (size_t i = 0; i < bound.Dim(); ++i)
+ {
+ const double dist = std::max(bound[i].Hi() - bound[i].Lo(), 0.0);
+ if (dist < minimumBoundDistance)
+ minimumBoundDistance = dist;
+ }
+
// Now, check if we need to split at all.
if (count <= maxLeafSize)
return; // We can't split this.
@@ -616,6 +637,15 @@ void BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::SplitNode(
// Calculate the furthest descendant distance.
furthestDescendantDistance = 0.5 * bound.Diameter();
+ // Find the minimum distance to any bound edge.
+ minimumBoundDistance = DBL_MAX;
+ for (size_t i = 0; i < bound.Dim(); ++i)
+ {
+ const double dist = std::max(bound[i].Hi() - bound[i].Lo(), 0.0);
+ if (dist < minimumBoundDistance)
+ minimumBoundDistance = dist;
+ }
+
// First, check if we need to split at all.
if (count <= maxLeafSize)
return; // We can't split this.
diff --git a/src/mlpack/core/tree/cover_tree/cover_tree.hpp b/src/mlpack/core/tree/cover_tree/cover_tree.hpp
index 088588a..bad4b8b 100644
--- a/src/mlpack/core/tree/cover_tree/cover_tree.hpp
+++ b/src/mlpack/core/tree/cover_tree/cover_tree.hpp
@@ -320,6 +320,10 @@ class CoverTree
//! descendant.
double& FurthestDescendantDistance() { return furthestDescendantDistance; }
+ //! Get the minimum distance from the center to any bound edge (this is the
+ //! same as furthestDescendantDistance).
+ double MinimumBoundDistance() const { return furthestDescendantDistance; }
+
//! Get the centroid of the node and store it in the given vector.
void Centroid(arma::vec& centroid) const { centroid = dataset.col(point); }
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
index 76f879e..564454c 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
@@ -228,7 +228,7 @@ class RectangleTree
const std::vector<size_t>& Points() const { return points; }
//! Modify the points vector for this node. Be careful!
std::vector<size_t>& Points() { return points; }
-
+
//! Get the local dataset of this node.
const arma::mat& LocalDataset() const { return *localDataset; }
//! Modify the local dataset of this node.
@@ -265,6 +265,11 @@ class RectangleTree
*/
double FurthestDescendantDistance() const;
+ //! Return the minimum distance from the center to any edge of the bound.
+ //! Currently, this returns 0, which doesn't break algorithms, but it isn't
+ //! necessarily correct, either.
+ double MinimumBoundDistance() const { return 0.0; }
+
//! Return the distance from the center of this node to the center of the
//! parent node.
double ParentDistance() const { return parentDistance; }
--
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