parameters: (shape, activation=default_override_or(identity), init=default_override_or(C.glorot_uniform()),
            input_rank=None, map_rank=None,
            bias=default_override_or(True), init_bias=default_override_or(0),
            name='')
return_statement: return dense
docstring: Dense(shape, activation=identity, init=glorot_uniform(), input_rank=None, map_rank=None, bias=True, init_bias=0, name='')
  
      Layer factory function to create an instance of a fully-connected linear layer of the form
      `activation(input @ W + b)` with weights `W` and bias `b`, and `activation` and `b` being optional.
      `shape` may describe a tensor as well.
  
      A ``Dense`` layer instance owns its parameter tensors `W` and `b`, and exposes them as attributes ``.W`` and ``.b``.
  
      Example:
       >>> f = Dense(5, activation=C.relu)
       >>> x = C.input_variable(3)
       >>> h = f(x)
       >>> h.shape
           (5,)
       >>> f.W.shape
           (3, 5)
       >>> f.b.value
           array([ 0.,  0.,  0.,  0.,  0.], dtype=float32)
  
       >>> # activation through default options
       >>> with C.default_options(activation=C.relu):
       ...     f = Dense(500)
  
      The ``Dense`` layer can be applied to inputs that are tensors, not just vectors.
      This is useful, e.g., at the top of a image-processing cascade, where after many
      convolutions with padding and strides it is difficult to know the precise dimensions.
      For this case, CNTK has an extended definition of matrix product, in which
      the input tensor will be treated as if it had been automatically flattened.
      The weight matrix will be a tensor that reflects the "flattened" dimensions in its axes.
  
      Example:
       >>> f = Dense(5, activation=C.softmax) # a 5-class classifier
       >>> x = C.input_variable((64,16,16)) # e.g. an image reduced by a convolution stack
       >>> y = f(x)
       >>> y.shape
       (5,)
       >>> f.W.shape  # "row" dimension of "matrix" consists of 3 axes that match the input
       (64, 16, 16, 5)
  
      This behavior can be modified by telling CNTK either the number of axes that should not be projected (``map_rank``)
      or the rank of the input (``input_rank``). If neither is specified, all input dimensions are
      projected, as in the example above.
  
      Example:
       >>> f = Dense(5, activation=C.softmax, input_rank=2) # a 5-class classifier
       >>> x = C.input_variable((10, 3, 3)) # e.g. 10 parallel 3x3 objects. Input has input_rank=2 axes
       >>> y = f(x)
       >>> y.shape  # the 10 parallel objects are classified separately, the "10" dimension is retained
       (10, 5)
       >>> f.W.shape  # "row" dimension of "matrix" consists of (3,3) matching the input axes to project
       (3, 3, 5)
  
       >>> f = Dense(5, activation=C.softmax, map_rank=2)
       >>> x = C.input_variable((4, 6, 3, 3, 3)) # e.g. 24 parallel 3x3x3 objects arranged in a 4x6 grid. The grid is to be retained
       >>> y = f(x)
       >>> y.shape  # the 4x6 elements are classified separately, the grid structure is retained
       (4, 6, 5)
       >>> f.W.shape  # "row" dimension of "matrix" consists of (3,3) matching the input axes to project
       (3, 3, 3, 5)
       >>> z = y([np.zeros(x.shape)])
       >>> assert z.shape == (1, 4, 6, 5)
  
      Args:
       shape (`int` or `tuple` of `ints`): vector or tensor dimension of the output of this layer
       activation (:class:`~cntk.ops.functions.Function`, defaults to identity): optional function to apply at the end, e.g. `relu`
       init (scalar or NumPy array or :mod:`cntk.initializer`, defaults to :func:`~cntk.initializer.glorot_uniform` ): initial value of weights `W`
       input_rank (int, defaults to `None`): number of inferred axes to add to W (`map_rank` must not be given)
       map_rank (int, defaults to `None`): expand W to leave exactly `map_rank` axes (`input_rank` must not be given)
       bias (bool, optional, defaults to `True`): the layer will have no bias if `False` is passed here
       init_bias (scalar or NumPy array or :mod:`cntk.initializer`, defaults to 0): initial value of weights `b`
       name (str, defaults to ''): the name of the function instance in the network
  
      Returns:
          cntk.ops.functions.Function:
          A function that accepts one argument and applies the operation to it
docstring_summary: Dense(shape, activation=identity, init=glorot_uniform(), input_rank=None, map_rank=None, bias=True, init_bias=0, name='')
docstring_tokens: Dense ( shape activation = identity init = glorot_uniform () input_rank = None map_rank = None bias = True init_bias = 0 name = )
function: def Dense(shape, activation=default_override_or(identity), init=default_override_or(C.glorot_uniform()),
            input_rank=None, map_rank=None,
            bias=default_override_or(True), init_bias=default_override_or(0),
            name=''):
      '''
      Dense(shape, activation=identity, init=glorot_uniform(), input_rank=None, map_rank=None, bias=True, init_bias=0, name='')
  
      Layer factory function to create an instance of a fully-connected linear layer of the form
      `activation(input @ W + b)` with weights `W` and bias `b`, and `activation` and `b` being optional.
      `shape` may describe a tensor as well.
  
      A ``Dense`` layer instance owns its parameter tensors `W` and `b`, and exposes them as attributes ``.W`` and ``.b``.
  
      Example:
       >>> f = Dense(5, activation=C.relu)
       >>> x = C.input_variable(3)
       >>> h = f(x)
       >>> h.shape
           (5,)
       >>> f.W.shape
           (3, 5)
       >>> f.b.value
           array([ 0.,  0.,  0.,  0.,  0.], dtype=float32)
  
       >>> # activation through default options
       >>> with C.default_options(activation=C.relu):
       ...     f = Dense(500)
  
      The ``Dense`` layer can be applied to inputs that are tensors, not just vectors.
      This is useful, e.g., at the top of a image-processing cascade, where after many
      convolutions with padding and strides it is difficult to know the precise dimensions.
      For this case, CNTK has an extended definition of matrix product, in which
      the input tensor will be treated as if it had been automatically flattened.
      The weight matrix will be a tensor that reflects the "flattened" dimensions in its axes.
  
      Example:
       >>> f = Dense(5, activation=C.softmax) # a 5-class classifier
       >>> x = C.input_variable((64,16,16)) # e.g. an image reduced by a convolution stack
       >>> y = f(x)
       >>> y.shape
       (5,)
       >>> f.W.shape  # "row" dimension of "matrix" consists of 3 axes that match the input
       (64, 16, 16, 5)
  
      This behavior can be modified by telling CNTK either the number of axes that should not be projected (``map_rank``)
      or the rank of the input (``input_rank``). If neither is specified, all input dimensions are
      projected, as in the example above.
  
      Example:
       >>> f = Dense(5, activation=C.softmax, input_rank=2) # a 5-class classifier
       >>> x = C.input_variable((10, 3, 3)) # e.g. 10 parallel 3x3 objects. Input has input_rank=2 axes
       >>> y = f(x)
       >>> y.shape  # the 10 parallel objects are classified separately, the "10" dimension is retained
       (10, 5)
       >>> f.W.shape  # "row" dimension of "matrix" consists of (3,3) matching the input axes to project
       (3, 3, 5)
  
       >>> f = Dense(5, activation=C.softmax, map_rank=2)
       >>> x = C.input_variable((4, 6, 3, 3, 3)) # e.g. 24 parallel 3x3x3 objects arranged in a 4x6 grid. The grid is to be retained
       >>> y = f(x)
       >>> y.shape  # the 4x6 elements are classified separately, the grid structure is retained
       (4, 6, 5)
       >>> f.W.shape  # "row" dimension of "matrix" consists of (3,3) matching the input axes to project
       (3, 3, 3, 5)
       >>> z = y([np.zeros(x.shape)])
       >>> assert z.shape == (1, 4, 6, 5)
  
      Args:
       shape (`int` or `tuple` of `ints`): vector or tensor dimension of the output of this layer
       activation (:class:`~cntk.ops.functions.Function`, defaults to identity): optional function to apply at the end, e.g. `relu`
       init (scalar or NumPy array or :mod:`cntk.initializer`, defaults to :func:`~cntk.initializer.glorot_uniform` ): initial value of weights `W`
       input_rank (int, defaults to `None`): number of inferred axes to add to W (`map_rank` must not be given)
       map_rank (int, defaults to `None`): expand W to leave exactly `map_rank` axes (`input_rank` must not be given)
       bias (bool, optional, defaults to `True`): the layer will have no bias if `False` is passed here
       init_bias (scalar or NumPy array or :mod:`cntk.initializer`, defaults to 0): initial value of weights `b`
       name (str, defaults to ''): the name of the function instance in the network
  
      Returns:
          cntk.ops.functions.Function:
          A function that accepts one argument and applies the operation to it
      '''
  
      activation = get_default_override(Dense, activation=activation)
      init       = get_default_override(Dense, init=init)
      bias       = get_default_override(Dense, bias=bias)
      init_bias  = get_default_override(Dense, init_bias=init_bias)
  
      output_shape = _as_tuple(shape)
  
      if input_rank is not None and map_rank is not None:
          raise ValueError("Dense: input_rank and map_rank cannot be specified at the same time.")
  
      # determine meaning of axes
      # W gets dimension (input_shape + shape)
      # where input_shape is determined as:
      #  - by default, equal to the dimensions of the input passed to Dense()
      #  - if input_rank is given, then the last 'input_rank' dimensions of the input (all others are not reduced over)
      #  - if map_rank is given, then the all but the first 'map_rank' dimensions of the input (those are not reduced over)
      # where input_rank and map_rank are mutually exclusive.
  
      output_rank = len(output_shape)   # support outputs with tensor layouts
  
      # If input_rank not given then pass a single _INFERRED; map_rank if given will determine the input_rank.
      # The dimension inference may still create multiple axes.
      input_shape = _INFERRED * (input_rank if input_rank is not None else 1)
  
      if input_rank is not None:
          infer_input_rank_to_map = -1 # means map_rank is not specified; input_rank rules
      elif map_rank is None:
          infer_input_rank_to_map = 0  # neither given: default to 'infer W to use all input dims'
      else:
          infer_input_rank_to_map = map_rank  # infer W to use all input dims except the first static 'map_rank' ones
  
      # parameters bound to this Function
      init_weights = _initializer_for(init, Record(output_rank=output_rank))
      W = Parameter(input_shape + output_shape, init=init_weights, name='W')
      b = Parameter(              output_shape, init=init_bias,    name='b') if bias else None
  
      # expression of this function
      @BlockFunction('Dense', name)
      def dense(x):
          r = times(x, W, output_rank=output_rank, infer_input_rank_to_map=infer_input_rank_to_map)
          if b:
              r = r + b
          if activation is not None:
              r = activation(r)
          return r
      return dense
function_tokens: def Dense ( shape , activation = default_override_or ( identity ) , init = default_override_or ( C . glorot_uniform ( ) ) , input_rank = None , map_rank = None , bias = default_override_or ( True ) , init_bias = default_override_or ( 0 ) , name = '' ) : activation = get_default_override ( Dense , activation = activation ) init = get_default_override ( Dense , init = init ) bias = get_default_override ( Dense , bias = bias ) init_bias = get_default_override ( Dense , init_bias = init_bias ) output_shape = _as_tuple ( shape ) if input_rank is not None and map_rank is not None : raise ValueError ( "Dense: input_rank and map_rank cannot be specified at the same time." ) # determine meaning of axes # W gets dimension (input_shape + shape) # where input_shape is determined as: #  - by default, equal to the dimensions of the input passed to Dense() #  - if input_rank is given, then the last 'input_rank' dimensions of the input (all others are not reduced over) #  - if map_rank is given, then the all but the first 'map_rank' dimensions of the input (those are not reduced over) # where input_rank and map_rank are mutually exclusive. output_rank = len ( output_shape ) # support outputs with tensor layouts # If input_rank not given then pass a single _INFERRED; map_rank if given will determine the input_rank. # The dimension inference may still create multiple axes. input_shape = _INFERRED * ( input_rank if input_rank is not None else 1 ) if input_rank is not None : infer_input_rank_to_map = - 1 # means map_rank is not specified; input_rank rules elif map_rank is None : infer_input_rank_to_map = 0 # neither given: default to 'infer W to use all input dims' else : infer_input_rank_to_map = map_rank # infer W to use all input dims except the first static 'map_rank' ones # parameters bound to this Function init_weights = _initializer_for ( init , Record ( output_rank = output_rank ) ) W = Parameter ( input_shape + output_shape , init = init_weights , name = 'W' ) b = Parameter ( output_shape , init = init_bias , name = 'b' ) if bias else None # expression of this function @ BlockFunction ( 'Dense' , name ) def dense ( x ) : r = times ( x , W , output_rank = output_rank , infer_input_rank_to_map = infer_input_rank_to_map ) if b : r = r + b if activation is not None : r = activation ( r ) return r return dense