[mlpack-svn] r16809 - mlpack/trunk/src/mlpack/core/tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Jul 10 10:31:01 EDT 2014
Author: rcurtin
Date: Thu Jul 10 10:31:00 2014
New Revision: 16809
Log:
Add MinWidth(), which is a better solution than having the tree calculate it by
hand.
Modified:
mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp Thu Jul 10 10:31:00 2014
@@ -60,11 +60,17 @@
//! Gets the dimensionality.
size_t Dim() const { return dim; }
- //! Get the range for a particular dimension. No bounds checking.
+ //! Get the range for a particular dimension. No bounds checking. Be
+ //! careful: this may make MinWidth() invalid.
math::Range& operator[](const size_t i) { return bounds[i]; }
//! Modify the range for a particular dimension. No bounds checking.
const math::Range& operator[](const size_t i) const { return bounds[i]; }
+ //! Get the minimum width of the bound.
+ double MinWidth() const { return minWidth; }
+ //! Modify the minimum width of the bound.
+ double& MinWidth() { return minWidth; }
+
/**
* Calculates the centroid of the range, placing it into the given vector.
*
@@ -166,6 +172,8 @@
size_t dim;
//! The bounds for each dimension.
math::Range* bounds;
+ //! Cached minimum width of bound.
+ double minWidth;
};
}; // namespace bound
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp Thu Jul 10 10:31:00 2014
@@ -23,7 +23,8 @@
template<int Power, bool TakeRoot>
HRectBound<Power, TakeRoot>::HRectBound() :
dim(0),
- bounds(NULL)
+ bounds(NULL),
+ minWidth(0)
{ /* Nothing to do. */ }
/**
@@ -33,7 +34,8 @@
template<int Power, bool TakeRoot>
HRectBound<Power, TakeRoot>::HRectBound(const size_t dimension) :
dim(dimension),
- bounds(new math::Range[dim])
+ bounds(new math::Range[dim]),
+ minWidth(0)
{ /* Nothing to do. */ }
/***
@@ -42,7 +44,8 @@
template<int Power, bool TakeRoot>
HRectBound<Power, TakeRoot>::HRectBound(const HRectBound& other) :
dim(other.Dim()),
- bounds(new math::Range[dim])
+ bounds(new math::Range[dim]),
+ minWidth(other.MinWidth())
{
// Copy other bounds over.
for (size_t i = 0; i < dim; i++)
@@ -70,6 +73,8 @@
for (size_t i = 0; i < dim; i++)
bounds[i] = other[i];
+ minWidth = other.MinWidth();
+
return *this;
}
@@ -91,6 +96,7 @@
{
for (size_t i = 0; i < dim; i++)
bounds[i] = math::Range();
+ minWidth = 0;
}
/***
@@ -333,8 +339,14 @@
arma::vec mins(min(data, 1));
arma::vec maxs(max(data, 1));
+ minWidth = DBL_MAX;
for (size_t i = 0; i < dim; i++)
+ {
bounds[i] |= math::Range(mins[i], maxs[i]);
+ const double width = bounds[i].Hi() - bounds[i].Lo();
+ if (width < minWidth)
+ minWidth = width;
+ }
return *this;
}
@@ -348,8 +360,14 @@
{
assert(other.dim == dim);
+ minWidth = DBL_MAX;
for (size_t i = 0; i < dim; i++)
+ {
bounds[i] |= other.bounds[i];
+ const double width = bounds[i].Hi() - bounds[i].Lo();
+ if (width < minWidth)
+ minWidth = width;
+ }
return *this;
}
@@ -400,6 +418,7 @@
convert << " Bounds: " << std::endl;
for (size_t i = 0; i < dim; ++i)
convert << util::Indent(bounds[i].ToString()) << std::endl;
+ convert << " Minimum width: " << minWidth << std::endl;
return convert.str();
}
More information about the mlpack-svn
mailing list