LinearLayer

LinearLayer[n]

represents a trainable, fully connected net layer that computes with output vector of size n.

LinearLayer[{n1,n2,}]

represents a layer that outputs a tensor of dimensions n1×n2×.

LinearLayer[]

leaves the dimensions of the output tensor to be inferred from context.

LinearLayer[n,opts]

includes options for initial weights and other parameters.

Details and Options

  • The following optional parameters can be included:
  • "Biases"Automaticinitial vector of biases (b in w.x+b)
    "Weights"Automaticinitial matrix of weights (w in w.x+b)
  • When weights and biases are not explicitly specified or are given as Automatic, they are added automatically when NetInitialize or NetTrain is used.
  • The setting "Biases"->None specifies that no biases should be used.
  • If weights and biases have been added, LinearLayer[][input] explicitly computes the output from applying the layer.
  • LinearLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • NetExtract can be used to extract weights and biases from a LinearLayer object.
  • LinearLayer is typically used inside NetChain, NetGraph, etc.
  • LinearLayer exposes the following ports for use in NetGraph etc.:
  • "Input"a tensor
    "Output"a tensor of size n1×n2×
  • LinearLayer[{}] specifies that the LinearLayer should produce a single real number.
  • LinearLayer[n,"Input"->m] is the most common usage of LinearLayer and represents a LinearLayer that takes a vector of length n and produces a vector of length m.
  • When it cannot be inferred from previous layers in a larger net, the option "Input"shape can be used to fix the input of LinearLayer. Possible forms for shape include:
  • "Real"a single real number
    ma vector of length m
    {m1,m2,}a tensor of dimensions m1×m2×
    NetEncoder[]an encoded tensor

Examples

open allclose all

Basic Examples  (2)

Create a LinearLayer whose output is a length-5 vector:

In[1]:=
Click for copyable input
Out[1]=

Create a randomly initialized LinearLayer:

In[1]:=
Click for copyable input
Out[1]=

Apply the layer to an input vector to produce an output vector:

In[2]:=
Click for copyable input
Out[2]=

Scope  (6)

Options  (2)

Applications  (1)

Properties & Relations  (3)

Possible Issues  (3)

See Also

ConstantPlusLayer  ElementwiseLayer  NetChain  NetGraph  NetInitialize  NetTrain  NetExtract  Ramp  DotLayer

Introduced in 2016
(11.0)