[mlpack-svn] r16821 - in mlpack/trunk/src/mlpack: core/tree/rectangle_tree tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jul 14 10:53:21 EDT 2014


Author: andrewmw94
Date: Mon Jul 14 10:53:20 2014
New Revision: 16821

Log:
more tests.  Really silly bug fix.

Modified:
   mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
   mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp

Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp	Mon Jul 14 10:53:20 2014
@@ -169,12 +169,12 @@
 bool RectangleTree<SplitType, DescentType, StatisticType, MatType>::
 DeletePoint(const size_t point)
 {
-
   if (numChildren == 0) {
     for (size_t i = 0; i < count; i++) {
       if (points[i] == point) {
         localDataset->col(i) = localDataset->col(--count); // decrement count
         points[i] = points[count];
+        std::cout << count << std::endl;
         CondenseTree(dataset.col(point)); // This function will ensure that minFill is satisfied.
         return true;
       }
@@ -388,11 +388,13 @@
         parent->ShrinkBoundForBound(bound); // We want to do this before reinserting points.
 
         // Reinsert the points at the root node.
-        RectangleTree<SplitType, DescentType, StatisticType, MatType>* root = this;
+        RectangleTree<SplitType, DescentType, StatisticType, MatType>* root = parent;
         while (root->Parent() != NULL)
           root = root->Parent();
-        for (size_t j = 0; j < numChildren; j++)
+        
+        for (size_t j = 0; j < count; j++) {
           root->InsertPoint(points[j]);
+        }
 
         parent->CondenseTree(point); // This will check the MinFill of the parent.
         //Now it should be safe to delete this node.

Modified: mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp	Mon Jul 14 10:53:20 2014
@@ -173,13 +173,32 @@
   arma::mat dataset;
   dataset.randu(8, 1000); // 1000 points in 8 dimensions.
 
+  const int numIter = 50;
+  
   RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
                       tree::RTreeDescentHeuristic,
                       NeighborSearchStat<NearestNeighborSort>,
                       arma::mat> tree(dataset, 20, 6, 5, 2, 0);
-  tree.DeletePoint(999);
-  assert(tree.NumDescendants() == 999);
+  for(int i = 0; i < numIter; i++) {
+      tree.DeletePoint(i);
+  }
+  std::cout << tree.NumDescendants() << std::endl;
+  assert(tree.NumDescendants() == 1000-numIter);
+          
+    mlpack::neighbor::NeighborSearch<NearestNeighborSort, metric::LMetric<2, true>,
+        RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
+	  	      tree::RTreeDescentHeuristic,
+  		      NeighborSearchStat<NearestNeighborSort>,
+  		      arma::mat> > allknn1(&tree,
+        dataset, true);
+  
+  arma::Mat<size_t> neighbors;
+  arma::mat distances;
+  allknn1.Search(5, neighbors, distances);
 
+  for(int i = 0; i < numIter; i++)
+    assert(distances.at(0, i) > 0);
+  
 }
 
 BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest)



More information about the mlpack-svn mailing list