13 #ifndef MLPACK_METHODS_ANN_LAYER_FAST_LSTM_HPP 14 #define MLPACK_METHODS_ANN_LAYER_FAST_LSTM_HPP 63 typename InputDataType = arma::mat,
64 typename OutputDataType = arma::mat
70 typedef typename InputDataType::elem_type InputElemType;
71 typedef typename OutputDataType::elem_type ElemType;
97 const size_t rho = std::numeric_limits<size_t>::max());
106 template<
typename InputType,
typename OutputType>
107 void Forward(
const InputType& input, OutputType& output);
118 template<
typename InputType,
typename ErrorType,
typename GradientType>
119 void Backward(
const InputType& input,
134 void ResetCell(
const size_t size);
143 template<
typename InputType,
typename ErrorType,
typename GradientType>
144 void Gradient(
const InputType& input,
145 const ErrorType& error,
146 GradientType& gradient);
149 size_t Rho()
const {
return rho; }
151 size_t&
Rho() {
return rho; }
164 OutputDataType
const&
Delta()
const {
return delta; }
166 OutputDataType&
Delta() {
return delta; }
169 OutputDataType
const&
Gradient()
const {
return grad; }
182 return 4 * outSize * inSize + 4 * outSize + 4 * outSize * outSize;
194 template<
typename Archive>
195 void serialize(Archive& ar,
const uint32_t );
204 template<
typename InputType,
typename OutputType>
205 void FastSigmoid(
const InputType& input, OutputType& sigmoids)
207 for (
size_t i = 0; i < input.n_elem; ++i)
208 sigmoids(i) = FastSigmoid(input(i));
217 ElemType FastSigmoid(
const InputElemType
data)
219 ElemType x = 0.5 * data;
224 z = (1.5 * x / (1 + x));
226 z = (0.935409070603099 + 0.0458812946797165 * (x - 1.7));
228 z = 0.99505475368673;
234 z = -(1.5 * xx / (1 + xx));
236 z = -(0.935409070603099 + 0.0458812946797165 * (xx - 1.7));
238 z = -0.99505475368673;
241 return 0.5 * (z + 1.0);
263 OutputDataType weights;
266 OutputDataType prevOutput;
276 size_t gradientStepIdx;
279 OutputDataType cellActivationError;
282 OutputDataType delta;
288 OutputDataType outputParameter;
291 OutputDataType output2GateWeight;
294 OutputDataType input2GateWeight;
297 OutputDataType input2GateBias;
303 OutputDataType gateActivation;
306 OutputDataType stateActivation;
312 OutputDataType cellActivation;
315 OutputDataType forgetGateError;
318 OutputDataType prevError;
321 OutputDataType outParameter;
void Forward(const InputType &input, OutputType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
Definition: fast_lstm_impl.hpp:184
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: fast_lstm.hpp:161
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
size_t Rho() const
Get the maximum number of steps to backpropagate through time (BPTT).
Definition: fast_lstm.hpp:149
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: fast_lstm_impl.hpp:353
void Backward(const InputType &input, const ErrorType &gy, GradientType &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
Definition: fast_lstm_impl.hpp:252
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: fast_lstm.hpp:159
OutputDataType const & Gradient() const
Get the gradient.
Definition: fast_lstm.hpp:169
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Delta()
Modify the delta.
Definition: fast_lstm.hpp:166
FastLSTM()
Create the Fast LSTM object.
Definition: fast_lstm_impl.hpp:23
OutputDataType & Parameters()
Modify the parameters.
Definition: fast_lstm.hpp:156
size_t & Rho()
Modify the maximum number of steps to backpropagate through time (BPTT).
Definition: fast_lstm.hpp:151
size_t OutSize() const
Get the number of output units.
Definition: fast_lstm.hpp:177
size_t InputShape() const
Get the shape of the input.
Definition: fast_lstm.hpp:186
size_t InSize() const
Get the number of input units.
Definition: fast_lstm.hpp:174
OutputDataType & Gradient()
Modify the gradient.
Definition: fast_lstm.hpp:171
size_t WeightSize() const
Get the size of the weight matrix.
Definition: fast_lstm.hpp:180
OutputDataType const & Parameters() const
Get the parameters.
Definition: fast_lstm.hpp:154
FastLSTM & operator=(const FastLSTM &layer)
Copy assignment operator.
Definition: fast_lstm_impl.hpp:88
An implementation of a faster version of the Fast LSTM network layer.
Definition: fast_lstm.hpp:66
OutputDataType const & Delta() const
Get the delta.
Definition: fast_lstm.hpp:164