[mlpack-svn] r16775 - 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 7 16:45:00 EDT 2014
Author: andrewmw94
Date: Mon Jul 7 16:45:00 2014
New Revision: 16775
Log:
R tree traversal test code.
Modified:
mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp
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 Mon Jul 7 16:45:00 2014
@@ -115,6 +115,9 @@
int j = 0;
GetBoundSeeds(*tree, &i, &j);
+
+ if(i == j)
+ std::cout << i << ", " << j << "; " << tree->NumChildren() << std::endl;
assert(i != j);
RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeOne = new
@@ -187,7 +190,7 @@
// Here we want to find the pair of points that it is worst to place in the same
// node. Because we are just using points, we will simply choose the two that would
// create the most voluminous hyperrectangle.
- double worstPairScore = 0.0;
+ double worstPairScore = -1.0;
int worstI = 0;
int worstJ = 0;
for(int i = 0; i < tree.Count(); i++) {
@@ -221,7 +224,7 @@
int* iRet,
int* jRet)
{
- double worstPairScore = 0.0;
+ double worstPairScore = -1.0;
int worstI = 0;
int worstJ = 0;
for(int i = 0; i < tree.NumChildren(); i++) {
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 7 16:45:00 2014
@@ -54,7 +54,6 @@
NeighborSearchStat<NearestNeighborSort>,
arma::mat> tree(dataset, 20, 6, 5, 2, 0);
BOOST_REQUIRE_EQUAL(tree.NumDescendants(), 1000);
- std::cout << tree.ToString() << std::endl;
}
std::vector<arma::vec*> getAllPointsInTree(const RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
@@ -139,5 +138,41 @@
assert(checkContainment(tree) == true);
}
+BOOST_AUTO_TEST_CASE(SingleTreeTraverserTest)
+{
+ arma::mat dataset;
+ dataset.randu(8, 1000); // 1000 points in 8 dimensions.
+ arma::Mat<size_t> neighbors1;
+ arma::mat distances1;
+ arma::Mat<size_t> neighbors2;
+ arma::mat distances2;
+
+ RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
+ tree::RTreeDescentHeuristic,
+ NeighborSearchStat<NearestNeighborSort>,
+ arma::mat> RTree(dataset, 20, 6, 5, 2, 0);
+
+ // nearest neighbor search with the R tree.
+ mlpack::neighbor::NeighborSearch<NearestNeighborSort, metric::LMetric<2, true>,
+ RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
+ tree::RTreeDescentHeuristic,
+ NeighborSearchStat<NearestNeighborSort>,
+ arma::mat> > allknn1(&RTree,
+ dataset, true);
+
+ allknn1.Search(5, neighbors1, distances1);
+
+ // nearest neighbor search the naive way.
+ mlpack::neighbor::AllkNN allknn2(dataset,
+ true, true);
+
+ allknn2.Search(5, neighbors2, distances2);
+
+ for(size_t i = 0; i < neighbors1.size(); i++) {
+ assert(neighbors1[i] == neighbors2[i]);
+ assert(distances1[i] == distances2[i]);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list