({{, (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer])[] 
represents a layer that adds a learnable bias to its input.}, {, (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer])[opts]
includes options for initial bias and other parameters. }})

OpenersNotesSection(Spacer1)Details and Options

The bias array learned by (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) has the same dimensions as the input to (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]).

The input to (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) is added elementwise to the bias array.

The following optional parameters can be included:

When the bias is not explicitly specified or is given as (RefLink[Automatic, paclet:ref/Automatic]), it is added automatically when (RefLink[NetInitialize, paclet:ref/NetInitialize]) or (RefLink[NetTrain, paclet:ref/NetTrain]) is used. By default, the bias will be initialized to a zero array.

If a bias has been added, (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer])[…][input] explicitly computes the output from applying the layer.

(RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer])[…][{(Subscript[input, 1]),(Subscript[input, 2]),…}] explicitly computes outputs for each of the (Subscript[input, i]).

When given a (RefLink[NumericArray, paclet:ref/NumericArray]) as input, the output will be a (RefLink[NumericArray, paclet:ref/NumericArray]).

The bias array can be obtained from an initialized (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) using (RefLink[NetExtract, paclet:ref/NetExtract])[layer,"Biases"].

(RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) is typically used inside (RefLink[NetChain, paclet:ref/NetChain]), (RefLink[NetGraph, paclet:ref/NetGraph]), etc.

(RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) exposes the following ports for use in (RefLink[NetGraph, paclet:ref/NetGraph]) etc.:

When it cannot be inferred from other layers in a larger net, the option "Input"->{(Subscript[d, 1]),(Subscript[d, 2]),…,(Subscript[d, n])} can be used to fix the input of (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) to be an array of dimensions (Subscript[d, 1])×(Subscript[d, 2])×…×(Subscript[d, n]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]):

ConstantPlusLayer[]

Create an initialized (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) whose input is a vector of length 3:

bias=NetInitialize@ConstantPlusLayer["Input"->3]

Apply the layer to an input vector:

bias[{1,1.,0.}]

OpenersExampleSection1(Spacer1)Scope  (3)

Create a (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) that operates on scalars:

bias=ConstantPlusLayer["Biases"->{0.5},"Input"->"Scalar","Output"->NetDecoder["Scalar"]]

Apply the layer to an input:

bias[1]

The layer threads across a batch of examples:

bias[{1,2,3}]

Plot the output of the layer as a function of the input, compared to y=x:

Plot[{bias[x],x},{x,-2,2}]

Use a (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) in a (RefLink[NetChain, paclet:ref/NetChain]) to independently bias the components of the output of another layer:

net=NetChain[{ElementwiseLayer[Sin],ConstantPlusLayer["Biases"->{1,3,5}]}]

Plot the three output components:

Plot[net[{x,x,x}] //Normal,{x,-10,10}]

Create a random (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) that applies a per-pixel and per-channel bias to an image:

bias=NetInitialize[ConstantPlusLayer["Input"->"Image","Output"->"Image"],Method->{"Random","Biases"->NormalDistribution[0,1/3]}]

bias[]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)"Biases"  (1)

Specify an initial bias:

bias=ConstantPlusLayer["Biases"->{1,2,3}]

Apply the layer to an input vector:

bias[{0,1,0}]

OpenersExampleSection3(Spacer1)Properties & Relations  (4)

By default, (RefLink[NetInitialize, paclet:ref/NetInitialize]) will create a bias that is composed of zeros:

bias=NetInitialize[ConstantPlusLayer[{3}]]

NetExtract[bias,"Biases"]

This is the identity initialization, as it leaves the input unchanged:

bias[{1,2,3}]

Specify a custom distribution to (RefLink[NetInitialize, paclet:ref/NetInitialize]):

bias=NetInitialize[ConstantPlusLayer[{3}],Method->{"Random","Biases"->NormalDistribution[]}]

bias[{1,2,3}]

Affine layers such as (RefLink[LinearLayer, paclet:ref/LinearLayer]) and (RefLink[ConvolutionLayer, paclet:ref/ConvolutionLayer]) include learned biases, so there is no reason to apply a (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) to their outputs.

(RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) is similar to (RefLink[LinearLayer, paclet:ref/LinearLayer]) in that both contain a learned "Biases" array, except that (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) does not perform a dot product.

(RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) is similar to (RefLink[TotalLayer, paclet:ref/TotalLayer]), except that (RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) adds a learned bias array to a single input, whereas (RefLink[TotalLayer, paclet:ref/TotalLayer]) performs elementwise addition of multiple inputs.

OpenersExampleSection4(Spacer1)Possible Issues  (1)

(RefLink[ConstantPlusLayer, paclet:ref/ConstantPlusLayer]) cannot accept symbolic inputs:

bias=NetInitialize@ConstantPlusLayer["Input"-> 2];
bias[{1,2}]

bias[{1,z}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ConstantArrayLayer, paclet:ref/ConstantArrayLayer])  ▪  (RefLink[ConstantTimesLayer, paclet:ref/ConstantTimesLayer])  ▪  (RefLink[LinearLayer, paclet:ref/LinearLayer])  ▪  (RefLink[TotalLayer, paclet:ref/TotalLayer])  ▪  (RefLink[ElementwiseLayer, paclet:ref/ElementwiseLayer])  ▪  (RefLink[NetChain, paclet:ref/NetChain])  ▪  (RefLink[NetGraph, paclet:ref/NetGraph])  ▪  (RefLink[NetInitialize, paclet:ref/NetInitialize])  ▪  (RefLink[NetTrain, paclet:ref/NetTrain])  ▪  (RefLink[NetExtract, paclet:ref/NetExtract])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Neural Networks in the Wolfram Language, paclet:tutorial/NeuralNetworksOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Neural Networks, paclet:guide/NeuralNetworks])}})}})