From e7b9b042d1d6e2d9895d5fa141e9c135b2d2ea57 Mon Sep 17 00:00:00 2001 From: Marcus Edel Date: Wed, 6 Jul 2016 14:19:03 +0200 Subject: [PATCH] Parameter unification; add comment about PCAType class will be changed to have the name PCA in mlpack 3.0.0. --- src/mlpack/methods/pca/pca.hpp | 5 +++-- src/mlpack/methods/pca/pca_impl.hpp | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/mlpack/methods/pca/pca.hpp b/src/mlpack/methods/pca/pca.hpp index 41c7517dfe..62b5475c61 100644 --- a/src/mlpack/methods/pca/pca.hpp +++ b/src/mlpack/methods/pca/pca.hpp @@ -22,7 +22,8 @@ namespace pca { * common, widely-used technique that is often used for either dimensionality * reduction or transforming data into a better basis. Further information on * PCA can be found in almost any statistics or machine learning textbook, and - * all over the internet. + * all over the internet. Note this class will be changed to have the name PCA + * in mlpack 3.0.0 */ template class PCAType @@ -48,7 +49,7 @@ class PCAType */ void Apply(const arma::mat& data, arma::mat& transformedData, - arma::vec& eigval, + arma::vec& eigVal, arma::mat& eigvec); /** diff --git a/src/mlpack/methods/pca/pca_impl.hpp b/src/mlpack/methods/pca/pca_impl.hpp index 9e3a89cdc0..9f963b22b9 100644 --- a/src/mlpack/methods/pca/pca_impl.hpp +++ b/src/mlpack/methods/pca/pca_impl.hpp @@ -1,5 +1,5 @@ /** - * @file pca.cpp + * @file pca_impl.hpp * @author Ajinkya Kale * @author Ryan Curtin * @author Marcus Edel @@ -32,13 +32,13 @@ PCAType::PCAType(const bool scaleData, * @param data - Data matrix * @param transformedData - Data with PCA applied * @param eigVal - contains eigen values in a column vector - * @param coeff - PCA Loadings/Coeffs/EigenVectors + * @param eigvec - PCA Loadings/Coeffs/EigenVectors */ template void PCAType::Apply(const arma::mat& data, arma::mat& transformedData, arma::vec& eigVal, - arma::mat& coeff) + arma::mat& eigvec) { Timer::Start("pca"); @@ -49,7 +49,7 @@ void PCAType::Apply(const arma::mat& data, // Scale the data if the user ask for. ScaleData(centeredData); - decomposition.Apply(data, centeredData, transformedData, eigVal, coeff, + decomposition.Apply(data, centeredData, transformedData, eigVal, eigvec, data.n_rows); Timer::Stop("pca"); @@ -67,8 +67,8 @@ void PCAType::Apply(const arma::mat& data, arma::mat& transformedData, arma::vec& eigVal) { - arma::mat coeffs; - Apply(data, transformedData, eigVal, coeffs); + arma::mat eigvec; + Apply(data, transformedData, eigVal, eigvec); } /** @@ -95,7 +95,7 @@ double PCAType::Apply(arma::mat& data, << "be greater than the existing dimensionality of the data (" << data.n_rows << ")!" << endl; - arma::mat coeffs; + arma::mat eigvec; arma::vec eigVal; Timer::Start("pca"); @@ -107,9 +107,9 @@ double PCAType::Apply(arma::mat& data, // Scale the data if the user ask for. ScaleData(centeredData); - decomposition.Apply(data, centeredData, data, eigVal, coeffs, newDimension); + decomposition.Apply(data, centeredData, data, eigVal, eigvec, newDimension); - if (newDimension < coeffs.n_rows) + if (newDimension < eigvec.n_rows) // Drop unnecessary rows. data.shed_rows(newDimension, data.n_rows - 1); @@ -145,10 +145,10 @@ double PCAType::Apply(arma::mat& data, Log::Fatal << "PCA::Apply(): varRetained (" << varRetained << ") should be " << "less than or equal to 1." << endl; - arma::mat coeffs; + arma::mat eigvec; arma::vec eigVal; - Apply(data, data, eigVal, coeffs); + Apply(data, data, eigVal, eigvec); // Calculate the dimension we should keep. size_t newDimension = 0;