mlpack 3.4.2
parametric_relu.hpp
Go to the documentation of this file.
1
15#ifndef MLPACK_METHODS_ANN_LAYER_PReLU_HPP
16#define MLPACK_METHODS_ANN_LAYER_PReLU_HPP
17
18#include <mlpack/prereqs.hpp>
19
20namespace mlpack {
21namespace ann {
22
41template <
42 typename InputDataType = arma::mat,
43 typename OutputDataType = arma::mat
44>
45class PReLU
46{
47 public:
56 PReLU(const double userAlpha = 0.03);
57
58 /*
59 * Reset the layer parameter.
60 */
61 void Reset();
62
70 template<typename InputType, typename OutputType>
71 void Forward(const InputType& input, OutputType& output);
72
82 template<typename DataType>
83 void Backward(const DataType& input, const DataType& gy, DataType& g);
84
92 template<typename eT>
93 void Gradient(const arma::Mat<eT>& input,
94 const arma::Mat<eT>& error,
95 arma::Mat<eT>& gradient);
96
98 OutputDataType const& Parameters() const { return alpha; }
100 OutputDataType& Parameters() { return alpha; }
101
103 OutputDataType const& OutputParameter() const { return outputParameter; }
105 OutputDataType& OutputParameter() { return outputParameter; }
106
108 OutputDataType const& Delta() const { return delta; }
110 OutputDataType& Delta() { return delta; }
111
113 OutputDataType const& Gradient() const { return gradient; }
115 OutputDataType& Gradient() { return gradient; }
116
118 double const& Alpha() const { return alpha(0); }
120 double& Alpha() { return alpha(0); }
121
125 template<typename Archive>
126 void serialize(Archive& ar, const unsigned int /* version */);
127
128 private:
130 OutputDataType delta;
131
133 OutputDataType outputParameter;
134
136 OutputDataType alpha;
137
139 OutputDataType gradient;
140
142 double userAlpha;
143}; // class PReLU
144
145} // namespace ann
146} // namespace mlpack
147
148// Include implementation.
149#include "parametric_relu_impl.hpp"
150
151#endif
The PReLU activation function, defined by (where alpha is trainable)
void Forward(const InputType &input, OutputType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
double & Alpha()
Modify the non zero gradient.
OutputDataType const & OutputParameter() const
Get the output parameter.
PReLU(const double userAlpha=0.03)
Create the PReLU object using the specified parameters.
void Gradient(const arma::Mat< eT > &input, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
Calculate the gradient using the output delta and the input activation.
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType & OutputParameter()
Modify the output parameter.
double const & Alpha() const
Get the non zero gradient.
void Backward(const DataType &input, const DataType &gy, DataType &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
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.