[mlpack-svn] r10714 - mlpack/trunk/src/mlpack/core/tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Dec 12 05:01:25 EST 2011
Author: rcurtin
Date: 2011-12-12 05:01:24 -0500 (Mon, 12 Dec 2011)
New Revision: 10714
Modified:
mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
Log:
Abstract-ize HRectBound to accept arbitrary types of things.
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp 2011-12-12 09:49:25 UTC (rev 10713)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp 2011-12-12 10:01:24 UTC (rev 10714)
@@ -73,12 +73,8 @@
/**
* Calculates minimum bound-to-point squared distance.
*/
- double MinDistance(const arma::vec& point) const;
- /**
- * Calculates minimum bound-to-point squared distance.
- */
- double MinDistance(const arma::vec& point,
- const std::vector<size_t>& indices) const;
+ template<typename VecType>
+ double MinDistance(const VecType& point) const;
/**
* Calculates minimum bound-to-bound squared distance.
@@ -86,33 +82,17 @@
* Example: bound1.MinDistanceSq(other) for minimum squared distance.
*/
double MinDistance(const HRectBound& other) const;
- /**
- * Calculates minimum bound-to-bound squared distance.
- *
- * Example: bound1.MinDistanceSq(other) for minimum squared distance.
- */
- double MinDistance(const HRectBound& other,
- const std::vector<size_t>& indices) const;
/**
* Calculates maximum bound-to-point squared distance.
*/
- double MaxDistance(const arma::vec& point) const;
- /**
- * Computes maximum distance.
- */
- double MaxDistance(const arma::vec& point,
- const std::vector<size_t>& indices) const;
+ template<typename VecType>
+ double MaxDistance(const VecType& point) const;
/**
* Computes maximum distance.
*/
double MaxDistance(const HRectBound& other) const;
- /**
- * Computes maximum distance.
- */
- double MaxDistance(const HRectBound& other,
- const std::vector<size_t>& indices) const;
/**
* Calculates minimum and maximum bound-to-bound squared distance.
@@ -122,12 +102,14 @@
/**
* Calculates minimum and maximum bound-to-point squared distance.
*/
- math::Range RangeDistance(const arma::vec& point) const;
+ template<typename VecType>
+ math::Range RangeDistance(const VecType& point) const;
/**
* Expands this region to include a new point.
*/
- HRectBound& operator|=(const arma::vec& vector);
+ template<typename VecType>
+ HRectBound& operator|=(const VecType& vector);
/**
* Expands this region to encompass another bound.
@@ -137,7 +119,8 @@
/**
* Determines if a point is within this bound.
*/
- bool Contains(const arma::vec& point) const;
+ template<typename VecType>
+ bool Contains(const VecType& point) const;
private:
size_t dim;
Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp 2011-12-12 09:49:25 UTC (rev 10713)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp 2011-12-12 10:01:24 UTC (rev 10714)
@@ -128,7 +128,8 @@
* Calculates minimum bound-to-point squared distance.
*/
template<int t_pow>
-double HRectBound<t_pow>::MinDistance(const arma::vec& point) const
+template<typename VecType>
+double HRectBound<t_pow>::MinDistance(const VecType& point) const
{
Log::Assert(point.n_elem == dim);
@@ -153,37 +154,6 @@
}
/**
- * Calculates minimum bound-to-point squared distance, filtered
- * by indices.
- */
-template<int t_pow>
-double HRectBound<t_pow>::MinDistance(const arma::vec& point,
- const std::vector<size_t>& indices) const
-{
- Log::Assert(point.n_elem == dim);
-
- double sum = 0.0;
-
- double lower, higher;
- for (size_t index = 0; index < indices.size(); index++)
- {
- size_t dimension = indices[index];
- lower = bounds[dimension].lo - point[dimension];
- higher = point[dimension] - bounds[dimension].hi;
-
- // Since at least one of 'lower' or 'higher' is negative, if we add each's
- // absolute value to itself and then sum those two, our result is the
- // nonnegative half of the equation times two; then we raise to power t_pow.
- sum += pow((lower + fabs(lower)) + (higher + fabs(higher)), (double) t_pow);
- }
-
- // Now take the t_pow'th root (but make sure our result is squared); then
- // divide by four to cancel out the constant of 2 (which has been squared now)
- // that was introduced earlier.
- return pow(sum, 2.0 / (double) t_pow) / 4.0;
-}
-
-/**
* Calculates minimum bound-to-bound squared distance.
*
* Example: bound1.MinDistanceSq(other) for minimum squared distance.
@@ -216,39 +186,11 @@
}
/**
- * Calculates minimum bound-to-bound squared distance, filtered by indices.
- *
- * Example: bound1.MinDistanceSq(other, indices) for minimum squared distance.
- */
-template<int t_pow>
-double HRectBound<t_pow>::MinDistance(const HRectBound& other,
- const std::vector<size_t>& indices) const
-{
- Log::Assert(dim == other.dim);
-
- double sum = 0.0;
- double lower, higher;
-
- for (size_t index = 0; index < indices.size(); index++)
- {
- size_t dimension = indices[index];
- lower = bounds[dimension].lo - other.bounds[dimension].hi;
- higher = other.bounds[dimension].lo - bounds[dimension].hi;
-
- // Since only one of 'lower' or 'higher' is negative, if we add each's
- // absolute value to itself and then sum those two, our result is the
- // nonnegative half of the equation times two; then we raise to power t_pow.
- sum += pow((lower + fabs(lower)) + (higher + fabs(higher)), (double) t_pow);
- }
-
- return pow(sum, 2.0 / (double) t_pow) / 4.0;
-}
-
-/**
* Calculates maximum bound-to-point squared distance.
*/
template<int t_pow>
-double HRectBound<t_pow>::MaxDistance(const arma::vec& point) const
+template<typename VecType>
+double HRectBound<t_pow>::MaxDistance(const VecType& point) const
{
double sum = 0;
@@ -265,30 +207,6 @@
}
/**
- * Calculates maximum bound-to-point squared distance, filtered by indices.
- */
-template<int t_pow>
-double HRectBound<t_pow>::MaxDistance(const arma::vec& point,
- const std::vector<size_t>& indices) const
-{
- double sum = 0.0;
- double lower, higher;
-
- Log::Assert(point.n_elem == dim);
-
- for (size_t index = 0; index < indices.size(); index++)
- {
- size_t dimension = indices[index];
- lower = fabs(point[dimension] - bounds[dimension].lo);
- higher = fabs(point[dimension] - bounds[dimension].hi);
-
- sum += pow(fabs(higher - lower) + higher + lower, (double) t_pow);
- }
-
- return pow(sum, 2.0 / (double) t_pow) / 4.0;
-}
-
-/**
* Computes maximum distance.
*/
template<int t_pow>
@@ -310,31 +228,6 @@
}
/**
- * Computes the maximum distance between blocks,
- * filtered by indices.
- */
-template<int t_pow>
-double HRectBound<t_pow>::MaxDistance(const HRectBound& other,
- const std::vector<size_t>& indices) const
-{
- double sum = 0.0;
- double lower, higher;
-
- Log::Assert(other.dim == dim);
-
- for (size_t index = 0; index < indices.size(); index++)
- {
- size_t dimension = indices[index];
- lower = fabs(other.bounds[dimension].hi - bounds[dimension].lo);
- higher = fabs(other.bounds[dimension].lo - bounds[dimension].hi);
-
- sum += pow(fabs(higher-lower) + higher + lower, (double) t_pow);
- }
-
- return pow(sum, 2.0 / (double) t_pow) / 4.0;
-}
-
-/**
* Calculates minimum and maximum bound-to-bound squared distance.
*/
template<int t_pow>
@@ -374,7 +267,8 @@
* Calculates minimum and maximum bound-to-point squared distance.
*/
template<int t_pow>
-math::Range HRectBound<t_pow>::RangeDistance(const arma::vec& point) const
+template<typename VecType>
+math::Range HRectBound<t_pow>::RangeDistance(const VecType& point) const
{
double loSum = 0;
double hiSum = 0;
@@ -418,7 +312,8 @@
* Expands this region to include a new point.
*/
template<int t_pow>
-HRectBound<t_pow>& HRectBound<t_pow>::operator|=(const arma::vec& vector)
+template<typename VecType>
+HRectBound<t_pow>& HRectBound<t_pow>::operator|=(const VecType& vector)
{
Log::Assert(vector.n_elem == dim);
@@ -446,7 +341,8 @@
* Determines if a point is within this bound.
*/
template<int t_pow>
-bool HRectBound<t_pow>::Contains(const arma::vec& point) const
+template<typename VecType>
+bool HRectBound<t_pow>::Contains(const VecType& point) const
{
for (size_t i = 0; i < point.n_elem; i++)
{
More information about the mlpack-svn
mailing list