[mlpack] 37/324: added code for accessing immediate child nodes (need to think of a way to rename this to be less confusing). Some more quasi-code to split nodes and insert points.

Barak A. Pearlmutter barak+git at cs.nuim.ie
Sun Aug 17 08:21:53 UTC 2014


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit cf304d03e3ffe94496c90deb45114dc77e0a5114
Author: andrewmw94 <andrewmw94 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Fri May 30 22:42:36 2014 +0000

    added code for accessing immediate child nodes (need to think of a way to rename this to be less confusing).  Some more quasi-code to split nodes and insert points.
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16584 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 .../core/tree/rectangle_tree/r_tree_split_impl.hpp | 43 ++++++++++++++++------
 .../core/tree/rectangle_tree/rectangle_tree.hpp    | 12 ++++++
 2 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
index babd973..252080f 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
@@ -13,7 +13,7 @@ namespace mlpack {
 namespace tree {
 
 template<typename MatType>
-bool RTreeSplit<MatType>::SplitLeafNode(const RectangleTree& tree)
+void RTreeSplit<MatType>::SplitLeafNode(const RectangleTree& tree)
 {
   // Use the quadratic split method from: Guttman "R-Trees: A Dynamic Index Structure for
   // Spatial Searching"  It is simplified since we don't handle rectangles, only points.
@@ -28,7 +28,28 @@ bool RTreeSplit<MatType>::SplitLeafNode(const RectangleTree& tree)
   treeTwo.insertPoint(tree.dataset[j]);
 
   AssignPointDestNode(tree, treeOne, treeTwo, i, j);
-  return true;
+  
+  RectangleTree* par = tree.parent();
+  int index = 0;
+  for(int i = 0; i < par.numOfChildren(); i++) {
+    if(par.getChildren()[i] == this) {
+      index = i;
+      break;
+    }
+  }
+  par.getChildren()[i] = treeOne;
+  par.getChildren()[par.end++] = treeTwo;
+
+  delete tree;
+
+  // we only add one at a time, so should only need to test for equality
+  // just in case, we use an assert.
+  boost::assert(numChildren <= maxNumChildren);
+
+  if(par.numOfChildren() == par.maxNumChildren) {
+    SplitNonLeafNode(par);
+  }
+  return;
 }
 
 bool RTreeSplit<MatType>::SplitNonLeafNode(const RectangleTree& tree)
@@ -103,6 +124,7 @@ void RTreeSplit<MatType>::GetBoundSeeds(const RectangleTree& tree, int* iRet, in
   return;
 }
 
+
 void RTreeSplit<MatType>::AssignPointDestNode(
     const RectangleTree& oldTree,
     RectangleTree& treeOne,
@@ -110,13 +132,16 @@ void RTreeSplit<MatType>::AssignPointDestNode(
     const int intI,
     const int intJ)
 {
+  Log::assert(end > 1); // If this isn't true, the tree is really weird.
   int end = oldTree.count;
-  oldTree.data
-
-
-
+  oldTree.dataset.col(intI) = oldTree.dataset.col(--end); // decrement end
+  oldTree.dataset.col(intJ) = oldTree.dataset.col(--end); // decrement end
     
   int index = 0;
+
+  // In each iteration, we go through all points and find the one that causes the least
+  // increase of volume when added to one of the rectangles.  We then add it to that
+  // rectangle.  
   while() {
     int bestIndex = 0;
     double bestScore = 0;
@@ -163,11 +188,7 @@ void RTreeSplit<MatType>::AssignPointDestNode(
     else
       treeTwo.insertPoint(oldTree.dataset(bestIndex);
 
-    // I have the imaginary removePoint here.  I need to find out more about how fast doing 
-    // various things with arma::mat is before I decide how to "remove" the points from the
-    // dataset.  Make sure this is not accidentally made the function for deleting points.
-    oldTree.removePoint(index);
-    end--;
+    oldTree.dataset.col(bestIndex) = oldTree.dataset.col(--end); // decrement end.
   }
 
 
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
index 5f89aac..bdde1d4 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
@@ -159,9 +159,21 @@ class RectangleTree
   //! Get the centroid of the node and store it in the given vector.
   void Centroid(arma::vec& centroid) { bound.Centroid(centroid); }
 
+  // TODO.  Think of a better name that makes the difference here obvious.
+
   //! Return the number of children in this node.
   size_t NumChildren() const;
 
+  //! Return the number of child nodes.  (One level beneath this one only.)
+  size_t getNumOfChildren() const { return numOfChildren; }
+  //! Modify the number of child nodes.  Be careful.
+  size_t& getNumOfChildren() { return numOfChildren; }
+
+  //! Get the children of this node.
+  const std::vector<RectangleTree*>& getChildren() const { return children; }
+  //! Modify the children of this node.
+  std::vector<RectangleTree*>& getChildren() { return children; }
+
   /**
    * Return the furthest distance to a point held in this node.  If this is not
    * a leaf node, then the distance is 0 because the node holds no points.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list