[mlpack-svn] r15485 - mlpack/trunk/src/mlpack/tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Jul 17 11:34:28 EDT 2013


Author: rcurtin
Date: Wed Jul 17 11:34:28 2013
New Revision: 15485

Log:
Clean up PCA test.


Modified:
   mlpack/trunk/src/mlpack/tests/pca_test.cpp

Modified: mlpack/trunk/src/mlpack/tests/pca_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/pca_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/pca_test.cpp	Wed Jul 17 11:34:28 2013
@@ -27,7 +27,7 @@
   vec eigVal, eigVal1;
   mat score, score1;
 
-  mat data = randu<mat>(100,100);
+  mat data = randu<mat>(100, 100);
 
   PCA p;
 
@@ -35,9 +35,13 @@
   princomp(coeff, score, eigVal, trans(data));
 
   // Verify the PCA results based on the eigenvalues.
-  for(size_t i = 0; i < eigVal.n_rows; i++)
-    for(size_t j = 0; j < eigVal.n_cols; j++)
-      BOOST_REQUIRE_SMALL(eigVal(i, j) - eigVal1(i, j), 0.0001);
+  for (size_t i = 0; i < eigVal.n_elem; i++)
+  {
+    if (eigVal[i] == 0.0)
+      BOOST_REQUIRE_SMALL(eigVal1[i], 1e-15);
+    else
+      BOOST_REQUIRE_CLOSE(eigVal[i], eigVal1[i], 0.0001);
+  }
 }
 
 /**
@@ -63,7 +67,7 @@
   // each other out in this summation.
   for (size_t i = 0; i < data.n_rows; i++)
   {
-    if (fabs(correct(i, 1) + data(i, 1)) < 0.001 /* arbitrary */)
+    if (accu(abs(correct.row(i) + data.row(i))) < 0.001 /* arbitrary */)
     {
       // Flip Armadillo coefficients for this column.
       data.row(i) *= -1;



More information about the mlpack-svn mailing list