sparse_autoencoder_function.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_FUNCTION_HPP
14 #define MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_FUNCTION_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace nn {
20 
27 {
28  public:
40  SparseAutoencoderFunction(const arma::mat& data,
41  const size_t visibleSize,
42  const size_t hiddenSize,
43  const double lambda = 0.0001,
44  const double beta = 3,
45  const double rho = 0.01);
46 
48  const arma::mat InitializeWeights();
49 
60  double Evaluate(const arma::mat& parameters) const;
61 
71  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
72 
80  void Sigmoid(const arma::mat& x, arma::mat& output) const
81  {
82  output = (1.0 / (1 + arma::exp(-x)));
83  }
84 
86  const arma::mat& GetInitialPoint() const { return initialPoint; }
87 
89  void VisibleSize(const size_t visible)
90  {
91  this->visibleSize = visible;
92  }
93 
95  size_t VisibleSize() const
96  {
97  return visibleSize;
98  }
99 
101  void HiddenSize(const size_t hidden)
102  {
103  this->hiddenSize = hidden;
104  }
105 
107  size_t HiddenSize() const
108  {
109  return hiddenSize;
110  }
111 
113  void Lambda(const double l)
114  {
115  this->lambda = l;
116  }
117 
119  double Lambda() const
120  {
121  return lambda;
122  }
123 
125  void Beta(const double b)
126  {
127  this->beta = b;
128  }
129 
131  double Beta() const
132  {
133  return beta;
134  }
135 
137  void Rho(const double r)
138  {
139  this->rho = r;
140  }
141 
143  double Rho() const
144  {
145  return rho;
146  }
147 
148  private:
150  const arma::mat& data;
152  arma::mat initialPoint;
154  size_t visibleSize;
156  size_t hiddenSize;
158  double lambda;
160  double beta;
162  double rho;
163 };
164 
165 } // namespace nn
166 } // namespace mlpack
167 
168 #endif
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.
This is a class for the sparse autoencoder objective function.
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
double Evaluate(const arma::mat &parameters) const
Evaluates the objective function of the sparse autoencoder model using the given parameters.
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluates the gradient values of the objective function given the current set of parameters.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Beta() const
Gets the KL divergence parameter.
double Rho() const
Gets the sparsity parameter.
void Lambda(const double l)
Sets the L2-regularization parameter.
size_t VisibleSize() const
Gets size of the visible layer.
double Lambda() const
Gets the L2-regularization parameter.
SparseAutoencoderFunction(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 objective function with the given parameters.
void Rho(const double r)
Sets the sparsity parameter.
void Beta(const double b)
Sets the KL divergence parameter.
void HiddenSize(const size_t hidden)
Sets size of the hidden layer.
const arma::mat InitializeWeights()
Initializes the parameters of the model to suitable values.
void VisibleSize(const size_t visible)
Sets size of the visible layer.
size_t HiddenSize() const
Gets the size of the hidden layer.