[mlpack-git] master, mlpack-1.0.x: more tests. Really silly bug fix. (481aeda)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:53:13 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 481aeda57629645430c235de14891e30f2b3cf2a
Author: andrewmw94 <andrewmw94 at gmail.com>
Date:   Mon Jul 14 14:53:20 2014 +0000

    more tests.  Really silly bug fix.


>---------------------------------------------------------------

481aeda57629645430c235de14891e30f2b3cf2a
 .../tree/rectangle_tree/rectangle_tree_impl.hpp    |  8 +++++---
 src/mlpack/tests/rectangle_tree_test.cpp           | 23 ++++++++++++++++++++--
 2 files changed, 26 insertions(+), 5 deletions(-)

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 17bada5..adf1b89 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
@@ -169,12 +169,12 @@ typename MatType>
 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 @@ void RectangleTree<SplitType, DescentType, StatisticType, MatType>::CondenseTree
         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.
diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp
index 6331a68..47d046d 100644
--- a/src/mlpack/tests/rectangle_tree_test.cpp
+++ b/src/mlpack/tests/rectangle_tree_test.cpp
@@ -173,12 +173,31 @@ BOOST_AUTO_TEST_CASE(PointDeletion) {
   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);
   
 }
 



More information about the mlpack-git mailing list