[mlpack-git] mlpack-1.0.x: Merge r17174-17175 into mlpack-1.0.11. (189acb6)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:06:52 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 189acb6ac80dd5fd9793752684fa38a245b3510b
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Dec 7 19:09:55 2014 +0000

    Merge r17174-17175 into mlpack-1.0.11.


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

189acb6ac80dd5fd9793752684fa38a245b3510b
 src/mlpack/methods/pca/pca.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/mlpack/methods/pca/pca.cpp b/src/mlpack/methods/pca/pca.cpp
index c4aa026..1484c15 100644
--- a/src/mlpack/methods/pca/pca.cpp
+++ b/src/mlpack/methods/pca/pca.cpp
@@ -22,8 +22,6 @@
  */
 #include "pca.hpp"
 #include <mlpack/core.hpp>
-#include <iostream>
-#include <complex>
 
 using namespace std;
 using namespace mlpack;
@@ -139,8 +137,12 @@ double PCA::Apply(arma::mat& data, const size_t newDimension) const
     // Drop unnecessary rows.
     data.shed_rows(newDimension, data.n_rows - 1);
 
+  // The svd method returns only non-zero eigenvalues so we have to calculate
+  // the right dimension before calculating the amount of variance retained.
+  double eigDim = std::min(newDimension - 1, (size_t) eigVal.n_elem - 1);
+
   // Calculate the total amount of variance retained.
-  return (sum(eigVal.subvec(0, newDimension - 1)) / sum(eigVal));
+  return (sum(eigVal.subvec(0, eigDim)) / sum(eigVal));
 }
 
 /**



More information about the mlpack-git mailing list