zca_whitening.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_DATA_ZCA_WHITENING_SCALE_HPP
13 #define MLPACK_CORE_DATA_ZCA_WHITENING_SCALE_HPP
14 
15 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace data {
21 
48 {
49  public:
55  ZCAWhitening(double eps = 0.00005) : pca(eps) { }
56 
62  template<typename MatType>
63  void Fit(const MatType& input)
64  {
65  pca.Fit(input);
66  }
67 
74  template<typename MatType>
75  void Transform(const MatType& input, MatType& output)
76  {
77  pca.Transform(input, output);
78  output = pca.EigenVectors() * output;
79  }
80 
87  template<typename MatType>
88  void InverseTransform(const MatType& input, MatType& output)
89  {
90  output = inv(pca.EigenVectors()) * arma::diagmat(arma::sqrt(
91  pca.EigenValues())) * inv(pca.EigenVectors().t()) * input;
92  output = (output.each_col() + pca.ItemMean());
93  }
94 
96  const arma::vec& ItemMean() const { return pca.ItemMean(); }
98  const arma::vec& EigenValues() const { return pca.EigenValues(); }
100  const arma::mat& EigenVectors() const { return pca.EigenVectors(); }
102  double Epsilon() const { return pca.Epsilon(); }
103 
104  template<typename Archive>
105  void serialize(Archive& ar, const uint32_t /* version */)
106  {
107  ar(CEREAL_NVP(pca));
108  }
109 
110  private:
111  // A pointer to PcaWhitening Class.
112  PCAWhitening pca;
113 }; // class ZCAWhitening
114 
115 } // namespace data
116 } // namespace mlpack
117 
118 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void Fit(const MatType &input)
Function to fit features, to find out the min max and scale.
const arma::mat & EigenVectors() const
Get the eigenvector.
void Transform(const MatType &input, MatType &output)
Function for ZCA whitening.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::vec & ItemMean() const
Get the mean row vector.
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.
A simple PCAWhitening class.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
double Epsilon() const
Get the regularization parameter.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
ZCAWhitening(double eps=0.00005)
A constructor to set the regularization parameter.
const double & Epsilon() const
Get the regularization parameter.
const arma::mat & EigenVectors() const
Get the eigenvector.
void Transform(const MatType &input, MatType &output)
Function for PCA whitening.
A simple ZCAWhitening class.
void serialize(Archive &ar, const uint32_t)