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:
80  template<typename OptimizerType = ens::L_BFGS>
81  SparseAutoencoder(const arma::mat& data,
82  const size_t visibleSize,
83  const size_t hiddenSize,
84  const double lambda = 0.0001,
85  const double beta = 3,
86  const double rho = 0.01,
87  OptimizerType optimizer = OptimizerType());
88 
97  void GetNewFeatures(arma::mat& data, arma::mat& features);
98 
105  void Sigmoid(const arma::mat& x, arma::mat& output) const
106  {
107  output = (1.0 / (1 + arma::exp(-x)));
108  }
109 
111  void VisibleSize(const size_t visible)
112  {
113  this->visibleSize = visible;
114  }
115 
117  size_t VisibleSize() const
118  {
119  return visibleSize;
120  }
121 
123  void HiddenSize(const size_t hidden)
124  {
125  this->hiddenSize = hidden;
126  }
127 
129  size_t HiddenSize() const
130  {
131  return hiddenSize;
132  }
133 
135  void Lambda(const double l)
136  {
137  this->lambda = l;
138  }
139 
141  double Lambda() const
142  {
143  return lambda;
144  }
145 
147  void Beta(const double b)
148  {
149  this->beta = b;
150  }
151 
153  double Beta() const
154  {
155  return beta;
156  }
157 
159  void Rho(const double r)
160  {
161  this->rho = r;
162  }
163 
165  double Rho() const
166  {
167  return rho;
168  }
169 
170  private:
172  arma::mat parameters;
174  size_t visibleSize;
176  size_t hiddenSize;
178  double lambda;
180  double beta;
182  double rho;
183 };
184 
185 } // namespace nn
186 } // namespace mlpack
187 
188 // Include implementation.
189 #include "sparse_autoencoder_impl.hpp"
190 
191 #endif
strip_type.hpp
Definition: add_to_po.hpp:21
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.