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)
56  {
57  pca = new data::PCAWhitening(eps);
58  }
59 
65  template<typename MatType>
66  void Fit(const MatType& input)
67  {
68  pca->Fit(input);
69  }
70 
77  template<typename MatType>
78  void Transform(const MatType& input, MatType& output)
79  {
80  pca->Transform(input, output);
81  output = pca->EigenVectors() * output;
82  }
83 
90  template<typename MatType>
91  void InverseTransform(const MatType& input, MatType& output)
92  {
93  output = inv(pca->EigenVectors()) * arma::diagmat(arma::sqrt(
94  pca->EigenValues())) * inv(pca->EigenVectors().t()) * input;
95  output = (output.each_col() + pca->ItemMean());
96  }
97 
99  const arma::vec& ItemMean() const { return pca->ItemMean(); }
101  const arma::vec& EigenValues() const { return pca->EigenValues(); }
103  const arma::mat& EigenVectors() const { return pca->EigenVectors(); }
105  double Epsilon() const { return pca->Epsilon(); }
106 
107  template<typename Archive>
108  void serialize(Archive& ar, const unsigned int /* version */)
109  {
110  ar & BOOST_SERIALIZATION_NVP(pca);
111  }
112 
113  private:
114  // A pointer to PcaWhitening Class.
115  PCAWhitening* pca;
116 }; // class ZCAWhitening
117 
118 } // namespace data
119 } // namespace mlpack
120 
121 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
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.
void serialize(Archive &ar, const unsigned int)
const arma::mat & EigenVectors() const
Get the eigenvector.
void Transform(const MatType &input, MatType &output)
Function for PCA whitening.
A simple ZCAWhitening class.