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,
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;
358 #include "lstm_impl.hpp" OutputDataType const & OutputParameter() const
Get the output parameter.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t OutSize() const
Get the number of output units.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
size_t InputShape() const
Get the shape of the input.
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t InSize() const
Get the number of input units.
size_t Rho() const
Get the maximum number of steps to backpropagate through time (BPTT).
OutputDataType const & Parameters() const
Get the parameters.
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...
OutputDataType const & Delta() const
Get the delta.
void Forward(const InputType &input, OutputType &output)
Ordinary feed-forward pass of a neural network, evaluating the function f(x) by propagating the activ...
LSTM()
Create the LSTM object.
LSTM & operator=(const LSTM &layer)
Copy assignment operator.
size_t WeightSize() const
Get the size of the weights.
OutputDataType const & Gradient() const
Get the gradient.
void ResetCell(const size_t size)
OutputDataType & Delta()
Modify the delta.
OutputDataType & Parameters()
Modify the parameters.
size_t & Rho()
Modify the maximum number of steps to backpropagate through time (BPTT).