sparse_autoencoder.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_HPP
13 #define MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 #include <ensmallen.hpp>
17 
19 
20 namespace mlpack {
21 namespace nn {
22 
64 {
65  public:
81  template<typename OptimizerType = ens::L_BFGS>
82  SparseAutoencoder(const arma::mat& data,
83  const size_t visibleSize,
84  const size_t hiddenSize,
85  const double lambda = 0.0001,
86  const double beta = 3,
87  const double rho = 0.01,
88  OptimizerType optimizer = OptimizerType());
89 
108  template<typename OptimizerType, typename... CallbackTypes>
109  SparseAutoencoder(const arma::mat& data,
110  const size_t visibleSize,
111  const size_t hiddenSize,
112  const double lambda,
113  const double beta,
114  const double rho ,
115  OptimizerType optimizer,
116  CallbackTypes&&... callbacks);
117 
126  void GetNewFeatures(arma::mat& data, arma::mat& features);
127 
135  void Sigmoid(const arma::mat& x, arma::mat& output) const
136  {
137  output = (1.0 / (1 + arma::exp(-x)));
138  }
139 
141  void VisibleSize(const size_t visible)
142  {
143  this->visibleSize = visible;
144  }
145 
147  size_t VisibleSize() const
148  {
149  return visibleSize;
150  }
151 
153  void HiddenSize(const size_t hidden)
154  {
155  this->hiddenSize = hidden;
156  }
157 
159  size_t HiddenSize() const
160  {
161  return hiddenSize;
162  }
163 
165  void Lambda(const double l)
166  {
167  this->lambda = l;
168  }
169 
171  double Lambda() const
172  {
173  return lambda;
174  }
175 
177  void Beta(const double b)
178  {
179  this->beta = b;
180  }
181 
183  double Beta() const
184  {
185  return beta;
186  }
187 
189  void Rho(const double r)
190  {
191  this->rho = r;
192  }
193 
195  double Rho() const
196  {
197  return rho;
198  }
199 
200  private:
202  arma::mat parameters;
204  size_t visibleSize;
206  size_t hiddenSize;
208  double lambda;
210  double beta;
212  double rho;
213 };
214 
215 } // namespace nn
216 } // namespace mlpack
217 
218 // Include implementation.
219 #include "sparse_autoencoder_impl.hpp"
220 
221 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
size_t VisibleSize() const
Gets size of the visible layer.
void GetNewFeatures(arma::mat &data, arma::mat &features)
Transforms the provided data into the representation learned by the sparse autoencoder.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Rho(const double r)
Sets the sparsity parameter.
size_t HiddenSize() const
Gets the size of the hidden layer.
double Lambda() const
Gets the L2-regularization parameter.
A sparse autoencoder is a neural network whose aim to learn compressed representations of the data...
double Rho() const
Gets the sparsity parameter.
SparseAutoencoder(const arma::mat &data, const size_t visibleSize, const size_t hiddenSize, const double lambda=0.0001, const double beta=3, const double rho=0.01, OptimizerType optimizer=OptimizerType())
Construct the sparse autoencoder model with the given training data.
void Lambda(const double l)
Sets the L2-regularization parameter.
void Beta(const double b)
Sets the KL divergence parameter.
double Beta() const
Gets the KL divergence parameter.
void HiddenSize(const size_t hidden)
Sets size of the hidden layer.
void Sigmoid(const arma::mat &x, arma::mat &output) const
Returns the elementwise sigmoid of the passed matrix, where the sigmoid function of a real number &#39;x&#39;...
void VisibleSize(const size_t visible)
Sets size of the visible layer.