mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
79  void Sigmoid(const arma::mat& x, arma::mat& output) const
80  {
81  output = (1.0 / (1 + arma::exp(-x)));
82  }
83 
85  const arma::mat& GetInitialPoint() const { return initialPoint; }
86 
88  void VisibleSize(const size_t visible)
89  {
90  this->visibleSize = visible;
91  }
92 
94  size_t VisibleSize() const
95  {
96  return visibleSize;
97  }
98 
100  void HiddenSize(const size_t hidden)
101  {
102  this->hiddenSize = hidden;
103  }
104 
106  size_t HiddenSize() const
107  {
108  return hiddenSize;
109  }
110 
112  void Lambda(const double l)
113  {
114  this->lambda = l;
115  }
116 
118  double Lambda() const
119  {
120  return lambda;
121  }
122 
124  void Beta(const double b)
125  {
126  this->beta = b;
127  }
128 
130  double Beta() const
131  {
132  return beta;
133  }
134 
136  void Rho(const double r)
137  {
138  this->rho = r;
139  }
140 
142  double Rho() const
143  {
144  return rho;
145  }
146 
147  private:
149  const arma::mat& data;
151  arma::mat initialPoint;
153  size_t visibleSize;
155  size_t hiddenSize;
157  double lambda;
159  double beta;
161  double rho;
162 };
163 
164 } // namespace nn
165 } // namespace mlpack
166 
167 #endif
This is a class for the sparse autoencoder objective function.
The core includes that mlpack expects; standard C++ includes and Armadillo.
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;...
double Evaluate(const arma::mat &parameters) const
Evaluates the objective function of the sparse autoencoder model using the given parameters.
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
void Lambda(const double l)
Sets the L2-regularization parameter.
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.
size_t HiddenSize() const
Gets the size of the hidden layer.
void Rho(const double r)
Sets the sparsity parameter.
double Beta() const
Gets the KL divergence parameter.
void Beta(const double b)
Sets the KL divergence parameter.
void Gradient(const arma::mat &parameters, arma::mat &gradient) const
Evaluates the gradient values of the objective function given the current set of parameters.
size_t VisibleSize() const
Gets size of the visible layer.
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.
double Rho() const
Gets the sparsity parameter.