[mlpack-git] mlpack-1.0.x: Merge r17174-17175 into mlpack-1.0.11. (5c29174)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Jan 7 11:57:56 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : mlpack-1.0.x
Link : https://github.com/mlpack/mlpack/compare/0000000000000000000000000000000000000000...904762495c039e345beba14c1142fd719b3bd50e
>---------------------------------------------------------------
commit 5c29174046ea68ddacbfc99548b1650732188de3
Author: Ryan Curtin <ryan at ratml.org>
Date: Sun Dec 7 19:09:55 2014 +0000
Merge r17174-17175 into mlpack-1.0.11.
>---------------------------------------------------------------
5c29174046ea68ddacbfc99548b1650732188de3
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