diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp index fed45340e3..12c879db90 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp @@ -271,7 +271,7 @@ class RectangleTree size_t& Begin() { return begin; } /** - * Gets the index one beyond the last index in the subset. + * Gets the index one beyond the last index in the subset. CURRENTLY MEANINGLESS! */ size_t End() const; @@ -305,18 +305,18 @@ class RectangleTree } /** - * Splits the current node, assigning its left and right children recursively. + * Splits the current node, recursing up the tree. * - * @param data Dataset which we are using. + * @param tree The RectangleTree object (node) to split. */ - void SplitNode(MatType& data); + void SplitNode(RectangleTree& tree); /** - * Splits the current node, assigning its left and right children recursively. - * Also returns a list of the changed indices. + * Splits the current node, recursing up the tree. + * CURRENTLY IT DOES NOT Also returns a list of the changed indices. * * @param data Dataset which we are using. - * @param oldFromNew Vector holding permuted indices. + * @param oldFromNew Vector holding permuted indices NOT IMPLEMENTED. */ void SplitNode(MatType& data, std::vector& oldFromNew); diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp index dd063a4efe..df48dcbdc1 100644 --- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp +++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp @@ -6,17 +6,138 @@ #ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_IMPL_HPP #define __MLPACK_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_IMPL_HPP -// In case it wasn't included already for sem reason. +// In case it wasn't included already for some reason. #include "rectangle_tree.hpp" +#include +#include +#include + namespace mlpack { namespace tree { template -RectangleTree::RectangleTree() +RectangleTree::RectangleTree( + MatType& data, + const size_t leafSize): +{ + //Do the actual stuff here + +} + +/** + * 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. + */ +template +RectangleTree:: + ~RectangleTree() +{ + for(int i = 0; i < numOfChildren; i++) { + delete children[i]; + } +} + +template +size_t RectangleTree:: + TreeSize() const +{ + int n = 0; + for(int i = 0; i < numOfChildren; i++) { + n += children[i].TreeSize(); + } + return n + 1; // we add one for this node +} + + + +template +size_t RectangleTree:: + TreeDepth() const +{ + // Recursively count the depth of each subtree. The plus one is + // because we have to count this node, too. + int maxSubDepth = 0; + for(int i = 0; i < numOfChildren; i++) { + int d = children[i].depth(); + if(d > maxSubDepth) + maxSubDepth = d; + } + return maxSubDepth + 1; +} + +template +inline bool BinarySpaceTree:: + IsLeaf() const +{ + return numOfChildren == 0; +} + +/** + * Return the last point in the tree. SINCE THE TREE STORES DATA SEPARATELY IN EACH LEAF + * THIS IS CURRENTLY MEANINGLESS. + */ +template +inline size_t RectangleTree::End() const +{ + if(numOfChildren) + return begin + count; + return children[numOfChildren-1].End(); +} + + //have functions for returning the list of modified indices if we end up doing it that way. + +/** + * Split the tree. This moves up the tree recursively. + */ +template +void RectangleTree::SplitNode( + RetangleTree& tree) +{ + +} + + +/** + * Returns a string representation of this object. + */ + template +std::string BinarySpaceTree::ToString() const +{ + std::ostringstream convert; + convert << "RectangleTree [" << this << "]" << std::endl; + convert << " First point: " << begin << std::endl; + convert << " Number of descendants: " << count << std::endl; + convert << " Bound: " << std::endl; + convert << mlpack::util::Indent(bound.ToString(), 2); + convert << " Statistic: " << std::endl; + convert << mlpack::util::Indent(stat.ToString(), 2); + convert << " Leaf size: " << leafSize << std::endl; + convert << " Split dimension: " << splitDimension << std::endl; + + // How many levels should we print? This will print the top two tree levels. + for( +} }; //namespace tree }; //namespace mlpack + +#endif