mlpack  1.0.12
sparse_autoencoder_function.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_FUNCTION_HPP
16 #define __MLPACK_METHODS_SPARSE_AUTOENCODER_SPARSE_AUTOENCODER_FUNCTION_HPP
17 
18 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace nn {
22 
29 {
30  public:
42  SparseAutoencoderFunction(const arma::mat& data,
43  const size_t visibleSize,
44  const size_t hiddenSize,
45  const double lambda = 0.0001,
46  const double beta = 3,
47  const double rho = 0.01);
48 
50  const arma::mat InitializeWeights();
51 
62  double Evaluate(const arma::mat& parameters) const;
63 
73  void Gradient(const arma::mat& parameters, arma::mat& gradient) const;
74 
81  void Sigmoid(const arma::mat& x, arma::mat& output) const
82  {
83  output = (1.0 / (1 + arma::exp(-x)));
84  }
85 
87  const arma::mat& GetInitialPoint() const { return initialPoint; }
88 
90  void VisibleSize(const size_t visible)
91  {
92  this->visibleSize = visible;
93  }
94 
96  size_t VisibleSize() const
97  {
98  return visibleSize;
99  }
100 
102  void HiddenSize(const size_t hidden)
103  {
104  this->hiddenSize = hidden;
105  }
106 
108  size_t HiddenSize() const
109  {
110  return hiddenSize;
111  }
112 
114  void Lambda(const double l)
115  {
116  this->lambda = l;
117  }
118 
120  double Lambda() const
121  {
122  return lambda;
123  }
124 
126  void Beta(const double b)
127  {
128  this->beta = b;
129  }
130 
132  double Beta() const
133  {
134  return beta;
135  }
136 
138  void Rho(const double r)
139  {
140  this->rho = r;
141  }
142 
144  double Rho() const
145  {
146  return rho;
147  }
148 
149  private:
151  const arma::mat& data;
153  arma::mat initialPoint;
155  size_t visibleSize;
157  size_t hiddenSize;
159  double lambda;
161  double beta;
163  double rho;
164 };
165 
166 }; // namespace nn
167 }; // namespace mlpack
168 
169 #endif
size_t VisibleSize() const
Gets size of the visible layer.
double lambda
L2-regularization parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
This is a class for the sparse autoencoder objective function.
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 'x'...
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.
const arma::mat & GetInitialPoint() const
Return the initial point for the optimization.
const arma::mat & data
The matrix of data points.
double Beta() const
Gets the KL divergence parameter.
size_t visibleSize
Size of the visible layer.
double Lambda() const
Gets the L2-regularization parameter.
arma::mat initialPoint
Initial parameter vector.
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 Beta(const double b)
Sets the KL divergence parameter.
double Evaluate(const arma::mat &parameters) const
Evaluates the objective function of the sparse autoencoder model using the given parameters.
void VisibleSize(const size_t visible)
Sets size of the visible layer.
double Rho() const
Gets the sparsity parameter.
void Lambda(const double l)
Sets the L2-regularization 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.