linear3d.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_LINEAR3D_HPP
14 #define MLPACK_METHODS_ANN_LAYER_LINEAR3D_HPP
15 
16 #include <mlpack/prereqs.hpp>
19 
20 namespace mlpack {
21 namespace ann {
22 
35 template <
36  typename InputDataType = arma::mat,
37  typename OutputDataType = arma::mat,
38  typename RegularizerType = NoRegularizer
39 >
40 class Linear3D
41 {
42  public:
44  Linear3D();
45 
53  Linear3D(const size_t inSize,
54  const size_t outSize,
55  RegularizerType regularizer = RegularizerType());
56 
58  Linear3D(const Linear3D& layer);
59 
61  Linear3D(Linear3D&&);
62 
64  Linear3D& operator=(const Linear3D& layer);
65 
67  Linear3D& operator=(Linear3D&& layer);
68 
69  /*
70  * Reset the layer parameter.
71  */
72  void Reset();
73 
81  template<typename eT>
82  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
83 
93  template<typename eT>
94  void Backward(const arma::Mat<eT>& /* input */,
95  const arma::Mat<eT>& gy,
96  arma::Mat<eT>& g);
97 
98  /*
99  * Calculate the gradient using the output delta and the input activation.
100  *
101  * @param input The input parameter used for calculating the gradient.
102  * @param error The calculated error.
103  * @param gradient The calculated gradient.
104  */
105  template<typename eT>
106  void Gradient(const arma::Mat<eT>& input,
107  const arma::Mat<eT>& error,
108  arma::Mat<eT>& gradient);
109 
111  OutputDataType const& Parameters() const { return weights; }
113  OutputDataType& Parameters() { return weights; }
114 
116  InputDataType const& InputParameter() const { return inputParameter; }
118  InputDataType& InputParameter() { return inputParameter; }
119 
121  OutputDataType const& OutputParameter() const { return outputParameter; }
123  OutputDataType& OutputParameter() { return outputParameter; }
124 
126  OutputDataType const& Delta() const { return delta; }
128  OutputDataType& Delta() { return delta; }
129 
131  size_t InputSize() const { return inSize; }
132 
134  size_t OutputSize() const { return outSize; }
135 
137  OutputDataType const& Gradient() const { return gradient; }
139  OutputDataType& Gradient() { return gradient; }
140 
142  OutputDataType const& Weight() const { return weight; }
144  OutputDataType& Weight() { return weight; }
145 
147  OutputDataType const& Bias() const { return bias; }
149  OutputDataType& Bias() { return bias; }
150 
152  size_t InputShape() const
153  {
154  return inSize;
155  }
156 
160  template<typename Archive>
161  void serialize(Archive& ar, const uint32_t /* version */);
162 
163  private:
165  size_t inSize;
166 
168  size_t outSize;
169 
171  OutputDataType weights;
172 
174  OutputDataType weight;
175 
177  OutputDataType bias;
178 
180  OutputDataType delta;
181 
183  OutputDataType gradient;
184 
186  InputDataType inputParameter;
187 
189  OutputDataType outputParameter;
190 
192  RegularizerType regularizer;
193 }; // class Linear
194 
195 } // namespace ann
196 } // namespace mlpack
197 
198 // Include implementation.
199 #include "linear3d_impl.hpp"
200 
201 #endif
OutputDataType const & Gradient() const
Get the gradient.
Definition: linear3d.hpp:137
OutputDataType & Weight()
Modify the weight of the layer.
Definition: linear3d.hpp:144
Linear algebra utility functions, generally performed on matrices or vectors.
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: linear3d.hpp:121
OutputDataType const & Parameters() const
Get the parameters.
Definition: linear3d.hpp:111
Linear3D()
Create the Linear3D object.
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: linear3d.hpp:123
size_t InputSize() const
Get the input size.
Definition: linear3d.hpp:131
OutputDataType const & Delta() const
Get the delta.
Definition: linear3d.hpp:126
OutputDataType const & Weight() const
Get the weight of the layer.
Definition: linear3d.hpp:142
InputDataType const & InputParameter() const
Get the input parameter.
Definition: linear3d.hpp:116
size_t OutputSize() const
Get the output size.
Definition: linear3d.hpp:134
OutputDataType & Bias()
Modify the bias weights of the layer.
Definition: linear3d.hpp:149
size_t InputShape() const
Get the shape of the input.
Definition: linear3d.hpp:152
OutputDataType const & Bias() const
Get the bias of the layer.
Definition: linear3d.hpp:147
OutputDataType & Parameters()
Modify the parameters.
Definition: linear3d.hpp:113
Linear3D & operator=(const Linear3D &layer)
Copy assignment operator.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
OutputDataType & Gradient()
Modify the gradient.
Definition: linear3d.hpp:139
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...
InputDataType & InputParameter()
Modify the input parameter.
Definition: linear3d.hpp:118
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 & Delta()
Modify the delta.
Definition: linear3d.hpp:128