[mlpack-svn] r13238 - mlpack/trunk/src/mlpack/methods/det
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jul 16 12:06:47 EDT 2012
Author: rcurtin
Date: 2012-07-16 12:06:47 -0400 (Mon, 16 Jul 2012)
New Revision: 13238
Modified:
mlpack/trunk/src/mlpack/methods/det/dtree.hpp
mlpack/trunk/src/mlpack/methods/det/dtree_impl.hpp
Log:
Clean up constructors; use initialization lists more exclusively. Also clean up
WithinRange() (inline it among other things; it is short).
Modified: mlpack/trunk/src/mlpack/methods/det/dtree.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/det/dtree.hpp 2012-07-16 15:43:14 UTC (rev 13237)
+++ mlpack/trunk/src/mlpack/methods/det/dtree.hpp 2012-07-16 16:06:47 UTC (rev 13238)
@@ -71,6 +71,11 @@
// maps the points back to their original indices.
size_t start_, end_;
+ // since we are using uniform density, we need
+ // the max and min of every dimension for every node
+ arma::vec maxVals;
+ arma::vec minVals;
+
// The split dim for this node
size_t split_dim_;
@@ -102,11 +107,6 @@
// the leaves of this subtree
cT subtree_leaves_v_t_inv_;
- // since we are using uniform density, we need
- // the max and min of every dimension for every node
- arma::vec maxVals;
- arma::vec minVals;
-
// the tag for the leaf used for hashing points
int bucket_tag_;
@@ -160,7 +160,7 @@
const double splitValue,
arma::Col<size_t>& oldFromNew) const;
- bool WithinRange_(VecType* query);
+ inline bool WithinRange(const arma::vec& query) const;
///////////////////// Public Functions //////////////////////////////////////
public:
@@ -172,7 +172,7 @@
// it contains instead of just the data.
DTree(const arma::vec& maxVals,
const arma::vec& minVals,
- size_t total_points);
+ const size_t totalPoints);
// Root node initializer
// with the data, no bounding box.
@@ -181,9 +181,9 @@
// Non-root node initializers
DTree(const arma::vec& max_vals,
const arma::vec& min_vals,
- size_t start,
- size_t end,
- cT error);
+ const size_t start,
+ const size_t end,
+ const double error);
DTree(const arma::vec& max_vals,
const arma::vec& min_vals,
Modified: mlpack/trunk/src/mlpack/methods/det/dtree_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/det/dtree_impl.hpp 2012-07-16 15:43:14 UTC (rev 13237)
+++ mlpack/trunk/src/mlpack/methods/det/dtree_impl.hpp 2012-07-16 16:06:47 UTC (rev 13238)
@@ -200,21 +200,18 @@
template<typename eT, typename cT>
DTree<eT, cT>::DTree(const arma::vec& maxVals,
const arma::vec& minVals,
- size_t total_points) :
+ const size_t totalPoints) :
start_(0),
- end_(total_points),
+ end_(totalPoints),
+ root_(true),
maxVals(maxVals),
minVals(minVals),
+ error_(-std::exp(LogNegativeError(totalPoints))),
+ bucket_tag_(-1),
left_(NULL),
right_(NULL)
-{
- error_ = -std::exp(LogNegativeError(total_points));
+{ /* Nothing to do. */ }
- bucket_tag_ = -1;
- root_ = true;
-}
-
-
template<typename eT, typename cT>
DTree<eT, cT>::DTree(arma::mat& data) :
start_(0),
@@ -223,7 +220,7 @@
right_(NULL)
{
maxVals.set_size(data.n_rows);
- minVals.set_size(data.n_cols);
+ minVals.set_size(data.n_rows);
// Initialize to first column; values will be overwritten if necessary.
maxVals = data.col(0);
@@ -252,42 +249,37 @@
template<typename eT, typename cT>
DTree<eT, cT>::DTree(const arma::vec& maxVals,
const arma::vec& minVals,
- size_t start,
- size_t end,
- cT error) :
+ const size_t start,
+ const size_t end,
+ const double error) :
start_(start),
end_(end),
- error_(error),
maxVals(maxVals),
minVals(minVals),
+ error_(error),
+ root_(false),
+ bucket_tag_(-1),
left_(NULL),
right_(NULL)
-{
- bucket_tag_ = -1;
- root_ = false;
-}
+{ /* Nothing to do. */ }
-
template<typename eT, typename cT>
DTree<eT, cT>::DTree(const arma::vec& maxVals,
const arma::vec& minVals,
- size_t total_points,
- size_t start,
- size_t end) :
+ const size_t totalPoints,
+ const size_t start,
+ const size_t end) :
start_(start),
end_(end),
maxVals(maxVals),
minVals(minVals),
+ error_(-std::exp(LogNegativeError(totalPoints))),
+ root_(false),
+ bucket_tag_(-1),
left_(NULL),
right_(NULL)
-{
- error_ = -std::exp(LogNegativeError(total_points));
+{ /* Nothing to do. */ }
- bucket_tag_ = -1;
- root_ = false;
-}
-
-
template<typename eT, typename cT>
DTree<eT, cT>::~DTree()
{
@@ -355,10 +347,8 @@
split_dim_ = dim;
// Recursively grow the children.
- left_ = new DTree(max_vals_l, min_vals_l, start_, splitIndex,
- (cT) left_error);
- right_ = new DTree(max_vals_r, min_vals_r, splitIndex, end_,
- (cT) right_error);
+ left_ = new DTree(max_vals_l, min_vals_l, start_, splitIndex, left_error);
+ right_ = new DTree(max_vals_r, min_vals_r, splitIndex, end_, right_error);
left_g = left_->Grow(data, old_from_new, useVolReg, maxLeafSize,
minLeafSize);
@@ -508,10 +498,10 @@
// Future improvement: Open up the range with epsilons on both sides where
// epsilon depends on the density near the boundary.
template<typename eT, typename cT>
-bool DTree<eT, cT>::WithinRange_(VecType* query)
+inline bool DTree<eT, cT>::WithinRange(const arma::vec& query) const
{
- for (size_t i = 0; i < query->n_elem; ++i)
- if (((*query)[i] < minVals[i]) || ((*query)[i] > maxVals[i]))
+ for (size_t i = 0; i < query.n_elem; ++i)
+ if ((query[i] < minVals[i]) || (query[i] > maxVals[i]))
return false;
return true;
@@ -525,7 +515,7 @@
if (root_ == 1) // If we are the root...
// Check if the query is within range.
- if (!WithinRange_(query))
+ if (!WithinRange(*query))
return 0.0;
if (subtree_leaves_ == 1) // If we are a leaf...
More information about the mlpack-svn
mailing list