12 #ifndef MLPACK_CORE_DATA_STANDARD_SCALE_HPP
13 #define MLPACK_CORE_DATA_STANDARD_SCALE_HPP
55 template<
typename MatType>
56 void Fit(
const MatType& input)
58 itemMean = arma::mean(input, 1);
59 itemStdDev = arma::stddev(input, 1, 1);
61 itemStdDev.for_each([](arma::vec::elem_type& val) { val =
62 (val == 0) ? 1 : val; });
71 template<
typename MatType>
72 void Transform(
const MatType& input, MatType& output)
74 if (itemMean.is_empty() || itemStdDev.is_empty())
76 throw std::runtime_error(
"Call Fit() before Transform(), please"
77 " refer to the documentation.");
79 output.copy_size(input);
80 output = (input.each_col() - itemMean).each_col() / itemStdDev;
89 template<
typename MatType>
92 output.copy_size(input);
93 output = (input.each_col() % itemStdDev).each_col() + itemMean;
97 const arma::vec&
ItemMean()
const {
return itemMean; }
99 const arma::vec&
ItemStdDev()
const {
return itemStdDev; }
101 template<
typename Archive>
104 ar & BOOST_SERIALIZATION_NVP(itemMean);
105 ar & BOOST_SERIALIZATION_NVP(itemStdDev);
112 arma::vec itemStdDev;