[mlpack-svn] r17064 - in mlpack/trunk/src/mlpack: core/tree tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Aug 18 13:50:15 EDT 2014
Author: rcurtin
Date: Mon Aug 18 13:50:15 2014
New Revision: 17064
Log:
Add HRectBound<>::Volume() and a test for it.
Modified:
mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
mlpack/trunk/src/mlpack/tests/tree_test.cpp
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 Mon Aug 18 13:50:15 2014
@@ -79,6 +79,13 @@
void Centroid(arma::vec& centroid) const;
/**
+ * Calculate the volume of the hyperrectangle.
+ *
+ * @return Volume of the hyperrectangle.
+ */
+ double Volume() const;
+
+ /**
* Calculates minimum bound-to-point distance.
*
* @param point Point to which the minimum distance is requested.
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 Mon Aug 18 13:50:15 2014
@@ -116,6 +116,21 @@
}
/**
+ * Calculate the volume of the hyperrectangle.
+ *
+ * @return Volume of the hyperrectangle.
+ */
+template<int Power, bool TakeRoot>
+double HRectBound<Power, TakeRoot>::Volume() const
+{
+ double volume = 1.0;
+ for (size_t i = 0; i < dim; ++i)
+ volume *= (bounds[i].Hi() - bounds[i].Lo());
+
+ return volume;
+}
+
+/**
* Calculates minimum bound-to-point squared distance.
*/
template<int Power, bool TakeRoot>
Modified: mlpack/trunk/src/mlpack/tests/tree_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/tree_test.cpp (original)
+++ mlpack/trunk/src/mlpack/tests/tree_test.cpp Mon Aug 18 13:50:15 2014
@@ -143,6 +143,21 @@
}
/**
+ * Ensure the volume calculation is correct.
+ */
+BOOST_AUTO_TEST_CASE(HRectBoundVolume)
+{
+ // Create a simple 3-dimensional bound.
+ HRectBound<2> b(3);
+
+ b[0] = Range(0.0, 5.0);
+ b[1] = Range(-2.0, -1.0);
+ b[2] = Range(-10.0, 50.0);
+
+ BOOST_REQUIRE_CLOSE(b.Volume(), 300.0, 1e-5);
+}
+
+/**
* Ensure that we calculate the correct minimum distance between a point and a
* bound.
*/
More information about the mlpack-svn
mailing list