mlpack 3.4.2
linear_no_bias.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_METHODS_ANN_LAYER_LINEAR_NO_BIAS_HPP
14#define MLPACK_METHODS_ANN_LAYER_LINEAR_NO_BIAS_HPP
15
16#include <mlpack/prereqs.hpp>
18
19#include "layer_types.hpp"
20
21namespace mlpack {
22namespace ann {
23
33template <
34 typename InputDataType = arma::mat,
35 typename OutputDataType = arma::mat,
36 typename RegularizerType = NoRegularizer
37>
39{
40 public:
50 LinearNoBias(const size_t inSize,
51 const size_t outSize,
52 RegularizerType regularizer = RegularizerType());
53
54 /*
55 * Reset the layer parameter.
56 */
57 void Reset();
58
66 template<typename eT>
67 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
68
78 template<typename eT>
79 void Backward(const arma::Mat<eT>& /* input */,
80 const arma::Mat<eT>& gy,
81 arma::Mat<eT>& g);
82
83 /*
84 * Calculate the gradient using the output delta and the input activation.
85 *
86 * @param input The input parameter used for calculating the gradient.
87 * @param error The calculated error.
88 * @param gradient The calculated gradient.
89 */
90 template<typename eT>
91 void Gradient(const arma::Mat<eT>& input,
92 const arma::Mat<eT>& error,
93 arma::Mat<eT>& gradient);
94
96 OutputDataType const& Parameters() const { return weights; }
98 OutputDataType& Parameters() { return weights; }
99
101 InputDataType const& InputParameter() const { return inputParameter; }
103 InputDataType& InputParameter() { return inputParameter; }
104
106 OutputDataType const& OutputParameter() const { return outputParameter; }
108 OutputDataType& OutputParameter() { return outputParameter; }
109
111 OutputDataType const& Delta() const { return delta; }
113 OutputDataType& Delta() { return delta; }
114
116 size_t InputSize() const { return inSize; }
117
119 size_t OutputSize() const { return outSize; }
120
122 OutputDataType const& Gradient() const { return gradient; }
124 OutputDataType& Gradient() { return gradient; }
125
129 template<typename Archive>
130 void serialize(Archive& ar, const unsigned int /* version */);
131
132 private:
134 size_t inSize;
135
137 size_t outSize;
138
140 OutputDataType weights;
141
143 OutputDataType weight;
144
146 OutputDataType delta;
147
149 OutputDataType gradient;
150
152 InputDataType inputParameter;
153
155 OutputDataType outputParameter;
156
158 RegularizerType regularizer;
159}; // class LinearNoBias
160
161} // namespace ann
162} // namespace mlpack
163
164// Include implementation.
165#include "linear_no_bias_impl.hpp"
166
167#endif
Implementation of the LinearNoBias class.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
LinearNoBias(const size_t inSize, const size_t outSize, RegularizerType regularizer=RegularizerType())
Create the LinearNoBias object using the specified number of units.
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.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t InputSize() const
Get the input size.
size_t OutputSize() const
Get the output size.
void Gradient(const arma::Mat< eT > &input, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
OutputDataType const & Gradient() const
Get the gradient.
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType & Gradient()
Modify the gradient.
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.
LinearNoBias()
Create the LinearNoBias object.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
OutputDataType & Delta()
Modify the delta.
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.