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; }
147 OutputDataType
const&
Delta()
const {
return delta; }
149 OutputDataType&
Delta() {
return delta; }
152 OutputDataType
const&
Gradient()
const {
return grad; }
159 template<
typename Archive>
160 void serialize(Archive& ar,
const unsigned int );
169 template<
typename InputType,
typename OutputType>
170 void FastSigmoid(InputType&& input, OutputType&& sigmoids)
172 for (
size_t i = 0; i < input.n_elem; ++i)
173 sigmoids(i) = FastSigmoid(input(i));
182 ElemType FastSigmoid(
const InputElemType data)
184 ElemType x = 0.5 * data;
189 z = (1.5 * x / (1 + x));
191 z = (0.935409070603099 + 0.0458812946797165 * (x - 1.7));
193 z = 0.99505475368673;
199 z = -(1.5 * xx / (1 + xx));
201 z = -(0.935409070603099 + 0.0458812946797165 * (xx - 1.7));
203 z = -0.99505475368673;
206 return 0.5 * (z + 1.0);
228 OutputDataType weights;
231 OutputDataType prevOutput;
241 size_t gradientStepIdx;
244 OutputDataType cellActivationError;
247 OutputDataType delta;
253 OutputDataType outputParameter;
256 OutputDataType output2GateWeight;
259 OutputDataType input2GateWeight;
262 OutputDataType input2GateBias;
268 OutputDataType gateActivation;
271 OutputDataType stateActivation;
277 OutputDataType cellActivation;
280 OutputDataType forgetGateError;
283 OutputDataType prevError;
286 OutputDataType outParameter;
299 #include "fast_lstm_impl.hpp" OutputDataType & Gradient()
Modify the gradient.
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.
An implementation of a faster version of the Fast LSTM network layer.