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;