[mlpack-svn] r13525 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Sep 10 15:28:21 EDT 2012
Author: rcurtin
Date: 2012-09-10 15:28:20 -0400 (Mon, 10 Sep 2012)
New Revision: 13525
Modified:
mlpack/trunk/src/mlpack/tests/kernel_test.cpp
Log:
Add tests for new MahalanobisDistance constructor.
Modified: mlpack/trunk/src/mlpack/tests/kernel_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/kernel_test.cpp 2012-09-10 19:27:44 UTC (rev 13524)
+++ mlpack/trunk/src/mlpack/tests/kernel_test.cpp 2012-09-10 19:28:20 UTC (rev 13525)
@@ -108,11 +108,13 @@
}
/**
- * Simple test of Mahalanobis distance with unset covariance matrix.
+ * Simple test of Mahalanobis distance with unset covariance matrix in
+ * constructor.
*/
BOOST_AUTO_TEST_CASE(md_unset_covariance)
{
MahalanobisDistance<false> md;
+ md.Covariance() = arma::eye<arma::mat>(4, 4);
arma::vec a = "1.0 2.0 2.0 3.0";
arma::vec b = "0.0 0.0 1.0 3.0";
@@ -121,12 +123,13 @@
}
/**
- * Simple test of Mahalanobis distance with unset covariance matrix and
- * t_take_root set to true.
+ * Simple test of Mahalanobis distance with unset covariance matrix in
+ * constructor and t_take_root set to true.
*/
BOOST_AUTO_TEST_CASE(md_root_unset_covariance)
{
MahalanobisDistance<true> md;
+ md.Covariance() = arma::eye<arma::mat>(4, 4);
arma::vec a = "1.0 2.0 2.5 5.0";
arma::vec b = "0.0 2.0 0.5 8.0";
@@ -135,6 +138,34 @@
}
/**
+ * Simple test of Mahalanobis distance setting identity covariance in
+ * constructor.
+ */
+BOOST_AUTO_TEST_CASE(md_eye_covariance)
+{
+ MahalanobisDistance<false> md(4);
+ arma::vec a = "1.0 2.0 2.0 3.0";
+ arma::vec b = "0.0 0.0 1.0 3.0";
+
+ BOOST_REQUIRE_CLOSE(md.Evaluate(a, b), 6.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(md.Evaluate(b, a), 6.0, 1e-5);
+}
+
+/**
+ * Simple test of Mahalanobis distance setting identity covariance in
+ * constructor and t_take_root set to true.
+ */
+BOOST_AUTO_TEST_CASE(md_root_eye_covariance)
+{
+ MahalanobisDistance<true> md(4);
+ arma::vec a = "1.0 2.0 2.5 5.0";
+ arma::vec b = "0.0 2.0 0.5 8.0";
+
+ BOOST_REQUIRE_CLOSE(md.Evaluate(a, b), sqrt(14.0), 1e-5);
+ BOOST_REQUIRE_CLOSE(md.Evaluate(b, a), sqrt(14.0), 1e-5);
+}
+
+/**
* Simple test with diagonal covariance matrix.
*/
BOOST_AUTO_TEST_CASE(md_diagonal_covariance)
More information about the mlpack-svn
mailing list