scaling_model.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_DATA_SCALING_MODEL_HPP
13 #define MLPACK_CORE_DATA_SCALING_MODEL_HPP
14 
15 #include <mlpack/core.hpp>
22 
23 namespace mlpack {
24 namespace data {
25 
30 {
31  public:
33  {
40  };
41 
42  private:
43  size_t scalerType;
44  data::MinMaxScaler* minmaxscale;
45  data::MaxAbsScaler* maxabsscale;
46  data::MeanNormalization* meanscale;
47  data::StandardScaler* standardscale;
48  data::PCAWhitening* pcascale;
49  data::ZCAWhitening* zcascale;
50  int minValue;
51  int maxValue;
52  double epsilon;
53 
54  public:
56  ScalingModel(const int minvalue = 0, const int maxvalue = 1,
57  double epsilonvalue = 0.00005);
58 
60  ScalingModel(const ScalingModel& other);
61 
63  ScalingModel(ScalingModel&& other);
64 
66  ScalingModel& operator=(const ScalingModel& other);
67 
69  ~ScalingModel();
70 
72  size_t ScalerType() const { return scalerType; }
74  size_t& ScalerType() { return scalerType; }
75 
77  template<typename MatType>
78  void Transform(const MatType& input, MatType& output);
79 
80  // Fit to intialize the scaling parameter.
81  template<typename MatType>
82  void Fit(const MatType& input);
83 
84  // Scale back the dataset to their original values.
85  template<typename MatType>
86  void InverseTransform(const MatType& input, MatType& output);
87 
89  template<typename Archive>
90  void serialize(Archive& ar, const unsigned int /* version */)
91  {
92  if (Archive::is_loading::value)
93  {
94  if (minmaxscale)
95  delete minmaxscale;
96  if (maxabsscale)
97  delete maxabsscale;
98  if (meanscale)
99  delete meanscale;
100  if (standardscale)
101  delete standardscale;
102  if (pcascale)
103  delete pcascale;
104  if (zcascale)
105  delete zcascale;
106 
107  minmaxscale = NULL;
108  maxabsscale = NULL;
109  standardscale = NULL;
110  meanscale = NULL;
111  pcascale = NULL;
112  zcascale = NULL;
113  }
114 
115  ar & BOOST_SERIALIZATION_NVP(scalerType);
116  ar & BOOST_SERIALIZATION_NVP(epsilon);
117  ar & BOOST_SERIALIZATION_NVP(minValue);
118  ar & BOOST_SERIALIZATION_NVP(maxValue);
119  if (scalerType == ScalerTypes::MIN_MAX_SCALER)
120  ar & BOOST_SERIALIZATION_NVP(minmaxscale);
121  else if (scalerType == ScalerTypes::MEAN_NORMALIZATION)
122  ar & BOOST_SERIALIZATION_NVP(meanscale);
123  else if (scalerType == ScalerTypes::MAX_ABS_SCALER)
124  ar & BOOST_SERIALIZATION_NVP(maxabsscale);
125  else if (scalerType == ScalerTypes::STANDARD_SCALER)
126  ar & BOOST_SERIALIZATION_NVP(standardscale);
127  else if (scalerType == ScalerTypes::PCA_WHITENING)
128  ar & BOOST_SERIALIZATION_NVP(pcascale);
129  else if (scalerType == ScalerTypes::ZCA_WHITENING)
130  ar & BOOST_SERIALIZATION_NVP(zcascale);
131  }
132 };
133 
134 } // namespace data
135 } // namespace mlpack
136 
137 // Include implementation.
138 #include "scaling_model_impl.hpp"
139 
140 #endif
size_t & ScalerType()
Modify the Scaler type.
ScalingModel(const int minvalue=0, const int maxvalue=1, double epsilonvalue=0.00005)
Create an object.
.hpp
Definition: add_to_po.hpp:21
void Transform(const MatType &input, MatType &output)
Transform to scale features.
A simple Mean Normalization class.
void Fit(const MatType &input)
A simple PCAWhitening class.
~ScalingModel()
Clean up memory.
The model to save to disk.
A simple MaxAbs Scaler class.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
ScalingModel & operator=(const ScalingModel &other)
Copy assignment operator.
A simple Standard Scaler class.
size_t ScalerType() const
Get the Scaler type.
void InverseTransform(const MatType &input, MatType &output)
A simple MinMax Scaler class.
A simple ZCAWhitening class.
void serialize(Archive &ar, const unsigned int)
Serialize the model.