ScalingLayer - Scaling layer for actor or critic network - MATLAB (original) (raw)

Main Content

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

Syntax

Description

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

`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.

example

Properties

expand all

Name — Name of layer

'scaling' (default) | character vector

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.

Description — Description of layer

'Scaling layer' (default) | character vector

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.

Scale — Element-wise scale on input

1 (default) | scalar | array

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

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.

Bias — Element-wise bias on input

0 (default) | scalar | array

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

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 Scaling Layer

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.

Specify Different Scale and Bias for Each Input Element

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)

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