12 #ifndef MLPACK_METHODS_ANN_LAYER_LSTM_HPP 13 #define MLPACK_METHODS_ANN_LAYER_LSTM_HPP 59 typename InputDataType = arma::mat,
60 typename OutputDataType = arma::mat
75 LSTM(
const size_t inSize,
77 const size_t rho = std::numeric_limits<size_t>::max());
98 template<
typename InputType,
typename OutputType>
99 void Forward(
const InputType& input, OutputType& output);
110 template<
typename InputType,
typename OutputType>
111 void Forward(
const InputType& input,
113 OutputType& cellState,
114 bool useCellState =
false);
125 template<
typename InputType,
typename ErrorType,
typename GradientType>
126 void Backward(
const InputType& input,
141 void ResetCell(
const size_t size);
150 template<
typename InputType,
typename ErrorType,
typename GradientType>
151 void Gradient(
const InputType& input,
152 const ErrorType& error,
153 GradientType& gradient);
156 size_t Rho()
const {
return rho; }
158 size_t&
Rho() {
return rho; }
171 OutputDataType
const&
Delta()
const {
return delta; }
173 OutputDataType&
Delta() {
return delta; }
176 OutputDataType
const&
Gradient()
const {
return grad; }
189 return (4 * outSize * inSize + 7 * outSize + 4 * outSize * outSize);
201 template<
typename Archive>
202 void serialize(Archive& ar,
const uint32_t );
224 OutputDataType weights;
227 OutputDataType prevOutput;
237 size_t gradientStepIdx;
240 OutputDataType cellActivationError;
243 OutputDataType delta;
249 OutputDataType outputParameter;
252 OutputDataType output2GateInputWeight;
255 OutputDataType input2GateInputWeight;
258 OutputDataType input2GateInputBias;
261 OutputDataType cell2GateInputWeight;
264 OutputDataType output2GateForgetWeight;
267 OutputDataType input2GateForgetWeight;
270 OutputDataType input2GateForgetBias;
273 OutputDataType cell2GateForgetWeight;
276 OutputDataType output2GateOutputWeight;
279 OutputDataType input2GateOutputWeight;
282 OutputDataType input2GateOutputBias;
285 OutputDataType cell2GateOutputWeight;
288 OutputDataType inputGate;
291 OutputDataType forgetGate;
294 OutputDataType hiddenLayer;
297 OutputDataType outputGate;
300 OutputDataType inputGateActivation;
303 OutputDataType forgetGateActivation;
306 OutputDataType outputGateActivation;
309 OutputDataType hiddenLayerActivation;
312 OutputDataType input2HiddenWeight;
315 OutputDataType input2HiddenBias;
318 OutputDataType output2HiddenWeight;
324 OutputDataType cellActivation;
327 OutputDataType forgetGateError;
330 OutputDataType outputGateError;
333 OutputDataType prevError;
336 OutputDataType outParameter;
339 OutputDataType inputCellError;
342 OutputDataType inputGateError;
345 OutputDataType hiddenError;
LSTM & operator=(const LSTM &layer)
Copy assignment operator.
Definition: lstm_impl.hpp:67
size_t InSize() const
Get the number of input units.
Definition: lstm.hpp:181
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: lstm.hpp:168
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Parameters()
Modify the parameters.
Definition: lstm.hpp:163
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: lstm_impl.hpp:541
size_t & Rho()
Modify the maximum number of steps to backpropagate through time (BPTT).
Definition: lstm.hpp:158
OutputDataType const & Gradient() const
Get the gradient.
Definition: lstm.hpp:176
OutputDataType const & Parameters() const
Get the parameters.
Definition: lstm.hpp:161
size_t OutSize() const
Get the number of output units.
Definition: lstm.hpp:184
size_t WeightSize() const
Get the size of the weights.
Definition: lstm.hpp:187
OutputDataType & Gradient()
Modify the gradient.
Definition: lstm.hpp:178
size_t Rho() const
Get the maximum number of steps to backpropagate through time (BPTT).
Definition: lstm.hpp:156
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: lstm_impl.hpp:237
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: lstm.hpp:166
OutputDataType const & Delta() const
Get the delta.
Definition: lstm.hpp:171
OutputDataType & Delta()
Modify the delta.
Definition: lstm.hpp:173
LSTM()
Create the LSTM object.
Definition: lstm_impl.hpp:22
size_t InputShape() const
Get the shape of the input.
Definition: lstm.hpp:193
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: lstm_impl.hpp:362