[mlpack-git] master, mlpack-1.0.x: more code for the RectangleTree. Still not built yet. (461b6bd)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:47:40 EST 2015
Repository : https://github.com/mlpack/mlpack
On branches: master,mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 461b6bd0d9525ccee010bb47da21aa1ccdb313a1
Author: andrewmw94 <andrewmw94 at gmail.com>
Date: Mon May 26 11:35:15 2014 +0000
more code for the RectangleTree. Still not built yet.
>---------------------------------------------------------------
461b6bd0d9525ccee010bb47da21aa1ccdb313a1
.../core/tree/rectangle_tree/rectangle_tree.hpp | 14 +--
.../tree/rectangle_tree/rectangle_tree_impl.hpp | 125 ++++++++++++++++++++-
2 files changed, 130 insertions(+), 9 deletions(-)
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
index fed4534..12c879d 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<size_t>& 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 dd063a4..df48dcb 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 <mlpack/core/util/cli.hpp>
+#include <mlpack/core/util/log.hpp>
+#include <mlpack/core/util/string_util.hpp>
+
namespace mlpack {
namespace tree {
template<typename StatisticType,
typename MatType,
typename SplitType>
-RectangleTree<StatisticType, MatType, SplitType>::RectangleTree()
+RectangleTree<StatisticType, MatType, SplitType>::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<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+RectangleTree<BoundType, StatisticType, MatType, SplitType>::
+ ~RectangleTree()
+{
+ for(int i = 0; i < numOfChildren; i++) {
+ delete children[i];
+ }
+}
+
+template<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+size_t RectangleTree<StatisticType, MatType, SplitType>::
+ 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<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+size_t RectangleTree<StatisticType, MatType, SplitType>::
+ 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<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+inline bool BinarySpaceTree<StatisticType, MatType, SplitType>::
+ 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<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+inline size_t RectangleTree<StatisticType, MatType, SplitType>::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<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+void RectangleTree<StatisticType, MatType, SplitType>::SplitNode(
+ RetangleTree& tree)
+{
+
+}
+
+
+/**
+ * Returns a string representation of this object.
+ */
+ template<typename StatisticType,
+ typename MatType,
+ typename SplitType>
+std::string BinarySpaceTree<StatisticType, MatType, SplitType>::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
More information about the mlpack-git
mailing list