[mlpack-svn] r14416 - 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
Thu Feb 28 14:14:56 EST 2013


Author: rcurtin
Date: 2013-02-28 14:14:56 -0500 (Thu, 28 Feb 2013)
New Revision: 14416

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:
Remove empty constructor; store dataset; allow return of metric with Metric().
We don't seem to pay an extra price for this because sizeof(BinarySpaceTree) >
64 bytes but < 128 bytes (two cache lines).  Also, reducing the size to one
cache line doesn't seem to provide much benefit (at least on amd64).


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-02-28 19:12:39 UTC (rev 14415)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp	2013-02-28 19:14:56 UTC (rev 14416)
@@ -52,14 +52,16 @@
   //! The number of points of the dataset contained in this node (and its
   //! children).
   size_t count;
+  //! The leaf size.
+  size_t leafSize;
   //! The bound object for this node.
   BoundType bound;
   //! Any extra data contained in the node.
   StatisticType stat;
-  //! The leaf size.
-  size_t leafSize;
   //! The dimension this node split on if it is a parent.
   size_t splitDimension;
+  //! The dataset.
+  MatType& dataset;
 
  public:
   //! So other classes can use TreeType::Mat.
@@ -195,11 +197,6 @@
   BinarySpaceTree(const BinarySpaceTree& other);
 
   /**
-   * Create an empty tree node.
-   */
-  BinarySpaceTree();
-
-  /**
    * 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.
@@ -274,6 +271,14 @@
   //! Modify the split dimension for this node.
   size_t& SplitDimension() { return splitDimension; }
 
+  //! Get the dataset which the tree is built on.
+  const arma::mat& Dataset() const { return dataset; }
+  //! Modify the dataset which the tree is built on.  Be careful!
+  arma::mat& Dataset() { return dataset; }
+
+  //! Get the metric which the tree uses.
+  typename BoundType::MetricType Metric() const { return bound.Metric(); }
+
   //! Return the number of children in this node.
   size_t NumChildren() const;
 

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-02-28 19:12:39 UTC (rev 14415)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp	2013-02-28 19:14:56 UTC (rev 14416)
@@ -27,9 +27,9 @@
     parent(NULL),
     begin(0), /* This root node starts at index 0, */
     count(data.n_cols), /* and spans all of the dataset. */
+    leafSize(leafSize),
     bound(data.n_rows),
-    stat(),
-    leafSize(leafSize)
+    dataset(data)
 {
   // Do the actual splitting of this node.
   SplitNode(data);
@@ -48,9 +48,9 @@
     parent(NULL),
     begin(0),
     count(data.n_cols),
+    leafSize(leafSize),
     bound(data.n_rows),
-    stat(),
-    leafSize(leafSize)
+    dataset(data)
 {
   // Initialize oldFromNew correctly.
   oldFromNew.resize(data.n_cols);
@@ -75,9 +75,9 @@
     parent(NULL),
     begin(0),
     count(data.n_cols),
+    leafSize(leafSize),
     bound(data.n_rows),
-    stat(),
-    leafSize(leafSize)
+    dataset(data)
 {
   // Initialize the oldFromNew vector correctly.
   oldFromNew.resize(data.n_cols);
@@ -108,9 +108,9 @@
     parent(parent),
     begin(begin),
     count(count),
+    leafSize(leafSize),
     bound(data.n_rows),
-    stat(),
-    leafSize(leafSize)
+    dataset(data)
 {
   // Perform the actual splitting.
   SplitNode(data);
@@ -132,9 +132,9 @@
     parent(parent),
     begin(begin),
     count(count),
+    leafSize(leafSize),
     bound(data.n_rows),
-    stat(),
-    leafSize(leafSize)
+    dataset(data)
 {
   // Hopefully the vector is initialized correctly!  We can't check that
   // entirely but we can do a minor sanity check.
@@ -161,9 +161,9 @@
     parent(parent),
     begin(begin),
     count(count),
+    leafSize(leafSize),
     bound(data.n_rows),
-    stat(),
-    leafSize(leafSize)
+    dataset(data)
 {
   // Hopefully the vector is initialized correctly!  We can't check that
   // entirely but we can do a minor sanity check.
@@ -181,6 +181,7 @@
     newFromOld[oldFromNew[i]] = i;
 }
 
+/*
 template<typename BoundType, typename StatisticType, typename MatType>
 BinarySpaceTree<BoundType, StatisticType, MatType>::BinarySpaceTree() :
     left(NULL),
@@ -193,7 +194,7 @@
     leafSize(20) // Default leaf size is 20.
 {
   // Nothing to do.
-}
+}*/
 
 /**
  * Create a binary space tree by copying the other tree.  Be careful!  This can
@@ -204,13 +205,14 @@
     const BinarySpaceTree& other) :
     left(NULL),
     right(NULL),
-    parent(other.Parent()),
-    begin(other.Begin()),
-    count(other.Count()),
-    bound(other.Bound()),
-    stat(other.Stat()),
-    leafSize(other.LeafSize()),
-    splitDimension(other.SplitDimension())
+    parent(other.parent),
+    begin(other.begin),
+    count(other.count),
+    leafSize(other.leafSize),
+    bound(other.bound),
+    stat(other.stat),
+    splitDimension(other.splitDimension),
+    dataset(other.dataset)
 {
   // Create left and right children (if any).
   if (other.Left())




More information about the mlpack-svn mailing list