12#ifndef MLPACK_CORE_DATA_PCA_WHITENING_SCALE_HPP
13#define MLPACK_CORE_DATA_PCA_WHITENING_SCALE_HPP
61 throw std::runtime_error(
"Regularization parameter is not correct");
70 template<
typename MatType>
71 void Fit(
const MatType& input)
73 itemMean = arma::mean(input, 1);
76 input.each_col() - itemMean));
77 eigenValues += epsilon;
86 template<
typename MatType>
87 void Transform(
const MatType& input, MatType& output)
89 if (eigenValues.is_empty() || eigenVectors.is_empty())
91 throw std::runtime_error(
"Call Fit() before Transform(), please"
92 " refer to the documentation.");
94 output.copy_size(input);
95 output = (input.each_col() - itemMean);
96 output = arma::diagmat(1.0 / (arma::sqrt(eigenValues))) * eigenVectors.t()
106 template<
typename MatType>
109 output = arma::diagmat(arma::sqrt(eigenValues)) * inv(eigenVectors.t())
111 output = (output.each_col() + itemMean);
115 const arma::vec&
ItemMean()
const {
return itemMean; }
121 const double&
Epsilon()
const {
return epsilon; }
123 template<
typename Archive>
126 ar & BOOST_SERIALIZATION_NVP(eigenValues);
127 ar & BOOST_SERIALIZATION_NVP(eigenVectors);
128 ar & BOOST_SERIALIZATION_NVP(itemMean);
129 ar & BOOST_SERIALIZATION_NVP(epsilon);
136 arma::mat eigenVectors;
140 arma::vec eigenValues;
A simple PCAWhitening class.
void Fit(const MatType &input)
Function to fit features, to find out the min max and scale.
PCAWhitening(double eps=0.00005)
A constructor to set the regularization parameter.
const arma::mat & EigenVectors() const
Get the eigenvector.
const arma::vec & ItemMean() const
Get the mean row vector.
void Transform(const MatType &input, MatType &output)
Function for PCA whitening.
const double & Epsilon() const
Get the regularization parameter.
void serialize(Archive &ar, const unsigned int)
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
arma::Mat< eT > ColumnCovariance(const arma::Mat< eT > &A, const size_t norm_type=0)
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.