[mlpack-git] master: Add some more tests. (7c7add5)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Fri Jul 10 19:00:03 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/4a97187bbba7ce8a6191b714949dd818ef0f37d2...e5905e62c15d1bcff21e6359b11efcd7ab6d7ca0

>---------------------------------------------------------------

commit 7c7add5f6ff1ad65c0c3e4eb84207dd5585cf6a3
Author: ryan <ryan at ratml.org>
Date:   Tue Apr 21 16:08:40 2015 -0400

    Add some more tests.


>---------------------------------------------------------------

7c7add5f6ff1ad65c0c3e4eb84207dd5585cf6a3
 src/mlpack/tests/serialization_test.cpp | 103 ++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/src/mlpack/tests/serialization_test.cpp b/src/mlpack/tests/serialization_test.cpp
index e34f417..23f07cb 100644
--- a/src/mlpack/tests/serialization_test.cpp
+++ b/src/mlpack/tests/serialization_test.cpp
@@ -17,10 +17,15 @@
 #include "old_boost_test_definitions.hpp"
 
 #include <mlpack/core/dists/regression_distribution.hpp>
+#include <mlpack/core/tree/ballbound.hpp>
+#include <mlpack/core/tree/hrectbound.hpp>
+#include <mlpack/core/metrics/mahalanobis_distance.hpp>
 
 using namespace mlpack;
 using namespace mlpack::distribution;
 using namespace mlpack::regression;
+using namespace mlpack::bound;
+using namespace mlpack::metric;
 using namespace arma;
 using namespace boost;
 using namespace boost::archive;
@@ -353,6 +358,22 @@ BOOST_AUTO_TEST_CASE(LaplaceDistributionTest)
   CheckMatrices(l.Mean(), xmlL.Mean(), textL.Mean(), binaryL.Mean());
 }
 
+BOOST_AUTO_TEST_CASE(MahalanobisDistanceTest)
+{
+  MahalanobisDistance<> d;
+  d.Covariance().randu(50, 50);
+
+  MahalanobisDistance<> xmlD, textD, binaryD;
+
+  SerializeObjectAll(d, xmlD, textD, binaryD);
+
+  // Check the covariance matrices.
+  CheckMatrices(d.Covariance(),
+                xmlD.Covariance(),
+                textD.Covariance(),
+                binaryD.Covariance());
+}
+
 BOOST_AUTO_TEST_CASE(LinearRegressionTest)
 {
   // Generate some random data.
@@ -418,4 +439,86 @@ BOOST_AUTO_TEST_CASE(RegressionDistributionTest)
                 binaryRd.Rf().Parameters());
 }
 
+BOOST_AUTO_TEST_CASE(BallBoundTest)
+{
+  BallBound<> b(100);
+  b.Center().randu();
+  b.Radius() = 14.0;
+
+  BallBound<> xmlB, textB, binaryB;
+
+  SerializeObjectAll(b, xmlB, textB, binaryB);
+
+  // Check the dimensionality.
+  BOOST_REQUIRE_EQUAL(b.Dim(), xmlB.Dim());
+  BOOST_REQUIRE_EQUAL(b.Dim(), textB.Dim());
+  BOOST_REQUIRE_EQUAL(b.Dim(), binaryB.Dim());
+
+  // Check the radius.
+  BOOST_REQUIRE_CLOSE(b.Radius(), xmlB.Radius(), 1e-8);
+  BOOST_REQUIRE_CLOSE(b.Radius(), textB.Radius(), 1e-8);
+  BOOST_REQUIRE_CLOSE(b.Radius(), binaryB.Radius(), 1e-8);
+
+  // Now check the vectors.
+  CheckMatrices(b.Center(), xmlB.Center(), textB.Center(), binaryB.Center());
+}
+
+BOOST_AUTO_TEST_CASE(MahalanobisBallBoundTest)
+{
+  BallBound<arma::vec, MahalanobisDistance<>> b(100);
+  b.Center().randu();
+  b.Radius() = 14.0;
+  b.Metric().Covariance().randu(100, 100);
+
+  BallBound<arma::vec, MahalanobisDistance<>> xmlB, textB, binaryB;
+
+  SerializeObjectAll(b, xmlB, textB, binaryB);
+
+  // Check the radius.
+  BOOST_REQUIRE_CLOSE(b.Radius(), xmlB.Radius(), 1e-8);
+  BOOST_REQUIRE_CLOSE(b.Radius(), textB.Radius(), 1e-8);
+  BOOST_REQUIRE_CLOSE(b.Radius(), binaryB.Radius(), 1e-8);
+
+  // Check the vectors.
+  CheckMatrices(b.Center(), xmlB.Center(), textB.Center(), binaryB.Center());
+  CheckMatrices(b.Metric().Covariance(),
+                xmlB.Metric().Covariance(),
+                textB.Metric().Covariance(),
+                binaryB.Metric().Covariance());
+}
+
+BOOST_AUTO_TEST_CASE(HRectBoundTest)
+{
+  HRectBound<2> b(2);
+
+  arma::mat points("0.0, 1.1; 5.0, 2.2");
+  points = points.t();
+  b |= points; // [0.0, 5.0]; [1.1, 2.2];
+  
+  HRectBound<2> xmlB, textB, binaryB;
+
+  SerializeObjectAll(b, xmlB, textB, binaryB);
+
+  // Check the dimensionality.
+  BOOST_REQUIRE_EQUAL(b.Dim(), xmlB.Dim());
+  BOOST_REQUIRE_EQUAL(b.Dim(), textB.Dim());
+  BOOST_REQUIRE_EQUAL(b.Dim(), binaryB.Dim());
+
+  // Check the bounds.
+  for (size_t i = 0; i < b.Dim(); ++i)
+  {
+    BOOST_REQUIRE_CLOSE(b[i].Lo(), xmlB[i].Lo(), 1e-8);
+    BOOST_REQUIRE_CLOSE(b[i].Hi(), xmlB[i].Hi(), 1e-8);
+    BOOST_REQUIRE_CLOSE(b[i].Lo(), textB[i].Lo(), 1e-8);
+    BOOST_REQUIRE_CLOSE(b[i].Hi(), textB[i].Hi(), 1e-8);
+    BOOST_REQUIRE_CLOSE(b[i].Lo(), binaryB[i].Lo(), 1e-8);
+    BOOST_REQUIRE_CLOSE(b[i].Hi(), binaryB[i].Hi(), 1e-8);
+  }
+
+  // Check the minimum width.
+  BOOST_REQUIRE_CLOSE(b.MinWidth(), xmlB.MinWidth(), 1e-8);
+  BOOST_REQUIRE_CLOSE(b.MinWidth(), textB.MinWidth(), 1e-8);
+  BOOST_REQUIRE_CLOSE(b.MinWidth(), binaryB.MinWidth(), 1e-8);
+}
+
 BOOST_AUTO_TEST_SUITE_END();



More information about the mlpack-git mailing list