mlpack 3.4.2
Loading...
Searching...
No Matches
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
23namespace mlpack {
24namespace 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
61
64
67
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
A simple MaxAbs Scaler class.
A simple Mean Normalization class.
A simple MinMax Scaler class.
A simple PCAWhitening class.
The model to save to disk.
size_t ScalerType() const
Get the Scaler type.
void Fit(const MatType &input)
ScalingModel & operator=(const ScalingModel &other)
Copy assignment operator.
ScalingModel(const ScalingModel &other)
Copy constructor.
ScalingModel(const int minvalue=0, const int maxvalue=1, double epsilonvalue=0.00005)
Create an object.
void Transform(const MatType &input, MatType &output)
Transform to scale features.
~ScalingModel()
Clean up memory.
size_t & ScalerType()
Modify the Scaler type.
ScalingModel(ScalingModel &&other)
Move constructor.
void serialize(Archive &ar, const unsigned int)
Serialize the model.
void InverseTransform(const MatType &input, MatType &output)
A simple Standard Scaler class.
A simple ZCAWhitening class.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
Linear algebra utility functions, generally performed on matrices or vectors.