scalingLayer

Scaling layer for actor or critic network

Description

A ScalingLayer is a deep neural network layer that linearly scales and biases an input array U, giving an output Y = Scale.*U + Bias. You can incorporate this layer into the deep neural networks you define for actors or critics in reinforcement learning agents. This layer is useful for scaling and shifting the outputs of nonlinear layers, such as tanhLayer and sigmoid.

For instance, a tanhLayer gives bounded output that falls between –1 and 1. If your actor network output has different bounds (as defined in the actor specification), you can include a ScalingLayer as an output to scale and shift the actor network output appropriately.

The parameters of a ScalingLayer object are not learnable.

Creation

Description

sLayer = scalingLayer creates a scaling layer with default property values.

example

sLayer = scalingLayer(Name,Value) sets properties using name-value pairs. For example, scalingLayer('Scale',0.5) creates a scaling layer that scales its input by 0.5. Enclose each property name in quotes.

Properties

expand all

Name of layer, specified as a character vector. To include a layer in a layer graph, you must specify a nonempty unique layer name. If you train a series network with this layer and Name is set to '', then the software automatically assigns a name to the layer at training time.

This property is read-only.

Description of layer, specified as a character vector. When you create the scaling layer, you can use this property to give it a description that helps you identify its purpose.

Element-wise scale on the input to the scaling layer, specified as one of the following:

  • Scalar — Specify the same scale factor for all elements of the input array.

  • Array with the same dimensions as the input array — Specify different scale factors for each element of the input array.

The scaling layer takes an input U and generates the output Y = Scale.*U + Bias.

Element-wise bias on the input to the scaling layer, specified as one of the following:

  • Scalar — Specify the same bias for all elements of the input array.

  • Array with the same dimensions as the input array — Specify a different bias for each element of the input array.

The scaling layer takes an input U and generates the output Y = Scale.*U + Bias.

Examples

collapse all

Create a scaling layer that converts an input array U to the output array Y = 0.1.*U - 0.4.

sLayer = scalingLayer('Scale',0.1,'Bias',-0.4)
sLayer = 
  ScalingLayer with properties:

     Name: 'scaling'
    Scale: 0.1000
     Bias: -0.4000

  Show all properties

Confirm that the scaling layer scales and offsets an input array as expected.

predict(sLayer,[10,20,30])
ans = 1×3

    0.6000    1.6000    2.6000

You can incorporate sLayer into an actor network or critic network for reinforcement learning.

Assume that the layer preceding the scalingLayer is a tanhLayer with three outputs and that you want to apply a different scaling factor and bias to each out using a scalingLayer. Since the tanhLayer outputs its channels along the third dimension, the scale and bias must be 1-by-1-by-3 arrays.

scale = reshape([2.5 0.4 10],[1 1 3]);
bias = reshape([5 0 -50],[1 1 3]);

Create the scalingLayer object.

sLayer = scalingLayer('Scale',scale,'Bias',bias);

Confirm that the scaling layer applies the correct scale and bias values to an array with the expected dimensions.

testData = reshape([10 10 10],[1 1 3]);
predict(sLayer,testData)
ans = 
ans(:,:,1) =

    30


ans(:,:,2) =

     4


ans(:,:,3) =

    50

Extended Capabilities

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Introduced in R2019a