13 #ifndef MLPACK_METHODS_ANN_LAYER_FAST_LSTM_HPP 14 #define MLPACK_METHODS_ANN_LAYER_FAST_LSTM_HPP 58 typename InputDataType = arma::mat,
59 typename OutputDataType = arma::mat
66 typedef typename OutputDataType::elem_type
ElemType;
80 const size_t rho = std::numeric_limits<size_t>::max());
89 template<
typename InputType,
typename OutputType>
90 void Forward(InputType&& input, OutputType&& output);
101 template<
typename InputType,
typename ErrorType,
typename GradientType>
102 void Backward(
const InputType&& input,
126 template<
typename InputType,
typename ErrorType,
typename GradientType>
129 GradientType&& gradient);
132 size_t Rho()
const {
return rho; }
134 size_t&
Rho() {
return rho; }
152 OutputDataType
const&
Delta()
const {
return delta; }
154 OutputDataType&
Delta() {
return delta; }
157 OutputDataType
const&
Gradient()
const {
return grad; }
164 template<
typename Archive>
165 void serialize(Archive& ar,
const unsigned int );
174 template<
typename InputType,
typename OutputType>
175 void FastSigmoid(InputType&& input, OutputType&& sigmoids)
177 for (
size_t i = 0; i < input.n_elem; ++i)
178 sigmoids(i) = FastSigmoid(input(i));
187 ElemType FastSigmoid(
const InputElemType data)
189 ElemType x = 0.5 * data;
194 z = (1.5 * x / (1 + x));
196 z = (0.935409070603099 + 0.0458812946797165 * (x - 1.7));
198 z = 0.99505475368673;
204 z = -(1.5 * xx / (1 + xx));
206 z = -(0.935409070603099 + 0.0458812946797165 * (xx - 1.7));
208 z = -0.99505475368673;
211 return 0.5 * (z + 1.0);
233 OutputDataType weights;
236 OutputDataType prevOutput;
246 size_t gradientStepIdx;
249 OutputDataType cellActivationError;
252 OutputDataType delta;
258 InputDataType inputParameter;
261 OutputDataType outputParameter;
264 OutputDataType output2GateWeight;
267 OutputDataType input2GateWeight;
270 OutputDataType input2GateBias;
276 OutputDataType gateActivation;
279 OutputDataType stateActivation;
285 OutputDataType cellActivation;
288 OutputDataType forgetGateError;
291 OutputDataType prevError;
294 OutputDataType outParameter;
307 #include "fast_lstm_impl.hpp" OutputDataType & Gradient()
Modify the gradient.
InputDataType const & InputParameter() const
Get the input parameter.
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.
InputDataType & InputParameter()
Modify the input parameter.
An implementation of a faster version of the Fast LSTM network layer.