class_docstr: lasagne.layers.recurrent.LSTMLayer(incoming, num_units,
  ingate=lasagne.layers.Gate(), forgetgate=lasagne.layers.Gate(),
  cell=lasagne.layers.Gate(
  W_cell=None, nonlinearity=lasagne.nonlinearities.tanh),
  outgate=lasagne.layers.Gate(),
  nonlinearity=lasagne.nonlinearities.tanh,
  cell_init=lasagne.init.Constant(0.),
  hid_init=lasagne.init.Constant(0.), backwards=False, learn_init=False,
  peepholes=True, gradient_steps=-1, grad_clipping=0, unroll_scan=False,
  precompute_input=True, mask_input=None, only_return_final=False, **kwargs)
  
  A long short-term memory (LSTM) layer.
  
  Includes optional "peephole connections" and a forget gate.  Based on the
  definition in [1]_, which is the current common definition.  The output is
  computed by
  
  .. math ::
  
      i_t &= \sigma_i(x_t W_{xi} + h_{t-1} W_{hi}
             + w_{ci} \odot c_{t-1} + b_i)\\
      f_t &= \sigma_f(x_t W_{xf} + h_{t-1} W_{hf}
             + w_{cf} \odot c_{t-1} + b_f)\\
      c_t &= f_t \odot c_{t - 1}
             + i_t \odot \sigma_c(x_t W_{xc} + h_{t-1} W_{hc} + b_c)\\
      o_t &= \sigma_o(x_t W_{xo} + h_{t-1} W_{ho} + w_{co} \odot c_t + b_o)\\
      h_t &= o_t \odot \sigma_h(c_t)
  
  Parameters
  ----------
  incoming : a :class:`lasagne.layers.Layer` instance or a tuple
      The layer feeding into this layer, or the expected input shape.
  num_units : int
      Number of hidden/cell units in the layer.
  ingate : Gate
      Parameters for the input gate (:math:`i_t`): :math:`W_{xi}`,
      :math:`W_{hi}`, :math:`w_{ci}`, :math:`b_i`, and :math:`\sigma_i`.
  forgetgate : Gate
      Parameters for the forget gate (:math:`f_t`): :math:`W_{xf}`,
      :math:`W_{hf}`, :math:`w_{cf}`, :math:`b_f`, and :math:`\sigma_f`.
  cell : Gate
      Parameters for the cell computation (:math:`c_t`): :math:`W_{xc}`,
      :math:`W_{hc}`, :math:`b_c`, and :math:`\sigma_c`.
  outgate : Gate
      Parameters for the output gate (:math:`o_t`): :math:`W_{xo}`,
      :math:`W_{ho}`, :math:`w_{co}`, :math:`b_o`, and :math:`\sigma_o`.
  nonlinearity : callable or None
      The nonlinearity that is applied to the output (:math:`\sigma_h`). If
      None is provided, no nonlinearity will be applied.
  cell_init : callable, np.ndarray, theano.shared or :class:`Layer`
      Initializer for initial cell state (:math:`c_0`).
  hid_init : callable, np.ndarray, theano.shared or :class:`Layer`
      Initializer for initial hidden state (:math:`h_0`).
  backwards : bool
      If True, process the sequence backwards and then reverse the
      output again such that the output from the layer is always
      from :math:`x_1` to :math:`x_n`.
  learn_init : bool
      If True, initial hidden values are learned.
  peepholes : bool
      If True, the LSTM uses peephole connections.
      When False, `ingate.W_cell`, `forgetgate.W_cell` and
      `outgate.W_cell` are ignored.
  gradient_steps : int
      Number of timesteps to include in the backpropagated gradient.
      If -1, backpropagate through the entire sequence.
  grad_clipping : float
      If nonzero, the gradient messages are clipped to the given value during
      the backward pass.  See [1]_ (p. 6) for further explanation.
  unroll_scan : bool
      If True the recursion is unrolled instead of using scan. For some
      graphs this gives a significant speed up but it might also consume
      more memory. When `unroll_scan` is True, backpropagation always
      includes the full sequence, so `gradient_steps` must be set to -1 and
      the input sequence length must be known at compile time (i.e., cannot
      be given as None).
  precompute_input : bool
      If True, precompute input_to_hid before iterating through
      the sequence. This can result in a speedup at the expense of
      an increase in memory usage.
  mask_input : :class:`lasagne.layers.Layer`
      Layer which allows for a sequence mask to be input, for when sequences
      are of variable length.  Default `None`, which means no mask will be
      supplied (i.e. all sequences are of the same length).
  only_return_final : bool
      If True, only return the final sequential output (e.g. for tasks where
      a single target value for the entire sequence is desired).  In this
      case, Theano makes an optimization which saves memory.
  
  References
  ----------
  .. [1] Graves, Alex: "Generating sequences with recurrent neural networks."
         arXiv preprint arXiv:1308.0850 (2013).
code: def __init__(
      self,
      incoming,
      num_units,
      ingate=Gate(),
      forgetgate=Gate(),
      cell=Gate(W_cell=None, nonlinearity=nonlinearities.tanh),
      outgate=Gate(),
      nonlinearity=nonlinearities.tanh,
      cell_init=init.Constant(0.0),
      hid_init=init.Constant(0.0),
      backwards=False,
      learn_init=False,
      peepholes=True,
      gradient_steps=-1,
      grad_clipping=0,
      unroll_scan=False,
      precompute_input=True,
      mask_input=None,
      only_return_final=False,
      **kwargs,
  ):
      # This layer inherits from a MergeLayer, because it can have four
      # inputs - the layer input, the mask, the initial hidden state and the
      # inital cell state. We will just provide the layer input as incomings,
      # unless a mask input, inital hidden state or initial cell state was
      # provided.
      incomings = [incoming]
      self.mask_incoming_index = -1
      self.hid_init_incoming_index = -1
      self.cell_init_incoming_index = -1
      if mask_input is not None:
          incomings.append(mask_input)
          self.mask_incoming_index = len(incomings) - 1
      if isinstance(hid_init, Layer):
          incomings.append(hid_init)
          self.hid_init_incoming_index = len(incomings) - 1
      if isinstance(cell_init, Layer):
          incomings.append(cell_init)
          self.cell_init_incoming_index = len(incomings) - 1
  
      # Initialize parent layer
      super(LSTMLayer, self).__init__(incomings, **kwargs)
  
      # If the provided nonlinearity is None, make it linear
      if nonlinearity is None:
          self.nonlinearity = nonlinearities.identity
      else:
          self.nonlinearity = nonlinearity
  
      self.learn_init = learn_init
      self.num_units = num_units
      self.backwards = backwards
      self.peepholes = peepholes
      self.gradient_steps = gradient_steps
      self.grad_clipping = grad_clipping
      self.unroll_scan = unroll_scan
      self.precompute_input = precompute_input
      self.only_return_final = only_return_final
  
      if unroll_scan and gradient_steps != -1:
          raise ValueError(
              "Gradient steps must be -1 when unroll_scan is true."
          )
  
      # Retrieve the dimensionality of the incoming layer
      input_shape = self.input_shapes[0]
  
      if unroll_scan and input_shape[1] is None:
          raise ValueError(
              "Input sequence length cannot be specified as "
              "None when unroll_scan is True"
          )
  
      num_inputs = np.prod(input_shape[2:])
  
      def add_gate_params(gate, gate_name):
          """Convenience function for adding layer parameters from a Gate
          instance."""
          return (
              self.add_param(
                  gate.W_in,
                  (num_inputs, num_units),
                  name="W_in_to_{}".format(gate_name),
              ),
              self.add_param(
                  gate.W_hid,
                  (num_units, num_units),
                  name="W_hid_to_{}".format(gate_name),
              ),
              self.add_param(
                  gate.b,
                  (num_units,),
                  name="b_{}".format(gate_name),
                  regularizable=False,
              ),
              gate.nonlinearity,
          )
  
      # Add in parameters from the supplied Gate instances
      (
          self.W_in_to_ingate,
          self.W_hid_to_ingate,
          self.b_ingate,
          self.nonlinearity_ingate,
      ) = add_gate_params(ingate, "ingate")
  
      (
          self.W_in_to_forgetgate,
          self.W_hid_to_forgetgate,
          self.b_forgetgate,
          self.nonlinearity_forgetgate,
      ) = add_gate_params(forgetgate, "forgetgate")
  
      (
          self.W_in_to_cell,
          self.W_hid_to_cell,
          self.b_cell,
          self.nonlinearity_cell,
      ) = add_gate_params(cell, "cell")
  
      (
          self.W_in_to_outgate,
          self.W_hid_to_outgate,
          self.b_outgate,
          self.nonlinearity_outgate,
      ) = add_gate_params(outgate, "outgate")
  
      # If peephole (cell to gate) connections were enabled, initialize
      # peephole connections.  These are elementwise products with the cell
      # state, so they are represented as vectors.
      if self.peepholes:
          self.W_cell_to_ingate = self.add_param(
              ingate.W_cell, (num_units,), name="W_cell_to_ingate"
          )
  
          self.W_cell_to_forgetgate = self.add_param(
              forgetgate.W_cell,
              (num_units,),
              name="W_cell_to_forgetgate",
          )
  
          self.W_cell_to_outgate = self.add_param(
              outgate.W_cell, (num_units,), name="W_cell_to_outgate"
          )
  
      # Setup initial values for the cell and the hidden units
      if isinstance(cell_init, Layer):
          self.cell_init = cell_init
      else:
          self.cell_init = self.add_param(
              cell_init,
              (1, num_units),
              name="cell_init",
              trainable=learn_init,
              regularizable=False,
          )
  
      if isinstance(hid_init, Layer):
          self.hid_init = hid_init
      else:
          self.hid_init = self.add_param(
              hid_init,
              (1, self.num_units),
              name="hid_init",
              trainable=learn_init,
              regularizable=False,
          )
  
imports: import numpy
  import theano
  import theano.tensor
  from ..None import nonlinearities
  from ..None import init
  from ..utils import unroll_scan
  from .base import MergeLayer, Layer
  from .input import InputLayer
  from .dense import DenseLayer
  from .None import helper
label_desc: Use image node_id 1 to create a new LSTMLayer object from inherited base classes: MergeLayer with example: obj = LSTMLayer(incoming, num_units, ingate, forgetgate, cell, outgate, nonlinearity, cell_init, hid_init, backwards, learn_init, peepholes, gradient_steps, grad_clipping, unroll_scan, precompute_input, mask_input, only_return_final)