[mlpack] 02/44: Merge r17174-17175 into mlpack-1.0.11.

Barak A. Pearlmutter barak+git at pearlmutter.net
Mon Feb 15 19:35:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to tag mlpack-1.0.11
in repository mlpack.

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.
---
 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));
 }
 
 /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list