Main Content

scalingLayer

Scaling layer for actor or critic network

Description

A scaling layer 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 expandable to the same dimensions as the input array — Specify different scale factors for each element of the input array.

Note

Scale and Bias must have the same size if they are both arrays.

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 expandable to the same dimensions as the input array — Specify a different bias for each element of the input array.

Note

Scale and Bias must have the same size if they are both arrays.

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

   Learnable Parameters
    No properties.

   State Parameters
    No properties.

Use properties method to see a list of 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 aligned along the first dimension, and that you want to apply a different scaling factor and bias to each out using a scalingLayer.

scale = [2.5 0.4 10]';
bias = [5 0 -50]';

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 = [10 10 10]';
predict(sLayer,testData)
ans = 3×1

    30
     4
    50

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

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

Version History

Introduced in R2019a