[mlpack-svn] r14238 - mlpack/branches/mlpack-1.x/src/mlpack/core/tree

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Feb 8 15:35:18 EST 2013


Author: rcurtin
Date: 2013-02-08 15:35:18 -0500 (Fri, 08 Feb 2013)
New Revision: 14238

Added:
   mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic_impl.hpp
Modified:
   mlpack/branches/mlpack-1.x/src/mlpack/core/tree/CMakeLists.txt
Log:
Add implementation too.


Modified: mlpack/branches/mlpack-1.x/src/mlpack/core/tree/CMakeLists.txt
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/core/tree/CMakeLists.txt	2013-02-08 20:33:49 UTC (rev 14237)
+++ mlpack/branches/mlpack-1.x/src/mlpack/core/tree/CMakeLists.txt	2013-02-08 20:35:18 UTC (rev 14238)
@@ -23,6 +23,7 @@
   periodichrectbound_impl.hpp
   statistic.hpp
   mrkd_statistic.hpp
+  mrkd_statistic_impl.hpp
 )
 
 # add directory name to sources

Copied: mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic_impl.hpp (from rev 14237, mlpack/trunk/src/mlpack/core/tree/mrkd_statistic_impl.hpp)
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic_impl.hpp	                        (rev 0)
+++ mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic_impl.hpp	2013-02-08 20:35:18 UTC (rev 14238)
@@ -0,0 +1,84 @@
+/**
+ * @file mrkd_statistic_impl.hpp
+ * @author James Cline
+ *
+ * Definition of the statistic for multi-resolution kd-trees.
+ */
+#ifndef __MLPACK_CORE_TREE_MRKD_STATISTIC_IMPL_HPP
+#define __MLPACK_CORE_TREE_MRKD_STATISTIC_IMPL_HPP
+
+// In case it hasn't already been included.
+#include "mrkd_statistic.hpp"
+
+namespace mlpack {
+namespace tree {
+
+/**
+ * This constructor is called when a leaf is created.
+ *
+ * @param dataset Matrix that the tree is being built on.
+ * @param begin Starting index corresponding to this leaf.
+ * @param count Number of points held in this leaf.
+ */
+template<typename MatType>
+MRKDStatistic::MRKDStatistic(const MatType& dataset,
+                             const size_t begin,
+                             const size_t count) :
+    dataset(&dataset),
+    begin(begin),
+    count(count),
+    leftStat(NULL),
+    rightStat(NULL),
+    parentStat(NULL)
+{
+  centerOfMass = dataset.col(begin);
+  for (size_t i = begin+1; i < begin+count; ++i)
+    centerOfMass += dataset.col(i);
+
+  sumOfSquaredNorms = 0.0;
+  for (size_t i = begin; i < begin+count; ++i)
+    sumOfSquaredNorms += arma::norm(dataset.col(i), 2);
+}
+
+/**
+ * This constructor is called when a non-leaf node is created.
+ * This lets you build fast bottom-up statistics when building trees.
+ *
+ * @param dataset Matrix that the tree is being built on.
+ * @param begin Starting index corresponding to this leaf.
+ * @param count Number of points held in this leaf.
+ * @param leftStat MRKDStatistic object of the left child node.
+ * @param rightStat MRKDStatistic object of the right child node.
+ */
+template<typename MatType>
+MRKDStatistic::MRKDStatistic(const MatType& dataset,
+                             const size_t begin,
+                             const size_t count,
+                             MRKDStatistic& leftStat,
+                             MRKDStatistic& rightStat) :
+    dataset(&dataset),
+    begin(begin),
+    count(count),
+    leftStat(&leftStat),
+    rightStat(&rightStat),
+    parentStat(NULL)
+{
+  sumOfSquaredNorms = leftStat.sumOfSquaredNorms + rightStat.sumOfSquaredNorms;
+
+  /*
+  centerOfMass = ((leftStat.centerOfMass * leftStat.count) +
+                  (rightStat.centerOfMass * rightStat.count)) /
+                  (leftStat.count + rightStat.count);
+  */
+  centerOfMass = leftStat.centerOfMass + rightStat.centerOfMass;
+
+  isWhitelistValid = false;
+
+  leftStat.parentStat = this;
+  rightStat.parentStat = this;
+}
+
+}; // namespace tree
+}; // namespace mlpack
+
+#endif // __MLPACK_CORE_TREE_MRKD_STATISTIC_IMPL_HPP




More information about the mlpack-svn mailing list