[mlpack-svn] r14046 - 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
Fri Dec 21 15:31:40 EST 2012
Author: rcurtin
Date: 2012-12-21 15:31:40 -0500 (Fri, 21 Dec 2012)
New Revision: 14046
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:
Minor refactoring of BinarySpaceTree and addition of copy constructor.
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 2012-12-21 20:01:45 UTC (rev 14045)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp 2012-12-21 20:31:40 UTC (rev 14046)
@@ -182,6 +182,14 @@
const size_t leafSize = 20);
/**
+ * Create a binary space tree by copying the other tree. Be careful! This
+ * can take a long time and use a lot of memory.
+ *
+ * @param other Tree to be replicated.
+ */
+ BinarySpaceTree(const BinarySpaceTree& other);
+
+ /**
* Create an empty tree node.
*/
BinarySpaceTree();
@@ -221,30 +229,41 @@
BinarySpaceTree* FindByBeginCount(size_t begin, size_t count);
//! Return the bound object for this node.
- const BoundType& Bound() const;
+ const BoundType& Bound() const { return bound; }
//! Return the bound object for this node.
- BoundType& Bound();
+ BoundType& Bound() { return bound; }
//! Return the statistic object for this node.
- const StatisticType& Stat() const;
+ const StatisticType& Stat() const { return stat; }
//! Return the statistic object for this node.
- StatisticType& Stat();
+ StatisticType& Stat() { return stat; }
//! Return whether or not this node is a leaf (true if it has no children).
bool IsLeaf() const;
//! Return the leaf size.
- size_t LeafSize() const;
+ size_t LeafSize() const { return leafSize; }
+ //! Modify the leaf size.
+ size_t& LeafSize() { return leafSize; }
//! Fills the tree to the specified level.
size_t ExtendTree(const size_t level);
//! Gets the left child of this node.
- BinarySpaceTree* Left() const;
+ BinarySpaceTree* Left() const { return left; }
+ //! Modify the left child of this node.
+ BinarySpaceTree*& Left() { return left; }
//! Gets the right child of this node.
- BinarySpaceTree* Right() const;
+ BinarySpaceTree* Right() const { return right; }
+ //! Modify the right child of this node.
+ BinarySpaceTree*& Right() { return right; }
+ //! Get the split dimension for this node.
+ size_t SplitDimension() const { return splitDimension; }
+ //! Modify the split dimension for this node.
+ size_t& SplitDimension() { return splitDimension; }
+
//! Return the number of children in this node.
size_t NumChildren() const;
@@ -318,20 +337,20 @@
*/
size_t TreeDepth() const;
- /**
- * Gets the index of the beginning point of this subset.
- */
- size_t Begin() const;
+ //! Return the index of the beginning point of this subset.
+ size_t Begin() const { return begin; }
+ //! Modify the index of the beginning point of this subset.
+ size_t& Begin() { return begin; }
/**
* Gets the index one beyond the last index in the subset.
*/
size_t End() const;
- /**
- * Gets the number of points in this subset.
- */
- size_t Count() const;
+ //! Return the number of points in this subset.
+ size_t Count() const { return count; }
+ //! Modify the number of points in this subset.
+ size_t& Count() { return count; }
//! Returns false: this tree type does not have self children.
static bool HasSelfChildren() { return false; }
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 2012-12-21 20:01:45 UTC (rev 14045)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp 2012-12-21 20:31:40 UTC (rev 14046)
@@ -204,6 +204,30 @@
}
/**
+ * Create a binary space tree by copying the other tree. Be careful! This can
+ * take a long time and use a lot of memory.
+ */
+template<typename BoundType, typename StatisticType, typename MatType>
+BinarySpaceTree<BoundType, StatisticType, MatType>::BinarySpaceTree(
+ const BinarySpaceTree& other) :
+ left(NULL),
+ right(NULL),
+ begin(other.Begin()),
+ count(other.Count()),
+ bound(other.Bound()),
+ stat(other.Stat()),
+ leafSize(other.LeafSize()),
+ splitDimension(other.SplitDimension())
+{
+ // Create left and right children (if any).
+ if (other.Left())
+ left = new BinarySpaceTree(*other.Left());
+
+ if (other.Right())
+ right = new BinarySpaceTree(*other.Right());
+}
+
+/**
* Deletes this node, deallocating the memory for the children and calling their
* destructors in turn. This will invalidate any pointers or references to any
* nodes which are children of this one.
@@ -328,64 +352,12 @@
}
template<typename BoundType, typename StatisticType, typename MatType>
-inline const
- BoundType& BinarySpaceTree<BoundType, StatisticType, MatType>::Bound() const
-{
- return bound;
-}
-
-template<typename BoundType, typename StatisticType, typename MatType>
-inline BoundType& BinarySpaceTree<BoundType, StatisticType, MatType>::Bound()
-{
- return bound;
-}
-
-template<typename BoundType, typename StatisticType, typename MatType>
-inline const StatisticType&
- BinarySpaceTree<BoundType, StatisticType, MatType>::Stat() const
-{
- return stat;
-}
-
-template<typename BoundType, typename StatisticType, typename MatType>
-inline StatisticType& BinarySpaceTree<BoundType, StatisticType, MatType>::Stat()
-{
- return stat;
-}
-
-template<typename BoundType, typename StatisticType, typename MatType>
-inline size_t BinarySpaceTree<BoundType, StatisticType, MatType>::GetSplitDimension() const
-{
- return splitDimension;
-}
-
-template<typename BoundType, typename StatisticType, typename MatType>
inline bool BinarySpaceTree<BoundType, StatisticType, MatType>::IsLeaf() const
{
return !left;
}
/**
- * Gets the left branch of the tree.
- */
-template<typename BoundType, typename StatisticType, typename MatType>
-inline BinarySpaceTree<BoundType, StatisticType, MatType>*
- BinarySpaceTree<BoundType, StatisticType, MatType>::Left() const
-{
- return left;
-}
-
-/**
- * Gets the right branch.
- */
-template<typename BoundType, typename StatisticType, typename MatType>
-inline BinarySpaceTree<BoundType, StatisticType, MatType>*
- BinarySpaceTree<BoundType, StatisticType, MatType>::Right() const
-{
- return right;
-}
-
-/**
* Returns the number of children in this node.
*/
template<typename BoundType, typename StatisticType, typename MatType>
@@ -455,15 +427,6 @@
}
/**
- * Gets the index of the begin point of this subset.
- */
-template<typename BoundType, typename StatisticType, typename MatType>
-inline size_t BinarySpaceTree<BoundType, StatisticType, MatType>::Begin() const
-{
- return begin;
-}
-
-/**
* Gets the index one beyond the last index in the series.
*/
template<typename BoundType, typename StatisticType, typename MatType>
@@ -472,16 +435,7 @@
return begin + count;
}
-/**
- * Gets the number of points in this subset.
- */
template<typename BoundType, typename StatisticType, typename MatType>
-inline size_t BinarySpaceTree<BoundType, StatisticType, MatType>::Count() const
-{
- return count;
-}
-
-template<typename BoundType, typename StatisticType, typename MatType>
void
BinarySpaceTree<BoundType, StatisticType, MatType>::SplitNode(MatType& data)
{
More information about the mlpack-svn
mailing list