[mlpack-svn] r14548 - mlpack/trunk/src/mlpack/core/tree/binary_space_tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Mar 13 16:46:41 EDT 2013
Author: rcurtin
Date: 2013-03-13 16:46:41 -0400 (Wed, 13 Mar 2013)
New Revision: 14548
Modified:
mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
Log:
Cache furthest descendant distance.
Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp 2013-03-13 20:44:40 UTC (rev 14547)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp 2013-03-13 20:46:41 UTC (rev 14548)
@@ -60,6 +60,8 @@
StatisticType stat;
//! The dimension this node split on if it is a parent.
size_t splitDimension;
+ //! The distance to the furthest descendant, cached to speed things up.
+ double furthestDescendantDistance;
//! The dataset.
MatType& dataset;
Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp 2013-03-13 20:44:40 UTC (rev 14547)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp 2013-03-13 20:46:41 UTC (rev 14548)
@@ -212,6 +212,7 @@
bound(other.bound),
stat(other.stat),
splitDimension(other.splitDimension),
+ furthestDescendantDistance(other.furthestDescendantDistance),
dataset(other.dataset)
{
// Create left and right children (if any).
@@ -384,9 +385,7 @@
inline double BinarySpaceTree<BoundType, StatisticType, MatType>::
FurthestDescendantDistance() const
{
- arma::vec centroid;
- bound.Centroid(centroid);
- return bound.MaxDistance(centroid);
+ return furthestDescendantDistance;
}
/**
@@ -443,6 +442,9 @@
// We need to expand the bounds of this node properly.
bound |= data.cols(begin, begin + count - 1);
+ // Calculate the furthest descendant distance.
+ furthestDescendantDistance = 0.5 * bound.Diameter();
+
// Now, check if we need to split at all.
if (count <= leafSize)
return; // We can't split this.
@@ -493,6 +495,9 @@
// We need to expand the bounds of this node properly.
bound |= data.cols(begin, begin + count - 1);
+ // Calculate the furthest descendant distance.
+ furthestDescendantDistance = 0.5 * bound.Diameter();
+
// First, check if we need to split at all.
if (count <= leafSize)
return; // We can't split this.
More information about the mlpack-svn
mailing list