mlpack
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
const arma::vec & ItemMean() const
Get the mean row vector.
Definition: zca_whitening.hpp:96
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
const arma::vec & ItemMean() const
Get the mean row vector.
Definition: pca_whitening.hpp:115
const double & Epsilon() const
Get the regularization parameter.
Definition: pca_whitening.hpp:121
void Fit(const MatType &input)
Function to fit features, to find out the min max and scale.
Definition: zca_whitening.hpp:63
The core includes that mlpack expects; standard C++ includes and Armadillo.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
Definition: pca_whitening.hpp:117
A simple PCAWhitening class.
Definition: pca_whitening.hpp:47
void Transform(const MatType &input, MatType &output)
Function for ZCA whitening.
Definition: zca_whitening.hpp:75
void Fit(const MatType &input)
Function to fit features, to find out the min max and scale.
Definition: pca_whitening.hpp:71
ZCAWhitening(double eps=0.00005)
A constructor to set the regularization parameter.
Definition: zca_whitening.hpp:55
double Epsilon() const
Get the regularization parameter.
Definition: zca_whitening.hpp:102
void Transform(const MatType &input, MatType &output)
Function for PCA whitening.
Definition: pca_whitening.hpp:87
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
Definition: zca_whitening.hpp:88
const arma::mat & EigenVectors() const
Get the eigenvector.
Definition: pca_whitening.hpp:119
const arma::vec & EigenValues() const
Get the eigenvalues vector.
Definition: zca_whitening.hpp:98
A simple ZCAWhitening class.
Definition: zca_whitening.hpp:47
const arma::mat & EigenVectors() const
Get the eigenvector.
Definition: zca_whitening.hpp:100