[mlpack-svn] r13359 - mlpack/trunk/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Aug 7 14:55:31 EDT 2012
Author: rmohan
Date: 2012-08-07 14:55:30 -0400 (Tue, 07 Aug 2012)
New Revision: 13359
Modified:
mlpack/trunk/src/mlpack/tests/nmf_test.cpp
Log:
Fixed NMF Test
Modified: mlpack/trunk/src/mlpack/tests/nmf_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/nmf_test.cpp 2012-08-07 13:53:53 UTC (rev 13358)
+++ mlpack/trunk/src/mlpack/tests/nmf_test.cpp 2012-08-07 18:55:30 UTC (rev 13359)
@@ -6,6 +6,9 @@
*/
#include <mlpack/core.hpp>
#include <mlpack/methods/nmf/nmf.hpp>
+#include <mlpack/methods/nmf/random_acol_init.hpp>
+#include <mlpack/methods/nmf/mult_div_update_rules.hpp>
+#include <mlpack/methods/nmf/als_update_rules.hpp>
#include <boost/test/unit_test.hpp>
#include "old_boost_test_definitions.hpp"
@@ -19,26 +22,90 @@
/**
* Check the if the product of the calculated factorization is close to the
- * input matrix.
+ * input matrix. Default case
*/
-BOOST_AUTO_TEST_CASE(NMFTest)
+BOOST_AUTO_TEST_CASE(NMFDefaultTest)
{
- mat v = randu<mat>(5, 5);
- size_t r = 4;
- mat w, h;
+ mat w = randu<mat>(20, 16);
+ mat h = randu<mat>(16, 20);
+ mat v = w * h;
+ size_t r = 16;
- NMF<> nmf(0);
+ NMF<> nmf;
nmf.Apply(v, r, w, h);
mat wh = w * h;
- v.print("v");
- wh.print("wh");
+ for (size_t row = 0; row < 5; row++)
+ for (size_t col = 0; col < 5; col++)
+ BOOST_REQUIRE_CLOSE(v(row, col), wh(row, col), 10.0);
+}
-// for (size_t row = 0; row < 5; row++)
-// for (size_t col = 0; col < 5; col++)
-// BOOST_REQUIRE_CLOSE(v(row, col), wh(row, col), 5.0);
+/**
+ * Check the if the product of the calculated factorization is close to the
+ * input matrix. Random Acol Initialization Distance Minimization Update
+ */
+BOOST_AUTO_TEST_CASE(NMFAcolDistTest)
+{
+ mat w = randu<mat>(20, 16);
+ mat h = randu<mat>(16, 20);
+ mat v = w * h;
+ size_t r = 16;
+
+ NMF<RandomAcolInitialization> nmf;
+ nmf.Apply(v, r, w, h);
+
+ mat wh = w * h;
+
+ for (size_t row = 0; row < 5; row++)
+ for (size_t col = 0; col < 5; col++)
+ BOOST_REQUIRE_CLOSE(v(row, col), wh(row, col), 10.0);
}
+/**
+ * Check the if the product of the calculated factorization is close to the
+ * input matrix. Random Initialization Divergence Minimization Update
+ */
+BOOST_AUTO_TEST_CASE(NMFRandomDivTest)
+{
+ mat w = randu<mat>(20, 16);
+ mat h = randu<mat>(16, 20);
+ mat v = w * h;
+ size_t r = 16;
+ NMF<RandomInitialization,
+ WMultiplicativeDivergenceRule,
+ HMultiplicativeDivergenceRule> nmf;
+ nmf.Apply(v, r, w, h);
+
+ mat wh = w * h;
+
+ for (size_t row = 0; row < 5; row++)
+ for (size_t col = 0; col < 5; col++)
+ BOOST_REQUIRE_CLOSE(v(row, col), wh(row, col), 10.0);
+}
+
+/**
+ * Check the if the product of the calculated factorization is close to the
+ * input matrix. Random Initialization Alternating Least Squares Update
+ */
+BOOST_AUTO_TEST_CASE(NMFALSTest)
+{
+ mat w = randu<mat>(20, 16);
+ mat h = randu<mat>(16, 20);
+ mat v = w * h;
+ size_t r = 16;
+
+ NMF<RandomInitialization,
+ WAlternatingLeastSquaresRule,
+ HAlternatingLeastSquaresRule> nmf;
+ nmf.Apply(v, r, w, h);
+
+ mat wh = w * h;
+
+ for (size_t row = 0; row < 5; row++)
+ for (size_t col = 0; col < 5; col++)
+ BOOST_REQUIRE_CLOSE(v(row, col), wh(row, col), 10.0);
+}
+
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list