[mlpack-svn] r17029 - mlpack/trunk/src/mlpack/core/tree/rectangle_tree

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Aug 14 13:34:15 EDT 2014


Author: rcurtin
Date: Thu Aug 14 13:34:14 2014
New Revision: 17029

Log:
First pass: make things 80 characters, minor style fixes.


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

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 Aug 14 13:34:14 2014
@@ -2,8 +2,8 @@
  * @file r_tree_descent_heuristic.hpp
  * @author Andrew Wells
  *
- * Definition of RTreeDescentHeuristic, a class that chooses the best child of a node in
- * an R tree when inserting a new point.
+ * Definition of RTreeDescentHeuristic, a class that chooses the best child of a
+ * node in an R tree when inserting a new point.
  */
 #ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_R_TREE_DESCENT_HEURISTIC_HPP
 #define __MLPACK_CORE_TREE_RECTANGLE_TREE_R_TREE_DESCENT_HEURISTIC_HPP
@@ -11,28 +11,42 @@
 #include <mlpack/core.hpp>
 
 namespace mlpack {
-namespace tree /** Trees and tree-building procedures. */ {
+namespace tree {
 
 /**
- * When descending a Rectangle tree to insert a point, we need to have a way to choose
- * a child node when the point isn't enclosed by any of them.  This heuristic is used to do so.
+ * When descending a RectangleTree to insert a point, we need to have a way to
+ * choose a child node when the point isn't enclosed by any of them.  This
+ * heuristic is used to do so.
  */
 class RTreeDescentHeuristic
 {
  public:
   /**
-   * Evaluate the node using a hueristic.  The heuristic guarantees two things:
-   * 1.  If point is contained in (or on) bound, the value returned is zero.
-   * 2.  If the point is not contained in (or on) bound, the value returned is greater than zero. 
+   * Evaluate the node using a heuristic.  The heuristic guarantees two things:
    *
-   * @param bound The bound used for the node that is being evaluated.
+   * 1. If point is contained in (or on) the bound, the value returned is zero.
+   * 2. If the point is not contained in (or on) the bound, the value returned
+   *    is greater than zero.
+   *
+   * @param node The node that is being evaluated.
    * @param point The point that is being inserted.
    */
   template<typename TreeType>
   static size_t ChooseDescentNode(const TreeType* node, const arma::vec& point);
-  
+
+  /**
+   * Evaluate the node using a heuristic.  The heuristic guarantees two things:
+   *
+   * 1. If point is contained in (or on) the bound, the value returned is zero.
+   * 2. If the point is not contained in (or on) the bound, the value returned
+   *    is greater than zero.
+   *
+   * @param node The node that is being evaluated.
+   * @param insertedNode The node that is being inserted.
+   */
   template<typename TreeType>
-  static size_t ChooseDescentNode(const TreeType* node, const TreeType* insertedNode);
+  static size_t ChooseDescentNode(const TreeType* node,
+                                  const TreeType* insertedNode);
 };
 
 }; // 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 Aug 14 13:34:14 2014
@@ -2,8 +2,8 @@
  * @file r_tree_descent_heuristic_impl.hpp
  * @author Andrew Wells
  *
- * Implementation of RTreeDescentHeuristic, a class that chooses the best child of a node in
- * an R tree when inserting a new point.
+ * Implementation of RTreeDescentHeuristic, a class that chooses the best child
+ * of a node in an R tree when inserting a new point.
  */
 #ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_R_TREE_DESCENT_HEURISTIC_IMPL_HPP
 #define __MLPACK_CORE_TREE_RECTANGLE_TREE_R_TREE_DESCENT_HEURISTIC_IMPL_HPP
@@ -14,7 +14,8 @@
 namespace tree {
 
 template<typename TreeType>
-inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node, const arma::vec& point)
+inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node,
+                                                       const arma::vec& point)
 {
   std::vector<double> scores(node->NumChildren());
   std::vector<int> vols(node->NumChildren());
@@ -22,77 +23,120 @@
   int bestIndex = 0;
   bool tied = false;
 
-  for (size_t i = 0; i < node->NumChildren(); i++) {
+  for (size_t i = 0; i < node->NumChildren(); i++)
+  {
     double v1 = 1.0;
     double v2 = 1.0;
-    for (size_t j = 0; j < node->Children()[i]->Bound().Dim(); j++) {
+    for (size_t j = 0; j < node->Children()[i]->Bound().Dim(); j++)
+    {
       v1 *= node->Children()[i]->Bound()[j].Width();
-      v2 *= node->Children()[i]->Bound()[j].Contains(point[j]) ? node->Children()[i]->Bound()[j].Width() : (node->Children()[i]->Bound()[j].Hi() < point[j] ? (point[j] - node->Children()[i]->Bound()[j].Lo()) :
+      v2 *= node->Children()[i]->Bound()[j].Contains(point[j]) ?
+          node->Children()[i]->Bound()[j].Width() :
+          (node->Children()[i]->Bound()[j].Hi() < point[j] ?
+              (point[j] - node->Children()[i]->Bound()[j].Lo()) :
               (node->Children()[i]->Bound()[j].Hi() - point[j]));
     }
+
     assert(v2 - v1 >= 0);
+
     vols[i] = v1;
-    scores[i] = v2-v1;
-    if (v2 - v1 < minScore) {
+    scores[i] = v2 - v1;
+
+    if (v2 - v1 < minScore)
+    {
       minScore = v2 - v1;
       bestIndex = i;
-    } else if(v2 - v1 == minScore)
+    }
+    else if (v2 - v1 == minScore)
+    {
       tied = true;
+    }
   }
-  if(tied) { // We break ties by choosing the smallest bound.
+
+  if (tied)
+  {
+    // We break ties by choosing the smallest bound.
     double minVol = DBL_MAX;
     bestIndex = 0;
-    for(int i = 0; i < scores.size(); i++) {
-      if(scores[i] == minScore) {
-        if(vols[i] < minVol) {
+    for (int i = 0; i < scores.size(); i++)
+    {
+      if (scores[i] == minScore)
+      {
+        if (vols[i] < minVol)
+        {
           minVol = vols[i];
           bestIndex = i;
         }
       }
     }
-  }  
+  }
+
   return bestIndex;
 }
 
 template<typename TreeType>
-inline size_t RTreeDescentHeuristic::ChooseDescentNode(const TreeType* node, const TreeType* insertedNode)
+inline size_t RTreeDescentHeuristic::ChooseDescentNode(
+    const TreeType* node,
+    const TreeType* insertedNode)
 {
   std::vector<double> scores(node->NumChildren());
   std::vector<int> vols(node->NumChildren());
+
   double minScore = DBL_MAX;
   int bestIndex = 0;
   bool tied = false;
-  
-  for (size_t i = 0; i < node->NumChildren(); i++) {
+
+  for (size_t i = 0; i < node->NumChildren(); i++)
+  {
     double v1 = 1.0;
     double v2 = 1.0;
-    for (size_t j = 0; j < node->Children()[i]->Bound().Dim(); j++) {
+    for (size_t j = 0; j < node->Children()[i]->Bound().Dim(); j++)
+    {
       v1 *= node->Children()[i]->Bound()[j].Width();
-      v2 *= node->Children()[i]->Bound()[j].Contains(insertedNode->Bound()[j]) ? node->Children()[i]->Bound()[j].Width() :
-              (insertedNode->Bound()[j].Contains(node->Children()[i]->Bound()[j]) ? insertedNode->Bound()[j].Width() : (insertedNode->Bound()[j].Lo() < node->Children()[i]->Bound()[j].Lo() ? (node->Children()[i]->Bound()[j].Hi() - insertedNode->Bound()[j].Lo()) : (insertedNode->Bound()[j].Hi() - node->Children()[i]->Bound()[j].Lo())));
+      v2 *= node->Children()[i]->Bound()[j].Contains(insertedNode->Bound()[j]) ?
+          node->Children()[i]->Bound()[j].Width() :
+          (insertedNode->Bound()[j].Contains(node->Children()[i]->Bound()[j]) ?
+          insertedNode->Bound()[j].Width() :
+          (insertedNode->Bound()[j].Lo() < node->Children()[i]->Bound()[j].Lo()
+          ? (node->Children()[i]->Bound()[j].Hi() -
+          insertedNode->Bound()[j].Lo()) : (insertedNode->Bound()[j].Hi() -
+          node->Children()[i]->Bound()[j].Lo())));
     }
+
     assert(v2 - v1 >= 0);
+
     vols[i] = v1;
-    scores[i] = v2-v1;
-    if (v2 - v1 < minScore) {
+    scores[i] = v2 - v1;
+
+    if (v2 - v1 < minScore)
+    {
       minScore = v2 - v1;
       bestIndex = i;
-    } else if(v2 - v1 == minScore)
+    }
+    else if (v2 - v1 == minScore)
+    {
       tied = true;
+    }
   }
-  if(tied) { // We break ties by choosing the smallest bound.
+
+  if (tied)
+  {
+    // We break ties by choosing the smallest bound.
     double minVol = DBL_MAX;
     bestIndex = 0;
-    for(int i = 0; i < scores.size(); i++) {
-      if(scores[i] == minScore) {
-        if(vols[i] < minVol) {
+    for (int i = 0; i < scores.size(); i++)
+    {
+      if (scores[i] == minScore)
+      {
+        if(vols[i] < minVol)
+        {
           minVol = vols[i];
           bestIndex = i;
         }
       }
     }
   }
-  
+
   return bestIndex;
 }
 



More information about the mlpack-svn mailing list