[mlpack-svn] r16584 - mlpack/trunk/src/mlpack/core/tree/rectangle_tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri May 30 18:42:37 EDT 2014
Author: andrewmw94
Date: Fri May 30 18:42:36 2014
New Revision: 16584
Log:
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.
Modified:
mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp Fri May 30 18:42:36 2014
@@ -13,7 +13,7 @@
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 @@
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 @@
return;
}
+
void RTreeSplit<MatType>::AssignPointDestNode(
const RectangleTree& oldTree,
RectangleTree& treeOne,
@@ -110,13 +132,16 @@
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 @@
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.
}
Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp Fri May 30 18:42:36 2014
@@ -159,9 +159,21 @@
//! 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.
More information about the mlpack-svn
mailing list