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

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Dec 6 04:48:20 EST 2011


Author: ajinkya
Date: 2011-12-06 04:48:19 -0500 (Tue, 06 Dec 2011)
New Revision: 10579

Modified:
   mlpack/trunk/src/mlpack/tests/pca_test.cpp
Log:
changed the test to accomodate pricipal axes in opp direction ie when eigenvectors returned are flipped in sign compared to the eignvec returned by matlab for the same dataset

Modified: mlpack/trunk/src/mlpack/tests/pca_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/pca_test.cpp	2011-12-06 09:06:07 UTC (rev 10578)
+++ mlpack/trunk/src/mlpack/tests/pca_test.cpp	2011-12-06 09:48:19 UTC (rev 10579)
@@ -41,7 +41,7 @@
 /**
  * Test that dimensionality reduction with PCA works the same way MATLAB does
  * (which should be correct!).
- *
+ */
 BOOST_AUTO_TEST_CASE(PCADimensionalityReductionTest)
 {
   // Fake, simple dataset.  The results we will compare against are from MATLAB.
@@ -57,10 +57,21 @@
   mat correct("-1.53781086 -3.51358020 -0.16139887 -1.87706634  7.08985628;"
               " 1.29937798  3.45762685 -2.69910005 -3.15620704  1.09830225");
 
+  // If the eigenvectors are pointed opposite directions, they will cancel
+// 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 */)
+    {
+         // Flip Armadillo coefficients for this column.
+         data.row(i) *= -1;
+    }
+  }
+
   for (size_t row = 0; row < 2; row++)
     for (size_t col = 0; col < 5; col++)
       BOOST_REQUIRE_CLOSE(data(row, col), correct(row, col), 1e-3);
 }
-*/
 
+
 BOOST_AUTO_TEST_SUITE_END();




More information about the mlpack-svn mailing list