mlpack 3.4.2
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
20namespace mlpack {
21namespace ann {
22
35template <
36 typename InputDataType = arma::mat,
37 typename OutputDataType = arma::mat,
38 typename RegularizerType = NoRegularizer
39>
41{
42 public:
45
53 Linear3D(const size_t inSize,
54 const size_t outSize,
55 RegularizerType regularizer = RegularizerType());
56
57 /*
58 * Reset the layer parameter.
59 */
60 void Reset();
61
69 template<typename eT>
70 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
71
81 template<typename eT>
82 void Backward(const arma::Mat<eT>& /* input */,
83 const arma::Mat<eT>& gy,
84 arma::Mat<eT>& g);
85
86 /*
87 * Calculate the gradient using the output delta and the input activation.
88 *
89 * @param input The input parameter used for calculating the gradient.
90 * @param error The calculated error.
91 * @param gradient The calculated gradient.
92 */
93 template<typename eT>
94 void Gradient(const arma::Mat<eT>& input,
95 const arma::Mat<eT>& error,
96 arma::Mat<eT>& gradient);
97
99 OutputDataType const& Parameters() const { return weights; }
101 OutputDataType& Parameters() { return weights; }
102
104 InputDataType const& InputParameter() const { return inputParameter; }
106 InputDataType& InputParameter() { return inputParameter; }
107
109 OutputDataType const& OutputParameter() const { return outputParameter; }
111 OutputDataType& OutputParameter() { return outputParameter; }
112
114 OutputDataType const& Delta() const { return delta; }
116 OutputDataType& Delta() { return delta; }
117
119 size_t InputSize() const { return inSize; }
120
122 size_t OutputSize() const { return outSize; }
123
125 OutputDataType const& Gradient() const { return gradient; }
127 OutputDataType& Gradient() { return gradient; }
128
130 OutputDataType const& Weight() const { return weight; }
132 OutputDataType& Weight() { return weight; }
133
135 OutputDataType const& Bias() const { return bias; }
137 OutputDataType& Bias() { return bias; }
138
142 template<typename Archive>
143 void serialize(Archive& ar, const unsigned int /* version */);
144
145 private:
147 size_t inSize;
148
150 size_t outSize;
151
153 OutputDataType weights;
154
156 OutputDataType weight;
157
159 OutputDataType bias;
160
162 OutputDataType delta;
163
165 OutputDataType gradient;
166
168 InputDataType inputParameter;
169
171 OutputDataType outputParameter;
172
174 RegularizerType regularizer;
175}; // class Linear
176
177} // namespace ann
178} // namespace mlpack
179
180// Include implementation.
181#include "linear3d_impl.hpp"
182
183#endif
Implementation of the Linear3D layer class.
Definition: linear3d.hpp:41
OutputDataType const & Delta() const
Get the delta.
Definition: linear3d.hpp:114
OutputDataType const & Parameters() const
Get the parameters.
Definition: linear3d.hpp:99
OutputDataType const & Weight() const
Get the weight of the layer.
Definition: linear3d.hpp:130
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 & Weight()
Modify the weight of the layer.
Definition: linear3d.hpp:132
OutputDataType const & Bias() const
Get the bias of the layer.
Definition: linear3d.hpp:135
InputDataType & InputParameter()
Modify the input parameter.
Definition: linear3d.hpp:106
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: linear3d.hpp:109
size_t InputSize() const
Get the input size.
Definition: linear3d.hpp:119
size_t OutputSize() const
Get the output size.
Definition: linear3d.hpp:122
void Gradient(const arma::Mat< eT > &input, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
OutputDataType const & Gradient() const
Get the gradient.
Definition: linear3d.hpp:125
Linear3D(const size_t inSize, const size_t outSize, RegularizerType regularizer=RegularizerType())
Create the Linear3D layer object using the specified number of units.
InputDataType const & InputParameter() const
Get the input parameter.
Definition: linear3d.hpp:104
Linear3D()
Create the Linear3D object.
OutputDataType & Bias()
Modify the bias weights of the layer.
Definition: linear3d.hpp:137
OutputDataType & Gradient()
Modify the gradient.
Definition: linear3d.hpp:127
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: linear3d.hpp:111
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
Definition: linear3d.hpp:101
OutputDataType & Delta()
Modify the delta.
Definition: linear3d.hpp:116
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.