[mlpack] 318/324: Center the reconstructed approximation and the kernel matrix.
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:22:22 UTC 2014
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit ed50e1c9bb27db2878baa2250e886b3dc55f988a
Author: marcus <marcus at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Fri Aug 15 16:52:11 2014 +0000
Center the reconstructed approximation and the kernel matrix.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17031 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../kernel_pca/kernel_rules/nystroem_method.hpp | 26 ++++++++++++++--------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/mlpack/methods/kernel_pca/kernel_rules/nystroem_method.hpp b/src/mlpack/methods/kernel_pca/kernel_rules/nystroem_method.hpp
index 34bcf62..044db4e 100644
--- a/src/mlpack/methods/kernel_pca/kernel_rules/nystroem_method.hpp
+++ b/src/mlpack/methods/kernel_pca/kernel_rules/nystroem_method.hpp
@@ -45,21 +45,29 @@ class NystroemKernelRule
nm.Apply(G);
transformedData = G.t() * G;
+ // Center the reconstructed approximation.
+ math::Center(transformedData, transformedData);
+
// For PCA the data has to be centered, even if the data is centered. But
// it is not guaranteed that the data, when mapped to the kernel space, is
- // also centered. Since we actually never work in the feature space we
+ // also centered. Since we actually never work in the feature space we
// cannot center the data. So, we perform a "psuedo-centering" using the
// kernel matrix.
- arma::rowvec rowMean = arma::sum(transformedData, 0) /
- transformedData.n_cols;
- transformedData.each_col() -= arma::sum(transformedData, 1) /
- transformedData.n_cols;
- transformedData.each_row() -= rowMean;
- transformedData += arma::sum(rowMean) / transformedData.n_cols;
+ arma::colvec colMean = arma::sum(G, 1) / G.n_rows;
+ G.each_row() -= arma::sum(G, 0) / G.n_rows;
+ G.each_col() -= colMean;
+ G += arma::sum(colMean) / G.n_rows;
// Eigendecompose the centered kernel matrix.
- arma::svd(eigvec, eigval, v, transformedData);
- eigval %= eigval / (data.n_cols - 1);
+ arma::eig_sym(eigval, eigvec, transformedData);
+
+ // Swap the eigenvalues since they are ordered backwards (we need largest
+ // to smallest).
+ for (size_t i = 0; i < floor(eigval.n_elem / 2.0); ++i)
+ eigval.swap_rows(i, (eigval.n_elem - 1) - i);
+
+ // Flip the coefficients to produce the same effect.
+ eigvec = arma::fliplr(eigvec);
transformedData = eigvec.t() * G.t();
}
--
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