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