class_docstr: lasagne.layers.DenseLayer(incoming, num_units,
  W=lasagne.init.GlorotUniform(), b=lasagne.init.Constant(0.),
  nonlinearity=lasagne.nonlinearities.rectify, num_leading_axes=1, **kwargs)
  
  A fully connected layer.
  
  Parameters
  ----------
  incoming : a :class:`Layer` instance or a tuple
      The layer feeding into this layer, or the expected input shape
  
  num_units : int
      The number of units of the layer
  
  W : Theano shared variable, expression, numpy array or callable
      Initial value, expression or initializer for the weights.
      These should be a matrix with shape ``(num_inputs, num_units)``.
      See :func:`lasagne.utils.create_param` for more information.
  
  b : Theano shared variable, expression, numpy array, callable or ``None``
      Initial value, expression or initializer for the biases. If set to
      ``None``, the layer will have no biases. Otherwise, biases should be
      a 1D array with shape ``(num_units,)``.
      See :func:`lasagne.utils.create_param` for more information.
  
  nonlinearity : callable or None
      The nonlinearity that is applied to the layer activations. If None
      is provided, the layer will be linear.
  
  num_leading_axes : int
      Number of leading axes to distribute the dot product over. These axes
      will be kept in the output tensor, remaining axes will be collapsed and
      multiplied against the weight matrix. A negative number gives the
      (negated) number of trailing axes to involve in the dot product.
  
  Examples
  --------
  >>> from lasagne.layers import InputLayer, DenseLayer
  >>> l_in = InputLayer((100, 20))
  >>> l1 = DenseLayer(l_in, num_units=50)
  
  If the input has more than two axes, by default, all trailing axes will be
  flattened. This is useful when a dense layer follows a convolutional layer.
  
  >>> l_in = InputLayer((None, 10, 20, 30))
  >>> DenseLayer(l_in, num_units=50).output_shape
  (None, 50)
  
  Using the `num_leading_axes` argument, you can specify to keep more than
  just the first axis. E.g., to apply the same dot product to each step of a
  batch of time sequences, you would want to keep the first two axes.
  
  >>> DenseLayer(l_in, num_units=50, num_leading_axes=2).output_shape
  (None, 10, 50)
  >>> DenseLayer(l_in, num_units=50, num_leading_axes=-1).output_shape
  (None, 10, 20, 50)
class_docstr_tok: ["lasagne.layers.DenseLayer","(","incoming",",","num_units",",","W=lasagne.init.GlorotUniform","(",")",",","b=lasagne.init.Constant","(","0",".",")",",","nonlinearity=lasagne.nonlinearities.rectify",",","num_leading_axes=1",",","*","*","kwargs",")","A","fully","connected","layer",".","Parameters","--","--","--","--","--","incoming",":","a",":","class",":","`","Layer","`","instance","or","a","tuple","The","layer","feeding","into","this","layer",",","or","the","expected","input","shape","num_units",":","int","The","number","of","units","of","the","layer","W",":","Theano","shared","variable",",","expression",",","numpy","array","or","callable","Initial","value",",","expression","or","initializer","for","the","weights",".","These","should","be","a","matrix","with","shape","``","(","num_inputs",",","num_units",")","``",".","See",":","func",":","`","lasagne.utils.create_param","`","for","more","information",".","b",":","Theano","shared","variable",",","expression",",","numpy","array",",","callable","or","``","None","``","Initial","value",",","expression","or","initializer","for","the","biases",".","If","set","to","``","None","``",",","the","layer","will","have","no","biases",".","Otherwise",",","biases","should","be","a","1D","array","with","shape","``","(","num_units",",",")","``",".","See",":","func",":","`","lasagne.utils.create_param","`","for","more","information",".","nonlinearity",":","callable","or","None","The","nonlinearity","that","is","applied","to","the","layer","activations",".","If","None","is","provided",",","the","layer","will","be","linear",".","num_leading_axes",":","int","Number","of","leading","axes","to","distribute","the","dot","product","over",".","These","axes","will","be","kept","in","the","output","tensor",",","remaining","axes","will","be","collapsed","and","multiplied","against","the","weight","matrix",".","A","negative","number","gives","the","(","negated",")","number","of","trailing","axes","to","involve","in","the","dot","product",".","Examples","--","--","--","--",">",">",">","from","lasagne.layers","import","InputLayer",",","DenseLayer",">",">",">","l_in","=","InputLayer","(","(","100",",","20",")",")",">",">",">","l1","=","DenseLayer","(","l_in",",","num_units=50",")","If","the","input","has","more","than","two","axes",",","by","default",",","all","trailing","axes","will","be","flattened",".","This","is","useful","when","a","dense","layer","follows","a","convolutional","layer",".",">",">",">","l_in","=","InputLayer","(","(","None",",","10",",","20",",","30",")",")",">",">",">","DenseLayer","(","l_in",",","num_units=50",")",".output_shape","(","None",",","50",")","Using","the","`","num_leading_axes","`","argument",",","you","can","specify","to","keep","more","than","just","the","first","axis",".","E.g.",",","to","apply","the","same","dot","product","to","each","step","of","a","batch","of","time","sequences",",","you","would","want","to","keep","the","first","two","axes",".",">",">",">","DenseLayer","(","l_in",",","num_units=50",",","num_leading_axes=2",")",".output_shape","(","None",",","10",",","50",")",">",">",">","DenseLayer","(","l_in",",","num_units=50",",","num_leading_axes=-1",")",".output_shape","(","None",",","10",",","20",",","50",")"]
code: def __init__(
      self,
      incoming,
      num_units,
      W=init.GlorotUniform(),
      b=init.Constant(0.0),
      nonlinearity=nonlinearities.rectify,
      num_leading_axes=1,
      **kwargs,
  ):
      super(DenseLayer, self).__init__(incoming, **kwargs)
      self.nonlinearity = (
          nonlinearities.identity
          if nonlinearity is None
          else nonlinearity
      )
  
      self.num_units = num_units
  
      if num_leading_axes >= len(self.input_shape):
          raise ValueError(
              "Got num_leading_axes=%d for a %d-dimensional input, "
              "leaving no trailing axes for the dot product."
              % (num_leading_axes, len(self.input_shape))
          )
      elif num_leading_axes < -len(self.input_shape):
          raise ValueError(
              "Got num_leading_axes=%d for a %d-dimensional input, "
              "requesting more trailing axes than there are input "
              "dimensions." % (num_leading_axes, len(self.input_shape))
          )
      self.num_leading_axes = num_leading_axes
  
      if any(s is None for s in self.input_shape[num_leading_axes:]):
          raise ValueError(
              "A DenseLayer requires a fixed input shape (except for "
              "the leading axes). Got %r for num_leading_axes=%d."
              % (self.input_shape, self.num_leading_axes)
          )
      num_inputs = int(np.prod(self.input_shape[num_leading_axes:]))
  
      self.W = self.add_param(W, (num_inputs, num_units), name="W")
      if b is None:
          self.b = None
      else:
          self.b = self.add_param(
              b, (num_units,), name="b", regularizable=False
          )
  
file_path: Lasagne/lasagne/layers/dense.py
imports: import numpy
  import theano.tensor
  from ..None import init
  from ..None import nonlinearities
  from .base import Layer
label_desc: Use image node_id 1 to create a new DenseLayer object from inherited base classes: Layer with example: obj = DenseLayer(incoming, num_units, W, b, nonlinearity, num_leading_axes)