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;