lookup.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_LOOKUP_HPP
14 #define MLPACK_METHODS_ANN_LAYER_LOOKUP_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 namespace mlpack {
20 namespace ann {
21 
31 template <
32  typename InputDataType = arma::mat,
33  typename OutputDataType = arma::mat
34 >
35 class Lookup
36 {
37  public:
45  Lookup(const size_t inSize = 0, const size_t outSize = 0);
46 
54  template<typename eT>
55  void Forward(const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
56 
66  template<typename eT>
67  void Backward(const arma::Mat<eT>&& /* input */,
68  const arma::Mat<eT>&& gy,
69  arma::Mat<eT>&& g);
70 
71  /*
72  * Calculate the gradient using the output delta and the input activation.
73  *
74  * @param input The input parameter used for calculating the gradient.
75  * @param error The calculated error.
76  * @param gradient The calculated gradient.
77  */
78  template<typename eT>
79  void Gradient(const arma::Mat<eT>&& input,
80  arma::Mat<eT>&& error,
81  arma::Mat<eT>&& gradient);
82 
84  OutputDataType const& Parameters() const { return weights; }
86  OutputDataType& Parameters() { return weights; }
87 
89  OutputDataType const& OutputParameter() const { return outputParameter; }
91  OutputDataType& OutputParameter() { return outputParameter; }
92 
94  OutputDataType const& Delta() const { return delta; }
96  OutputDataType& Delta() { return delta; }
97 
99  OutputDataType const& Gradient() const { return gradient; }
101  OutputDataType& Gradient() { return gradient; }
102 
106  template<typename Archive>
107  void serialize(Archive& ar, const unsigned int /* version */);
108 
109  private:
111  size_t inSize;
112 
114  size_t outSize;
115 
117  OutputDataType weights;
118 
120  OutputDataType delta;
121 
123  OutputDataType gradient;
124 
126  OutputDataType outputParameter;
127 }; // class Lookup
128 
129 // Alias for using as embedding layer.
130 template<typename MatType = arma::mat>
132 
133 } // namespace ann
134 } // namespace mlpack
135 
136 // Include implementation.
137 #include "lookup_impl.hpp"
138 
139 #endif
.hpp
Definition: add_to_po.hpp:21
void Forward(const arma::Mat< eT > &&input, arma::Mat< eT > &&output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
OutputDataType const & Gradient() const
Get the gradient.
Definition: lookup.hpp:99
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Parameters()
Modify the parameters.
Definition: lookup.hpp:86
Lookup(const size_t inSize=0, const size_t outSize=0)
Create the Lookup object using the specified number of input and output units.
OutputDataType const & Delta() const
Get the delta.
Definition: lookup.hpp:94
Implementation of the Lookup class.
Definition: lookup.hpp:35
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: lookup.hpp:91
void Backward(const arma::Mat< eT > &&, const arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
OutputDataType const & Parameters() const
Get the parameters.
Definition: lookup.hpp:84
OutputDataType & Gradient()
Modify the gradient.
Definition: lookup.hpp:101
OutputDataType & Delta()
Modify the delta.
Definition: lookup.hpp:96
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: lookup.hpp:89