12 #ifndef MLPACK_CORE_DATA_MEAN_NORMALIZATION_HPP 13 #define MLPACK_CORE_DATA_MEAN_NORMALIZATION_HPP 54 template<
typename MatType>
55 void Fit(
const MatType& input)
57 itemMean = arma::mean(input, 1);
58 itemMin = arma::min(input, 1);
59 itemMax = arma::max(input, 1);
60 scale = itemMax - itemMin;
62 scale.for_each([](arma::vec::elem_type& val) { val =
63 (val == 0) ? 1 : val; });
72 template<
typename MatType>
73 void Transform(
const MatType& input, MatType& output)
75 if (itemMean.is_empty() || scale.is_empty())
77 throw std::runtime_error(
"Call Fit() before Transform(), please" 78 " refer to the documentation.");
80 output.copy_size(input);
81 output = (input.each_col() - itemMean).each_col() / scale;
90 template<
typename MatType>
93 output.copy_size(input);
94 output = (input.each_col() % scale).each_col() + itemMean;
98 const arma::vec&
ItemMean()
const {
return itemMean; }
100 const arma::vec&
ItemMin()
const {
return itemMin; }
102 const arma::vec&
ItemMax()
const {
return itemMax; }
104 const arma::vec&
Scale()
const {
return scale; }
106 template<
typename Archive>
109 ar(CEREAL_NVP(itemMin));
110 ar(CEREAL_NVP(itemMax));
111 ar(CEREAL_NVP(scale));
112 ar(CEREAL_NVP(itemMean));
Linear algebra utility functions, generally performed on matrices or vectors.
const arma::vec & Scale() const
Get the Scale row vector.
const arma::vec & ItemMax() const
Get the Max row vector.
The core includes that mlpack expects; standard C++ includes and Armadillo.
A simple Mean Normalization class.
const arma::vec & ItemMin() const
Get the Min row vector.
void Transform(const MatType &input, MatType &output)
Function to scale features.
void Fit(const MatType &input)
Function to fit features, to find out the min max and scale.
void serialize(Archive &ar, const uint32_t)
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
const arma::vec & ItemMean() const
Get the Mean row vector.