[mlpack-git] master: Add QUIC-SVD singular values test. (a91fefa)

gitdub at mlpack.org gitdub at mlpack.org
Wed Jul 6 15:30:09 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/98babfc774bce91170df994763b670b9abd20917...e7b9b042d1d6e2d9895d5fa141e9c135b2d2ea57

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

commit a91fefaff03530ddb969352dde732dc03f3894ff
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Wed Jul 6 01:02:51 2016 +0200

    Add QUIC-SVD singular values test.


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

a91fefaff03530ddb969352dde732dc03f3894ff
 src/mlpack/tests/quic_svd_test.cpp | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/src/mlpack/tests/quic_svd_test.cpp b/src/mlpack/tests/quic_svd_test.cpp
index 218bfff..81316ac 100644
--- a/src/mlpack/tests/quic_svd_test.cpp
+++ b/src/mlpack/tests/quic_svd_test.cpp
@@ -14,7 +14,6 @@
 BOOST_AUTO_TEST_SUITE(QUICSVDTest);
 
 using namespace mlpack;
-using namespace mlpack::svd;
 
 /**
  * The reconstruction error of the obtained SVD should be small.
@@ -27,7 +26,7 @@ BOOST_AUTO_TEST_CASE(QUICSVDReconstructionError)
 
   // Obtain the SVD using default parameters.
   arma::mat u, v, sigma;
-  QUIC_SVD quicsvd(dataset, u, v, sigma);
+  svd::QUIC_SVD quicsvd(dataset, u, v, sigma);
 
   // Reconstruct the matrix using the SVD.
   arma::mat reconstruct;
@@ -39,4 +38,35 @@ BOOST_AUTO_TEST_CASE(QUICSVDReconstructionError)
   BOOST_REQUIRE_SMALL(relativeError, 1e-5);
 }
 
+/**
+ * The singular value error of the obtained SVD should be small.
+ */
+BOOST_AUTO_TEST_CASE(QUICSVDSigularValueError)
+{
+  arma::mat U = arma::randn<arma::mat>(3, 20);
+  arma::mat V = arma::randn<arma::mat>(10, 3);
+
+  arma::mat R;
+  arma::qr_econ(U, R, U);
+  arma::qr_econ(V, R, V);
+
+  arma::mat s = arma::diagmat(arma::vec("1 0.1 0.01"));
+
+  arma::mat data = arma::trans(U * arma::diagmat(s) * V.t());
+
+  arma::vec s1, s3;
+  arma::mat U1, U2, V1, V2, s2;
+
+  // Obtain the SVD using default parameters.
+  arma::svd_econ(U1, s1, V1, data);
+  svd::QUIC_SVD quicsvd(data, U1, V1, s2);
+
+  s3 = arma::diagvec(s2);
+  s1 = s1.subvec(0, s3.n_elem - 1);
+
+  // The sigular value error should be small.
+  double error = arma::norm(s1 - s3);
+  BOOST_REQUIRE_SMALL(error, 0.02);
+}
+
 BOOST_AUTO_TEST_SUITE_END();




More information about the mlpack-git mailing list