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(CEREAL_NVP(itemMean));
105 ar(CEREAL_NVP(itemStdDev));
112 arma::vec itemStdDev;
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
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.
const arma::vec & ItemStdDev() const
Get the standard deviation row vector.
A simple Standard Scaler class.
void Transform(const MatType &input, MatType &output)
Function to scale features.
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
void serialize(Archive &ar, const uint32_t)