13 #ifndef MLPACK_METHODS_ANN_LAYER_FAST_LSTM_HPP 14 #define MLPACK_METHODS_ANN_LAYER_FAST_LSTM_HPP 62 typename InputDataType = arma::mat,
63 typename OutputDataType = arma::mat
70 typedef typename OutputDataType::elem_type
ElemType;
84 const size_t rho = std::numeric_limits<size_t>::max());
93 template<
typename InputType,
typename OutputType>
94 void Forward(InputType&& input, OutputType&& output);
105 template<
typename InputType,
typename ErrorType,
typename GradientType>
106 void Backward(
const InputType&& input,
130 template<
typename InputType,
typename ErrorType,
typename GradientType>
133 GradientType&& gradient);
136 size_t Rho()
const {
return rho; }
138 size_t&
Rho() {
return rho; }
151 OutputDataType
const&
Delta()
const {
return delta; }
153 OutputDataType&
Delta() {
return delta; }
156 OutputDataType
const&
Gradient()
const {
return grad; }
163 template<
typename Archive>
164 void serialize(Archive& ar,
const unsigned int );
173 template<
typename InputType,
typename OutputType>
174 void FastSigmoid(InputType&& input, OutputType&& sigmoids)
176 for (
size_t i = 0; i < input.n_elem; ++i)
177 sigmoids(i) = FastSigmoid(input(i));
186 ElemType FastSigmoid(
const InputElemType data)
188 ElemType x = 0.5 * data;
193 z = (1.5 * x / (1 + x));
195 z = (0.935409070603099 + 0.0458812946797165 * (x - 1.7));
197 z = 0.99505475368673;
203 z = -(1.5 * xx / (1 + xx));
205 z = -(0.935409070603099 + 0.0458812946797165 * (xx - 1.7));
207 z = -0.99505475368673;
210 return 0.5 * (z + 1.0);
232 OutputDataType weights;
235 OutputDataType prevOutput;
245 size_t gradientStepIdx;
248 OutputDataType cellActivationError;
251 OutputDataType delta;
257 OutputDataType outputParameter;
260 OutputDataType output2GateWeight;
263 OutputDataType input2GateWeight;
266 OutputDataType input2GateBias;
272 OutputDataType gateActivation;
275 OutputDataType stateActivation;
281 OutputDataType cellActivation;
284 OutputDataType forgetGateError;
287 OutputDataType prevError;
290 OutputDataType outParameter;
303 #include "fast_lstm_impl.hpp" OutputDataType & Gradient()
Modify the gradient.
OutputDataType & Delta()
Modify the delta.
void Forward(InputType &&input, OutputType &&output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType::elem_type ElemType
OutputDataType const & Parameters() const
Get the parameters.
OutputDataType const & Gradient() const
Get the gradient.
size_t & Rho()
Modify the maximum number of steps to backpropagate through time (BPTT).
FastLSTM()
Create the Fast LSTM object.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & OutputParameter() const
Get the output parameter.
InputDataType::elem_type InputElemType
void Backward(const InputType &&input, ErrorType &&gy, GradientType &&g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
OutputDataType & OutputParameter()
Modify the output parameter.
void ResetCell(const size_t size)
size_t Rho() const
Get the maximum number of steps to backpropagate through time (BPTT).
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
An implementation of a faster version of the Fast LSTM network layer.