[mlpack-svn] r10842 - mlpack/trunk/src/mlpack/core/tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Dec 16 01:37:10 EST 2011
Author: rcurtin
Date: 2011-12-16 01:37:10 -0500 (Fri, 16 Dec 2011)
New Revision: 10842
Modified:
mlpack/trunk/src/mlpack/core/tree/ballbound.hpp
mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp
mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp
mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
Log:
Clean up BallBound code; now, expand things in batch because that's better.
Modified: mlpack/trunk/src/mlpack/core/tree/ballbound.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/ballbound.hpp 2011-12-16 06:36:29 UTC (rev 10841)
+++ mlpack/trunk/src/mlpack/core/tree/ballbound.hpp 2011-12-16 06:37:10 UTC (rev 10842)
@@ -113,9 +113,15 @@
const BallBound& operator|=(const BallBound& other);
/**
- * Expand the bound to include the given point.
+ * Expand the bound to include the given point. The centroid is recalculated
+ * to be the center of all of the given points.
+ *
+ * @tparam MatType Type of matrix; could be arma::mat, arma::spmat, or a
+ * vector.
+ * @tparam data Data points to add.
*/
- const BallBound& operator|=(const VecType& point);
+ template<typename MatType>
+ const BallBound& operator|=(const MatType& data);
};
}; // namespace bound
Modified: mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp 2011-12-16 06:36:29 UTC (rev 10841)
+++ mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp 2011-12-16 06:37:10 UTC (rev 10842)
@@ -110,7 +110,7 @@
/**
* Expand the bound to include the given bound.
- */
+ *
template<typename VecType>
const BallBound<VecType>&
BallBound<VecType>::operator|=(
@@ -123,14 +123,15 @@
radius = dist;
return *this;
-}
+}*/
/**
* Expand the bound to include the given point.
*/
template<typename VecType>
+template<typename MatType>
const BallBound<VecType>&
-BallBound<VecType>::operator|=(const VecType& point)
+BallBound<VecType>::operator|=(const MatType& point)
{
double dist = metric::EuclideanDistance::Evaluate(center, point);
Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp 2011-12-16 06:36:29 UTC (rev 10841)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree_impl.hpp 2011-12-16 06:37:10 UTC (rev 10842)
@@ -389,10 +389,8 @@
template<typename BoundType, typename StatisticType, typename MatType>
void BinarySpaceTree<BoundType, StatisticType, MatType>::SplitNode(MatType& data)
{
- // This should be a single function for Bound.
// We need to expand the bounds of this node properly.
- for (size_t i = begin; i < (begin + count); i++)
- bound |= data.col(i);
+ bound |= data.cols(begin, begin + count - 1);
// Now, check if we need to split at all.
if (count <= leafSize)
@@ -441,8 +439,7 @@
{
// This should be a single function for Bound.
// We need to expand the bounds of this node properly.
- for (size_t i = begin; i < (begin + count); i++)
- bound |= data.col(i);
+ bound |= data.cols(begin, begin + count - 1);
// First, check if we need to split at all.
if (count <= leafSize)
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp 2011-12-16 06:36:29 UTC (rev 10841)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp 2011-12-16 06:37:10 UTC (rev 10842)
@@ -106,10 +106,14 @@
math::Range RangeDistance(const VecType& point) const;
/**
- * Expands this region to include a new point.
+ * Expands this region to include new points.
+ *
+ * @tparam MatType Type of matrix; could be Mat, SpMat, a subview, or just a
+ * vector.
+ * @param data Data points to expand this region to include.
*/
- template<typename VecType>
- HRectBound& operator|=(const VecType& vector);
+ template<typename MatType>
+ HRectBound& operator|=(const MatType& data);
/**
* Expands this region to encompass another bound.
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp 2011-12-16 06:36:29 UTC (rev 10841)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp 2011-12-16 06:37:10 UTC (rev 10842)
@@ -310,13 +310,16 @@
* Expands this region to include a new point.
*/
template<int t_pow>
-template<typename VecType>
-HRectBound<t_pow>& HRectBound<t_pow>::operator|=(const VecType& vector)
+template<typename MatType>
+HRectBound<t_pow>& HRectBound<t_pow>::operator|=(const MatType& data)
{
- Log::Assert(vector.n_elem == dim);
+ Log::Assert(data.n_rows == dim);
+ arma::vec mins = min(data, 1);
+ arma::vec maxs = max(data, 1);
+
for (size_t i = 0; i < dim; i++)
- bounds[i] |= vector[i];
+ bounds[i] |= math::Range(mins[i], maxs[i]);
return *this;
}
More information about the mlpack-svn
mailing list