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 
70 
72  ~ScalingModel();
73 
75  size_t ScalerType() const { return scalerType; }
77  size_t& ScalerType() { return scalerType; }
78 
80  template<typename MatType>
81  void Transform(const MatType& input, MatType& output);
82 
83  // Fit to intialize the scaling parameter.
84  template<typename MatType>
85  void Fit(const MatType& input);
86 
87  // Scale back the dataset to their original values.
88  template<typename MatType>
89  void InverseTransform(const MatType& input, MatType& output);
90 
92  template<typename Archive>
93  void serialize(Archive& ar, const uint32_t /* version */)
94  {
95  if (cereal::is_loading<Archive>())
96  {
97  if (minmaxscale)
98  delete minmaxscale;
99  if (maxabsscale)
100  delete maxabsscale;
101  if (meanscale)
102  delete meanscale;
103  if (standardscale)
104  delete standardscale;
105  if (pcascale)
106  delete pcascale;
107  if (zcascale)
108  delete zcascale;
109 
110  minmaxscale = NULL;
111  maxabsscale = NULL;
112  standardscale = NULL;
113  meanscale = NULL;
114  pcascale = NULL;
115  zcascale = NULL;
116  }
117 
118  ar(CEREAL_NVP(scalerType));
119  ar(CEREAL_NVP(epsilon));
120  ar(CEREAL_NVP(minValue));
121  ar(CEREAL_NVP(maxValue));
122  if (scalerType == ScalerTypes::MIN_MAX_SCALER)
123  ar(CEREAL_POINTER(minmaxscale));
124  else if (scalerType == ScalerTypes::MEAN_NORMALIZATION)
125  ar(CEREAL_POINTER(meanscale));
126  else if (scalerType == ScalerTypes::MAX_ABS_SCALER)
127  ar(CEREAL_POINTER(maxabsscale));
128  else if (scalerType == ScalerTypes::STANDARD_SCALER)
129  ar(CEREAL_POINTER(standardscale));
130  else if (scalerType == ScalerTypes::PCA_WHITENING)
131  ar(CEREAL_POINTER(pcascale));
132  else if (scalerType == ScalerTypes::ZCA_WHITENING)
133  ar(CEREAL_POINTER(zcascale));
134  }
135 };
136 
137 } // namespace data
138 } // namespace mlpack
139 
140 // Include implementation.
141 #include "scaling_model_impl.hpp"
142 
143 #endif
size_t & ScalerType()
Modify the Scaler type.
ScalingModel(const int minvalue=0, const int maxvalue=1, double epsilonvalue=0.00005)
Create an object.
Linear algebra utility functions, generally performed on matrices or vectors.
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)
#define CEREAL_POINTER(T)
Cereal does not support the serialization of raw pointer.
void serialize(Archive &ar, const uint32_t)
Serialize the model.
A simple MinMax Scaler class.
A simple ZCAWhitening class.