12 #ifndef MLPACK_CORE_DATA_PCA_WHITENING_SCALE_HPP 13 #define MLPACK_CORE_DATA_PCA_WHITENING_SCALE_HPP 60 throw std::runtime_error(
"Regularization parameter is not correct");
69 template<
typename MatType>
70 void Fit(
const MatType& input)
72 itemMean = arma::mean(input, 1);
75 input.each_col() - itemMean));
76 eigenValues += epsilon;
85 template<
typename MatType>
86 void Transform(
const MatType& input, MatType& output)
88 if (eigenValues.is_empty() || eigenVectors.is_empty())
90 throw std::runtime_error(
"Call Fit() before Transform(), please" 91 " refer to the documentation.");
93 output.copy_size(input);
94 output = (input.each_col() - itemMean);
95 output = arma::diagmat(1.0 / (arma::sqrt(eigenValues))) * eigenVectors.t()
105 template<
typename MatType>
108 output = arma::diagmat(arma::sqrt(eigenValues)) * inv(eigenVectors.t())
110 output = (output.each_col() + itemMean);
114 const arma::vec&
ItemMean()
const {
return itemMean; }
120 const double&
Epsilon()
const {
return epsilon; }
122 template<
typename Archive>
125 ar & BOOST_SERIALIZATION_NVP(eigenValues);
126 ar & BOOST_SERIALIZATION_NVP(eigenVectors);
127 ar & BOOST_SERIALIZATION_NVP(itemMean);
128 ar & BOOST_SERIALIZATION_NVP(epsilon);
135 arma::mat eigenVectors;
139 arma::vec eigenValues;
The core includes that mlpack expects; standard C++ includes and Armadillo.
arma::Mat< eT > ColumnCovariance(const arma::Mat< eT > &A, const size_t norm_type=0)
const arma::vec & ItemMean() const
Get the mean row vector.
void Fit(const MatType &input)
Function to fit features, to find out the min max and scale.
A simple PCAWhitening class.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
void serialize(Archive &ar, const unsigned int)
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
const double & Epsilon() const
Get the regularization parameter.
PCAWhitening(double eps=0.00005)
A constructor to set the regularization parameter.
const arma::mat & EigenVectors() const
Get the eigenvector.
void Transform(const MatType &input, MatType &output)
Function for PCA whitening.