mlpack  master
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, const size_t outSize);
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  InputDataType const& InputParameter() const { return inputParameter; }
91  InputDataType& InputParameter() { return inputParameter; }
92 
94  OutputDataType const& OutputParameter() const { return outputParameter; }
96  OutputDataType& OutputParameter() { return outputParameter; }
97 
99  OutputDataType const& Delta() const { return delta; }
101  OutputDataType& Delta() { return delta; }
102 
104  OutputDataType const& Gradient() const { return gradient; }
106  OutputDataType& Gradient() { return gradient; }
107 
111  template<typename Archive>
112  void Serialize(Archive& ar, const unsigned int /* version */);
113 
114  private:
115 
117  size_t inSize;
118 
120  size_t outSize;
121 
123  OutputDataType weights;
124 
126  OutputDataType delta;
127 
129  OutputDataType gradient;
130 
132  InputDataType inputParameter;
133 
135  OutputDataType outputParameter;
136 }; // class Lookup
137 
138 } // namespace ann
139 } // namespace mlpack
140 
141 // Include implementation.
142 #include "lookup_impl.hpp"
143 
144 #endif
OutputDataType const & Gradient() const
Get the gradient.
Definition: lookup.hpp:104
OutputDataType const & Delta() const
Get the delta.
Definition: lookup.hpp:99
InputDataType & InputParameter()
Modify the input parameter.
Definition: lookup.hpp:91
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
Lookup(const size_t inSize, const size_t outSize)
Create the Lookup object using the specified number of input and output units.
InputDataType const & InputParameter() const
Get the input parameter.
Definition: lookup.hpp:89
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType delta
Locally-stored delta object.
Definition: lookup.hpp:126
OutputDataType outputParameter
Locally-stored output parameter object.
Definition: lookup.hpp:135
OutputDataType weights
Locally-stored weight object.
Definition: lookup.hpp:123
OutputDataType & Parameters()
Modify the parameters.
Definition: lookup.hpp:86
OutputDataType & Gradient()
Modify the gradient.
Definition: lookup.hpp:106
size_t inSize
Locally-stored number of input units.
Definition: lookup.hpp:117
Implementation of the Lookup class.
Definition: lookup.hpp:35
size_t outSize
Locally-stored number of output units.
Definition: lookup.hpp:120
InputDataType inputParameter
Locally-stored input parameter object.
Definition: lookup.hpp:132
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 & OutputParameter()
Modify the output parameter.
Definition: lookup.hpp:96
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: lookup.hpp:94
OutputDataType const & Parameters() const
Get the parameters.
Definition: lookup.hpp:84
OutputDataType & Delta()
Modify the delta.
Definition: lookup.hpp:101
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 gradient
Locally-stored gradient object.
Definition: lookup.hpp:129