mlpack  2.0.1
sparse_autoencoder.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_HPP
15 #define __MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_HPP
16 
17 #include <mlpack/core.hpp>
19 
21 
22 namespace mlpack {
23 namespace nn {
24 
67 template<
68  template<typename> class OptimizerType = mlpack::optimization::L_BFGS
69 >
71 {
72  public:
86  SparseAutoencoder(const arma::mat& data,
87  const size_t visibleSize,
88  const size_t hiddenSize,
89  const double lambda = 0.0001,
90  const double beta = 3,
91  const double rho = 0.01);
92 
102  SparseAutoencoder(OptimizerType<SparseAutoencoderFunction>& optimizer);
103 
112  void GetNewFeatures(arma::mat& data, arma::mat& features);
113 
120  void Sigmoid(const arma::mat& x, arma::mat& output) const
121  {
122  output = (1.0 / (1 + arma::exp(-x)));
123  }
124 
126  void VisibleSize(const size_t visible)
127  {
128  this->visibleSize = visible;
129  }
130 
132  size_t VisibleSize() const
133  {
134  return visibleSize;
135  }
136 
138  void HiddenSize(const size_t hidden)
139  {
140  this->hiddenSize = hidden;
141  }
142 
144  size_t HiddenSize() const
145  {
146  return hiddenSize;
147  }
148 
150  void Lambda(const double l)
151  {
152  this->lambda = l;
153  }
154 
156  double Lambda() const
157  {
158  return lambda;
159  }
160 
162  void Beta(const double b)
163  {
164  this->beta = b;
165  }
166 
168  double Beta() const
169  {
170  return beta;
171  }
172 
174  void Rho(const double r)
175  {
176  this->rho = r;
177  }
178 
180  double Rho() const
181  {
182  return rho;
183  }
184 
185  private:
187  arma::mat parameters;
189  size_t visibleSize;
191  size_t hiddenSize;
193  double lambda;
195  double beta;
197  double rho;
198 };
199 
200 } // namespace nn
201 } // namespace mlpack
202 
203 // Include implementation.
204 #include "sparse_autoencoder_impl.hpp"
205 
206 #endif
double Lambda() const
Gets the L2-regularization parameter.
void GetNewFeatures(arma::mat &data, arma::mat &features)
Transforms the provided data into the representation learned by the sparse autoencoder.
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;...
Linear algebra utility functions, generally performed on matrices or vectors.
void VisibleSize(const size_t visible)
Sets size of the visible layer.
double Rho() const
Gets the sparsity parameter.
arma::mat parameters
Parameters after optimization.
void Rho(const double r)
Sets the sparsity parameter.
A sparse autoencoder is a neural network whose aim to learn compressed representations of the data...
double lambda
L2-regularization parameter.
void HiddenSize(const size_t hidden)
Sets size of the hidden layer.
size_t visibleSize
Size of the visible layer.
void Lambda(const double l)
Sets the L2-regularization parameter.
size_t hiddenSize
Size of the hidden layer.
size_t VisibleSize() const
Gets size of the visible layer.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
double rho
Sparsity parameter.
double Beta() const
Gets the KL divergence parameter.
double beta
KL divergence parameter.
void Beta(const double b)
Sets the KL divergence parameter.
size_t HiddenSize() const
Gets the size of the hidden layer.
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)
Construct the sparse autoencoder model with the given training data.
The generic L-BFGS optimizer, which uses a back-tracking line search algorithm to minimize a function...
Definition: lbfgs.hpp:36