mlpack 3.4.2
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
19namespace mlpack {
20namespace 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 unsigned int /* version */)
106 {
107 ar & BOOST_SERIALIZATION_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
A simple PCAWhitening class.
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.
const arma::vec & ItemMean() const
Get the mean row vector.
void Transform(const MatType &input, MatType &output)
Function for PCA whitening.
const double & Epsilon() const
Get the regularization parameter.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
A simple ZCAWhitening class.
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.
const arma::vec & ItemMean() const
Get the mean row vector.
void Transform(const MatType &input, MatType &output)
Function for ZCA whitening.
ZCAWhitening(double eps=0.00005)
A constructor to set the regularization parameter.
void serialize(Archive &ar, const unsigned int)
double Epsilon() const
Get the regularization parameter.
void InverseTransform(const MatType &input, MatType &output)
Function to retrieve original dataset.
const arma::vec & EigenValues() const
Get the eigenvalues vector.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.