[mlpack-git] master: Refactor to use Center() instead of Centroid(). (54c32b8)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Jul 16 12:16:47 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/b4659b668021db631b3c8a48e3d735b513706fdc...015d79104286231ef70ea0ba1d99a6c397025b3e

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

commit 54c32b8aa4f7595b5e807b5ef732ebfa5489e443
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Jul 16 16:15:38 2015 +0000

    Refactor to use Center() instead of Centroid().


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

54c32b8aa4f7595b5e807b5ef732ebfa5489e443
 src/mlpack/core/tree/ballbound.hpp                 |  6 ++--
 .../tree/binary_space_tree/binary_space_tree.hpp   |  8 ++---
 .../binary_space_tree/binary_space_tree_impl.hpp   | 38 ++++++++++------------
 src/mlpack/core/tree/cover_tree/cover_tree.hpp     |  6 ++--
 src/mlpack/core/tree/hrectbound.hpp                |  6 ++--
 src/mlpack/core/tree/hrectbound_impl.hpp           |  8 ++---
 .../tree/rectangle_tree/r_star_tree_split_impl.hpp | 10 +++---
 .../core/tree/rectangle_tree/rectangle_tree.hpp    |  2 +-
 .../core/tree/rectangle_tree/x_tree_split_impl.hpp |  6 ++--
 9 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/src/mlpack/core/tree/ballbound.hpp b/src/mlpack/core/tree/ballbound.hpp
index 4800832..c2c6457 100644
--- a/src/mlpack/core/tree/ballbound.hpp
+++ b/src/mlpack/core/tree/ballbound.hpp
@@ -104,11 +104,11 @@ class BallBound
   bool Contains(const VecType& point) const;
 
   /**
-   * Place the centroid of BallBound into the given vector.
+   * Place the center of BallBound into the given vector.
    *
-   * @param centroid Vector which the centroid will be written to.
+   * @param center Vector which the centroid will be written to.
    */
-  void Centroid(VecType& centroid) const { centroid = center; }
+  void Center(VecType& center) const { center = this->center; }
 
   /**
    * Calculates minimum bound-to-point squared distance.
diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
index ce8edf3..1f350ad 100644
--- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
@@ -262,12 +262,9 @@ class BinarySpaceTree
   //! Modify the dataset which the tree is built on.  Be careful!
   MatType& Dataset() { return *dataset; }
 
-  //! Get the metric which the tree uses.
+  //! Get the metric that the tree uses.
   typename BoundType::MetricType Metric() const { return bound.Metric(); }
 
-  //! Get the centroid of the node and store it in the given vector.
-  void Centroid(arma::vec& centroid) { bound.Centroid(centroid); }
-
   //! Return the number of children in this node.
   size_t NumChildren() const;
 
@@ -394,6 +391,9 @@ class BinarySpaceTree
   //! Returns false: this tree type does not have self children.
   static bool HasSelfChildren() { return false; }
 
+  //! Store the center of the bounding region in the given vector.
+  void Center(arma::vec& center) { bound.Center(center); }
+
  private:
   /**
    * Splits the current node, assigning its left and right children recursively.
diff --git a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
index 2e37440..36c91a8 100644
--- a/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
+++ b/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
@@ -327,7 +327,7 @@ inline size_t BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::
 }
 
 /**
- * Return a bound on the furthest point in the node from the centroid.  This
+ * Return a bound on the furthest point in the node from the center.  This
  * returns 0 unless the node is a leaf.
  */
 template<typename BoundType,
@@ -340,13 +340,13 @@ inline double BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::
   if (!IsLeaf())
     return 0.0;
 
-  // Otherwise return the distance from the centroid to a corner of the bound.
+  // Otherwise return the distance from the center to a corner of the bound.
   return 0.5 * bound.Diameter();
 }
 
 /**
  * Return the furthest possible descendant distance.  This returns the maximum
- * distance from the centroid to the edge of the bound and not the empirical
+ * distance from the center to the edge of the bound and not the empirical
  * quantity which is the actual furthest descendant distance.  So the actual
  * furthest descendant distance may be less than what this method returns (but
  * it will never be greater than this).
@@ -485,15 +485,14 @@ void BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::SplitNode(
       splitter, maxLeafSize);
 
   // Calculate parent distances for those two nodes.
-  arma::vec centroid, leftCentroid, rightCentroid;
-  Centroid(centroid);
-  left->Centroid(leftCentroid);
-  right->Centroid(rightCentroid);
+  arma::vec center, leftCenter, rightCenter;
+  Center(center);
+  left->Center(leftCenter);
+  right->Center(rightCenter);
 
-  const double leftParentDistance = bound.Metric().Evaluate(centroid,
-      leftCentroid);
-  const double rightParentDistance = bound.Metric().Evaluate(centroid,
-      rightCentroid);
+  const double leftParentDistance = bound.Metric().Evaluate(center, leftCenter);
+  const double rightParentDistance = bound.Metric().Evaluate(center,
+      rightCenter);
 
   left->ParentDistance() = leftParentDistance;
   right->ParentDistance() = rightParentDistance;
@@ -542,15 +541,14 @@ void BinarySpaceTree<BoundType, StatisticType, MatType, SplitType>::SplitNode(
       oldFromNew, splitter, maxLeafSize);
 
   // Calculate parent distances for those two nodes.
-  arma::vec centroid, leftCentroid, rightCentroid;
-  Centroid(centroid);
-  left->Centroid(leftCentroid);
-  right->Centroid(rightCentroid);
-
-  const double leftParentDistance = bound.Metric().Evaluate(centroid,
-      leftCentroid);
-  const double rightParentDistance = bound.Metric().Evaluate(centroid,
-      rightCentroid);
+  arma::vec center, leftCenter, rightCenter;
+  Center(center);
+  left->Center(leftCenter);
+  right->Center(rightCenter);
+
+  const double leftParentDistance = bound.Metric().Evaluate(center, leftCenter);
+  const double rightParentDistance = bound.Metric().Evaluate(center,
+      rightCenter);
 
   left->ParentDistance() = leftParentDistance;
   right->ParentDistance() = rightParentDistance;
diff --git a/src/mlpack/core/tree/cover_tree/cover_tree.hpp b/src/mlpack/core/tree/cover_tree/cover_tree.hpp
index 647c37f..6dafc6a 100644
--- a/src/mlpack/core/tree/cover_tree/cover_tree.hpp
+++ b/src/mlpack/core/tree/cover_tree/cover_tree.hpp
@@ -332,10 +332,10 @@ class CoverTree
   //! same as furthestDescendantDistance).
   double MinimumBoundDistance() const { return furthestDescendantDistance; }
 
-  //! Get the centroid of the node and store it in the given vector.
-  void Centroid(arma::vec& centroid) const
+  //! Get the center of the node and store it in the given vector.
+  void Center(arma::vec& center) const
   {
-    centroid = arma::vec(dataset.col(point));
+    center = arma::vec(dataset.col(point));
   }
 
   //! Get the instantiated metric.
diff --git a/src/mlpack/core/tree/hrectbound.hpp b/src/mlpack/core/tree/hrectbound.hpp
index d6646d0..ea525f3 100644
--- a/src/mlpack/core/tree/hrectbound.hpp
+++ b/src/mlpack/core/tree/hrectbound.hpp
@@ -73,11 +73,11 @@ class HRectBound
   double& MinWidth() { return minWidth; }
 
   /**
-   * Calculates the centroid of the range, placing it into the given vector.
+   * Calculates the center of the range, placing it into the given vector.
    *
-   * @param centroid Vector which the centroid will be written to.
+   * @param center Vector which the center will be written to.
    */
-  void Centroid(arma::vec& centroid) const;
+  void Center(arma::vec& center) const;
 
   /**
    * Calculate the volume of the hyperrectangle.
diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp
index 116323b..43a7982 100644
--- a/src/mlpack/core/tree/hrectbound_impl.hpp
+++ b/src/mlpack/core/tree/hrectbound_impl.hpp
@@ -105,14 +105,14 @@ inline void HRectBound<Power, TakeRoot>::Clear()
  * @param centroid Vector which the centroid will be written to.
  */
 template<int Power, bool TakeRoot>
-inline void HRectBound<Power, TakeRoot>::Centroid(arma::vec& centroid) const
+inline void HRectBound<Power, TakeRoot>::Center(arma::vec& center) const
 {
   // Set size correctly if necessary.
-  if (!(centroid.n_elem == dim))
-    centroid.set_size(dim);
+  if (!(center.n_elem == dim))
+    center.set_size(dim);
 
   for (size_t i = 0; i < dim; i++)
-    centroid(i) = bounds[i].Mid();
+    center(i) = bounds[i].Mid();
 }
 
 /**
diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp
index 8aef253..9587407 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp
@@ -64,11 +64,11 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
     }
 
     std::vector<SortStruct> sorted(tree->Count());
-    arma::vec centroid;
-    tree->Bound().Centroid(centroid); // Modifies centroid.
+    arma::vec center;
+    tree->Bound().Center(center); // Modifies centroid.
     for (size_t i = 0; i < sorted.size(); i++)
     {
-      sorted[i].d = tree->Bound().Metric().Evaluate(centroid,
+      sorted[i].d = tree->Bound().Metric().Evaluate(center,
           tree->LocalDataset().col(i));
       sorted[i].n = i;
     }
@@ -310,10 +310,10 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
 
     std::vector<sortStruct> sorted(tree->NumChildren());
     arma::vec c1;
-    tree->Bound().Centroid(c1); // Modifies c1.
+    tree->Bound().Center(c1); // Modifies c1.
     for(size_t i = 0; i < sorted.size(); i++) {
       arma::vec c2;
-      tree->Children()[i]->Bound().Centroid(c2); // Modifies c2.
+      tree->Children()[i]->Bound().Center(c2); // Modifies c2.
       sorted[i].d = tree->Bound().Metric().Evaluate(c1,c2);
       sorted[i].n = i;
     }
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
index a62988e..6f703a5 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
@@ -321,7 +321,7 @@ class RectangleTree
   typename HRectBound<>::MetricType Metric() const { return bound.Metric(); }
 
   //! Get the centroid of the node and store it in the given vector.
-  void Centroid(arma::vec& centroid) { bound.Centroid(centroid); }
+  void Center(arma::vec& center) { bound.Center(center); }
 
   //! Return the number of child nodes.  (One level beneath this one only.)
   size_t NumChildren() const { return numChildren; }
diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp
index 7758a26..43002d7 100644
--- a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp
@@ -59,10 +59,10 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
    }
 
    std::vector<sortStruct> sorted(tree->Count());
-   arma::vec centroid;
-   tree->Bound().Centroid(centroid); // Modifies centroid.
+   arma::vec center;
+   tree->Bound().Center(center); // Modifies centroid.
    for(size_t i = 0; i < sorted.size(); i++) {
-     sorted[i].d = tree->Bound().Metric().Evaluate(centroid, tree->LocalDataset().col(i));
+     sorted[i].d = tree->Bound().Metric().Evaluate(center, tree->LocalDataset().col(i));
      sorted[i].n = i;
    }
 



More information about the mlpack-git mailing list