[mlpack-svn] r14237 - 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:33:49 EST 2013


Author: rcurtin
Date: 2013-02-08 15:33:49 -0500 (Fri, 08 Feb 2013)
New Revision: 14237

Modified:
   mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic.hpp
Log:
Update MRKDStatistic.


Modified: mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic.hpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic.hpp	2013-02-08 20:27:34 UTC (rev 14236)
+++ mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic.hpp	2013-02-08 20:33:49 UTC (rev 14237)
@@ -1,14 +1,14 @@
 /**
  * @file mrkd_statistic.hpp
+ * @author James Cline
  *
- * Definition of the policy type for the statistic class.
- *
- * You should define your own statistic that looks like EmptyStatistic.
+ * Definition of the statistic for multi-resolution kd-trees.
  */
-
 #ifndef __MLPACK_CORE_TREE_MRKD_STATISTIC_HPP
 #define __MLPACK_CORE_TREE_MRKD_STATISTIC_HPP
 
+#include <mlpack/core.hpp>
+
 namespace mlpack {
 namespace tree {
 
@@ -17,111 +17,103 @@
  */
 class MRKDStatistic
 {
-  public:
-    MRKDStatistic()
-    :
-      dataset(NULL),
-      begin(0),
-      count(0)
-    { }
+ public:
+  //! Initialize an empty statistic.
+  MRKDStatistic();
 
-    ~MRKDStatistic() {}
+  /**
+   * 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(const MatType& dataset,
+                const size_t begin,
+                const size_t count);
 
-    /**
-     * 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(const MatType& dataset,
-                   const size_t begin,
-                   const size_t count)
-    :
-      dataset(&dataset),
-      begin(begin),
-      count(count),
-      parentStat(NULL)
-    {
-      centerOfMass = dataset.col(begin);
-      for(size_t i = begin+1; i < begin+count; ++i)
-        centerOfMass += dataset.col(i);
+  /**
+   * 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(const MatType& dataset,
+                const size_t begin,
+                const size_t count,
+                MRKDStatistic& leftStat,
+                MRKDStatistic& rightStat);
 
-      sumOfSquaredNorms = 0.0;
-      for(size_t i = begin; i < begin+count; ++i)
-        sumOfSquaredNorms += arma::norm(dataset.col(i), 2);
-    }
+  /**
+   * Returns a string representation of this object.
+   */
+  std::string ToString() const;
 
-    /**
-     * 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(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;
+  //! Get the index of the initial item in the dataset.
+  size_t Begin() const { return begin; }
+  //! Modify the index of the initial item in the dataset.
+  size_t& Begin() { return begin; }
 
-      /*
-      centerOfMass = ((leftStat.centerOfMass * leftStat.count) +
-                      (rightStat.centerOfMass * rightStat.count)) /
-                      (leftStat.count + rightStat.count);
-      */
-      centerOfMass = leftStat.centerOfMass + rightStat.centerOfMass;
+  //! Get the number of items in the dataset.
+  size_t Count() const { return count; }
+  //! Modify the number of items in the dataset.
+  size_t& Count() { return count; }
 
-      isWhiteListValid = false;
+  //! Get the center of mass.
+  const arma::colvec& CenterOfMass() const { return centerOfMass; }
+  //! Modify the center of mass.
+  arma::colvec& CenterOfMass() { return centerOfMass; }
 
-      leftStat.parentStat = this;
-      rightStat.parentStat = this;
-    }
+  //! Get the index of the dominating centroid.
+  size_t DominatingCentroid() const { return dominatingCentroid; }
+  //! Modify the index of the dominating centroid.
+  size_t& DominatingCentroid() { return dominatingCentroid; }
 
-    //! The data points this object contains
-    const arma::mat* dataset;
-    //! The initial item in the dataset, so we don't have to make a copy
-    size_t begin;
-    //! The number of items in the dataset
-    size_t count;
-    //! The left child 
-    const MRKDStatistic* leftStat;
-    //! The right child 
-    const MRKDStatistic* rightStat;
-    //! A link to my parent node, null if I am the root
-    const MRKDStatistic* parentStat;
+  //! Access the whitelist.
+  const std::vector<size_t>& Whitelist() const { return whitelist; }
+  //! Modify the whitelist.
+  std::vector<size_t>& Whitelist() { return whitelist; }
 
-    // Computed statistics
-    //! The center of mass for this dataset
-    arma::colvec centerOfMass;
-    //! The sum of the squared Euclidian norms for this dataset
-    double sumOfSquaredNorms;
-		
-		// There may be a better place to store this -- HRectBound?
-		//! The index of the dominating centroid of the associated hyperrectangle
-		size_t dominatingCentroid;
+ private:
+  //! The data points this object contains.
+  const arma::mat* dataset;
+  //! The initial item in the dataset, so we don't have to make a copy.
+  size_t begin;
+  //! The number of items in the dataset.
+  size_t count;
+  //! The left child.
+  const MRKDStatistic* leftStat;
+  //! The right child.
+  const MRKDStatistic* rightStat;
+  //! A link to the parent node; NULL if this is the root.
+  const MRKDStatistic* parentStat;
 
-    //! The list of centroids that cannot own this hyperrectangle
-    std::vector<size_t> whiteList;
-    //! Whether or not the whitelist is valid
-    bool isWhiteListValid;
+  // Computed statistics.
+  //! The center of mass for this dataset.
+  arma::colvec centerOfMass;
+  //! The sum of the squared Euclidian norms for this dataset.
+  double sumOfSquaredNorms;
+
+  // There may be a better place to store this -- HRectBound?
+  //! The index of the dominating centroid of the associated hyperrectangle.
+  size_t dominatingCentroid;
+
+  //! The list of centroids that cannot own this hyperrectangle.
+  std::vector<size_t> whitelist;
+  //! Whether or not the whitelist is valid.
+  bool isWhitelistValid;
 };
 
 }; // namespace tree
 }; // namespace mlpack
 
+// Include implementation.
+#include "mrkd_statistic_impl.hpp"
+
 #endif // __MLPACK_CORE_TREE_MRKD_STATISTIC_HPP


Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/core/tree/mrkd_statistic.hpp
___________________________________________________________________
Added: svn:mergeinfo
   + /mlpack/trunk/src/mlpack/core/tree/mrkd_statistic.hpp:13981-14236




More information about the mlpack-svn mailing list