[mlpack-svn] r16643 - in mlpack/trunk/src/mlpack: core/tree/rectangle_tree methods/neighbor_search

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jun 5 13:22:25 EDT 2014


Author: andrewmw94
Date: Thu Jun  5 13:22:25 2014
New Revision: 16643

Log:
require kd-trees to have leafSize of at least 1.  Add an assert to ensure that the SingleTreeTraverser isn't called on a tree with only one node.

Modified:
   mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic.hpp
   mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp
   mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp
   mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp
   mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
   mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp

Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic.hpp	Thu Jun  5 13:22:25 2014
@@ -18,7 +18,7 @@
  * The split is done in the dimension that has the maximum width. The points are
  * divided into two parts based on the mean in this dimension.
  */
-template<typename BoundType, typename MatType = arma::mat>
+template<typename MatType = arma::mat>
 class RTreeDescentHueristic
 {
  public:
@@ -30,7 +30,7 @@
    * @param bound The bound used for the node that is being evaluated.
    * @param point The point that is being inserted.
    */
-  static double EvalNode(const BoundType& bound, const arma::vec& point);
+  static double EvalNode(const HRectBound& bound, const arma::vec& point);
 };
 
 }; // namespace tree

Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_descent_heuristic_impl.hpp	Thu Jun  5 13:22:25 2014
@@ -18,8 +18,8 @@
  * The split is done in the dimension that has the maximum width. The points are
  * divided into two parts based on the mean in this dimension.
  */
-template<typename BoundType, typename MatType = arma::mat>
-double RTreeDescentHeuristic<BoundType, MatType>::EvalNode(const BoundType& bound, const arma::vec& point)
+template<typename MatType = arma::mat>
+double RTreeDescentHeuristic<MatType>::EvalNode(const HRectBound& bound, const arma::vec& point)
 {
   return bound.contains(point) ? 0 : bound.minDistance(point);
 }

Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp	Thu Jun  5 13:22:25 2014
@@ -16,7 +16,7 @@
 namespace mlpack {
 namespace tree {
 
-template<typename Statistic Type,
+template<typename StatisticType,
     typename MatType,
     typename SplitType>
 template<typename RuleType>

Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp	Thu Jun  5 13:22:25 2014
@@ -1 +1,47 @@
- 
+/**
+  * @file rectangle_tree_traverser.hpp
+  * @author Andrew Wells
+  *
+  * A class for traversing rectangle type trees with a given set of rules
+  * which indicate the branches to prune and the order in which to recurse.
+  * This is a depth-first traverser.
+  */
+#ifndef __MLPAC_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_TRAVERSER_IMPL_HPP
+#define __MLPAC_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_TRAVERSER_IMPL_HPP
+
+#include "rectangle_tree_traverser.hpp"
+
+#include <stack>
+
+namespace mlpack {
+namespace tree {
+
+template<typename StatisticType,
+    typename MatType,
+    typename SplitType,
+    typename DescentType>
+template<typename RuleType>
+RectangleTree<StatisticType, MatType, SplitType, DescentType>::
+RectangleTreeTraverser<RuleType>::RectangleTreeTraverser(RuleType& rule) :
+    rule(rule),
+    numPrunes(0)
+{ /* Nothing to do */ }
+
+template<typename StatisticType,
+    typename MatType,
+    typename SplitType
+    typename DescentType>
+template<typename RuleType>
+void RectangleTree<StatisticType, MatType, SplitType, DescentType>::
+RectangleTreeTraverser<RuleType>::Traverse(
+    const size_t queryIndex,
+    RectangeTree<StatisticType, MatyType, SplitType, DescentType>&
+        referenceNode)
+{
+
+}
+
+}; // namespace tree
+}; // namespace mlpack
+
+#endif
\ No newline at end of file

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp	(original)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp	Thu Jun  5 13:22:25 2014
@@ -101,7 +101,7 @@
   }
 
   // Sanity check on k value: must be greater than 0, must be less than the
-  // number of reference points.
+  // number of reference points.  Since it is unsigned, we only test the upper bound.
   if (k > referenceData.n_cols)
   {
     Log::Fatal << "Invalid k: " << k << "; must be greater than 0 and less ";
@@ -110,10 +110,10 @@
   }
 
   // Sanity check on leaf size.
-  if (lsInt < 0)
+  if (lsInt < 1)
   {
     Log::Fatal << "Invalid leaf size: " << lsInt << ".  Must be greater "
-        "than or equal to 0." << endl;
+        "than 0." << endl;
   }
   size_t leafSize = lsInt;
 

Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp	Thu Jun  5 13:22:25 2014
@@ -252,9 +252,13 @@
   }
   else if (singleMode)
   {
+    // The search doesn't work if the root node is also a leaf node.
+    // if this is the case, it is suggested that you use the naive method.
+    assert(!(referenceTree->IsLeaf()));
+    
     // Create the traverser.
     typename TreeType::template SingleTreeTraverser<RuleType> traverser(rules);
-
+    
     // Now have it traverse for each point.
     for (size_t i = 0; i < querySet.n_cols; ++i)
       traverser.Traverse(i, *referenceTree);



More information about the mlpack-svn mailing list