[mlpack-svn] r12134 - in mlpack/trunk/src/mlpack/methods: kernel_pca pca
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Mar 30 16:40:56 EDT 2012
Author: mamidon
Date: 2012-03-30 16:40:55 -0400 (Fri, 30 Mar 2012)
New Revision: 12134
Modified:
mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca.hpp
mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_impl.hpp
mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_main.cpp
mlpack/trunk/src/mlpack/methods/pca/pca.cpp
mlpack/trunk/src/mlpack/methods/pca/pca.hpp
mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp
Log:
Modified PCA/Kernel PCA interfaces to remove redundant centering option.
Modified: mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca.hpp 2012-03-30 19:24:27 UTC (rev 12133)
+++ mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca.hpp 2012-03-30 20:40:55 UTC (rev 12134)
@@ -19,7 +19,6 @@
{
public:
KernelPCA(const KernelType kernel = KernelType(),
- const bool centerData = true,
const bool scaleData = false);
/**
@@ -63,13 +62,6 @@
//! Modify the kernel.
KernelType& Kernel() { return kernel; }
- //! Return whether or not this KernelPCA object will center the data when
- //! kernel PCA is performed.
- bool CenterData() const { return centerData; }
- //! Modify whether or not this KernelPCA object will center the data when
- //! kernel PCA is performed.
- bool& CenterData() { return centerData; }
-
//! Return whether or not this KernelPCA object will scale (by standard
//! deviation) the data when kernel PCA is performed.
bool ScaleData() const { return scaleData; }
@@ -80,8 +72,6 @@
private:
//! The instantiated kernel.
KernelType kernel;
- //! If true, the data will be centered when Apply() is run.
- bool centerData;
//! If true, the data will be scaled (by standard deviation) when Apply() is
//! run.
bool scaleData;
Modified: mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_impl.hpp 2012-03-30 19:24:27 UTC (rev 12133)
+++ mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_impl.hpp 2012-03-30 20:40:55 UTC (rev 12134)
@@ -18,10 +18,8 @@
template <typename KernelType>
KernelPCA<KernelType>::KernelPCA(const KernelType kernel,
- const bool centerData,
const bool scaleData) :
kernel(kernel),
- centerData(centerData),
scaleData(scaleData)
{ }
Modified: mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_main.cpp 2012-03-30 19:24:27 UTC (rev 12133)
+++ mlpack/trunk/src/mlpack/methods/kernel_pca/kernel_pca_main.cpp 2012-03-30 20:40:55 UTC (rev 12134)
@@ -65,8 +65,6 @@
PARAM_FLAG("scale", "If set, the data will be scaled before performing KPCA "
"such that the variance of each feature is 1.", "s");
-PARAM_FLAG("nocenter", "If set, the data will NOT be centered before performing"
- " KPCA.", "N");
PARAM_DOUBLE("kernel_scale", "Scale, for 'hyptan' kernel.", "S", 1.0);
PARAM_DOUBLE("offset", "Offset, for 'hyptan' and 'polynomial' kernels.", "O",
@@ -104,11 +102,10 @@
const string kernelType = CLI::GetParam<string>("kernel");
const bool scaleData = CLI::HasParam("scale");
- const bool centerData = !CLI::HasParam("nocenter");
if (kernelType == "linear")
{
- KernelPCA<LinearKernel> kpca(LinearKernel(), centerData, scaleData);
+ KernelPCA<LinearKernel> kpca(LinearKernel(), scaleData);
kpca.Apply(dataset, newDim);
}
else if (kernelType == "gaussian")
@@ -116,7 +113,7 @@
const double bandwidth = CLI::GetParam<double>("bandwidth");
GaussianKernel kernel(bandwidth);
- KernelPCA<GaussianKernel> kpca(kernel, centerData, scaleData);
+ KernelPCA<GaussianKernel> kpca(kernel, scaleData);
kpca.Apply(dataset, newDim);
}
else if (kernelType == "polynomial")
@@ -125,7 +122,7 @@
const double offset = CLI::GetParam<double>("offset");
PolynomialKernel kernel(offset, degree);
- KernelPCA<PolynomialKernel> kpca(kernel, centerData, scaleData);
+ KernelPCA<PolynomialKernel> kpca(kernel, scaleData);
kpca.Apply(dataset, newDim);
}
else if (kernelType == "hyptan")
@@ -134,7 +131,7 @@
const double offset = CLI::GetParam<double>("offset");
HyperbolicTangentKernel kernel(scale, offset);
- KernelPCA<HyperbolicTangentKernel> kpca(kernel, centerData, scaleData);
+ KernelPCA<HyperbolicTangentKernel> kpca(kernel, scaleData);
kpca.Apply(dataset, newDim);
}
else if (kernelType == "laplacian")
@@ -142,12 +139,12 @@
const double bandwidth = CLI::GetParam<double>("bandwidth");
LaplacianKernel kernel(bandwidth);
- KernelPCA<LaplacianKernel> kpca(kernel, centerData, scaleData);
+ KernelPCA<LaplacianKernel> kpca(kernel, scaleData);
kpca.Apply(dataset, newDim);
}
else if (kernelType == "cosine")
{
- KernelPCA<CosineDistance> kpca(CosineDistance(), centerData, scaleData);
+ KernelPCA<CosineDistance> kpca(CosineDistance(), scaleData);
kpca.Apply(dataset, newDim);
}
else
Modified: mlpack/trunk/src/mlpack/methods/pca/pca.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/pca/pca.cpp 2012-03-30 19:24:27 UTC (rev 12133)
+++ mlpack/trunk/src/mlpack/methods/pca/pca.cpp 2012-03-30 20:40:55 UTC (rev 12134)
@@ -13,8 +13,7 @@
namespace mlpack {
namespace pca {
-PCA::PCA(const bool centerData, const bool scaleData) :
- centerData(centerData),
+PCA::PCA(const bool scaleData) :
scaleData(scaleData)
{ }
Modified: mlpack/trunk/src/mlpack/methods/pca/pca.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/pca/pca.hpp 2012-03-30 19:24:27 UTC (rev 12133)
+++ mlpack/trunk/src/mlpack/methods/pca/pca.hpp 2012-03-30 20:40:55 UTC (rev 12134)
@@ -16,7 +16,7 @@
class PCA
{
public:
- PCA(const bool centerData = true, const bool scaleData = false);
+ PCA(const bool scaleData = false);
/**
* Apply Principal Component Analysis to the provided data set.
@@ -56,12 +56,6 @@
*/
~PCA();
- //! Get whether or not this PCA object will center the data.
- bool CenterData() const { return centerData; }
- //! Modify whether or not this PCA object will center the data when PCA is
- //! is performed.
- bool& CenterData() { return centerData; }
-
//! Get whether or not this PCA object will scale (by standard deviation) the
//! data when PCA is performed.
bool ScaleData() const { return scaleData; }
@@ -70,7 +64,6 @@
bool& ScaleData() { return scaleData; }
private:
- bool centerData;
bool scaleData;
}; // class PCA
Modified: mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp 2012-03-30 19:24:27 UTC (rev 12133)
+++ mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp 2012-03-30 20:40:55 UTC (rev 12134)
@@ -27,8 +27,6 @@
PARAM_FLAG("scale", "If set, the data will be scaled before running PCA, such "
"that the variance of each feature is 1.", "s");
-PARAM_FLAG("nocenter", "If set, the data will NOT be centered before performing"
- " PCA.", "N");
int main(int argc, char** argv)
{
@@ -56,10 +54,9 @@
// Get the options for running PCA.
const size_t scale = CLI::HasParam("scale");
- const size_t center = !CLI::HasParam("nocenter");
// Perform PCA.
- PCA p(center, scale);
+ PCA p(scale);
Log::Info << "Performing PCA on dataset..." << endl;
p.Apply(dataset, newDimension);
More information about the mlpack-svn
mailing list