GRU Layer - Gated recurrent unit (GRU) layer for recurrent neural network (RNN) - Simulink (original) (raw)

Gated recurrent unit (GRU) layer for recurrent neural network (RNN)

Since R2025a

Libraries:
Deep Learning Toolbox / Deep Learning Layers / Sequence Layers

Description

The GRU Layer block represents a recurrent neural network (RNN) layer that learns dependencies between time steps in time-series and sequence data in theCT format (two dimensions corresponding to channels and time steps, in that order).

The exportNetworkToSimulink function generates this block to represent agruLayer object.

Limitations

Ports

Input

expand all

Input data. The data must have two dimensions corresponding to channels and time steps, in that order, or one dimension corresponding to channels.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

The result of applying the GRU operation to the input data. The output data has two dimensions corresponding to channels and time steps, in that order.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

To edit block parameters interactively, use theProperty Inspector. From the Simulink® Toolstrip, on the Simulation tab, in thePrepare gallery, select Property Inspector.

Main

Specify the name of a workspace variable that contains agruLayer object from a trained network. TheGRU Layer block configures itself by using the properties of the object and calculates the block output by using the learnable parameters of the object.

Programmatic Use

Block Parameter: Layer
Type: workspace variable
Values: gruLayer object
Default: 'layerObject'

Data format for the input data. The options use the same notation as the fmt argument of thedlarray object, except layer blocks do not support the Batch (B) dimension and instead assume an observation number of1.

Programmatic Use

Block Parameter: DataFormat
Type: character vector
Values: 'CT'
Default: 'CT'

Whether to use stateful prediction, specified as a boolean. Iftrue, the block maintains the hidden state between time steps. If false, the block performs stateless prediction by resetting the hidden states to their initial values at the beginning of each time step. Use stateless prediction for frame-based processing where Simulink step time represents frame period and the network processes multiple samples at each time step. For more information, seeSample- and Frame-Based Concepts (DSP System Toolbox).

Programmatic Use

Block Parameter: StatefulPrediction
Type: character vector
Values: 'on' | 'off'
Default: 'on'

Data Types

If the object that you pass as the value of the Layer parameter uses the tanh state activation function or thesigmoid gate activation function, then the block uses the approximation method that you specify to compute the layer output.

Approximation Method Data Types Supported When to Use This Method
None (default) Floating-point You are processing only floating-point data.
CORDIC Floating-point (double and single) and fixed-point with aBias value of 0 and aSlope value of a power of 2 You are processing fixed-point data and want to deploy to FPGA hardware.
Lookup Floating-point and fixed-point You are processing fixed-point data and want to generate C/C++ code.

For more information about the CORDIC approximation method, see cordictanh (Fixed-Point Designer).

Programmatic Use

Block Parameter: ApproximationMethod
Type: character vector
Values: 'None' | 'CORDIC' 'Lookup'
Default: 'None'

Lower value of the output range that the software checks.

The software uses the minimum to perform:

Tips

Output minimum does not saturate or clip the actual output signal. Use the Saturation (Simulink) block instead.

Dependencies

To enable this parameter, set Output data type to a value other than Inherit: Inherit via internal rule.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutMin
Values: '[]' (default) | scalar in quotes

Upper value of the output range that the software checks.

The software uses the maximum value to perform:

Tips

Output maximum does not saturate or clip the actual output signal. Use the Saturation (Simulink) block instead.

Dependencies

To enable this parameter, set Output data type to a value other than Inherit: Inherit via internal rule.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutMax
Values: '[]' (default) | scalar in quotes

Choose the data type for the output. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you choose Inherit: Inherit via internal rule, Simulink sets the output data type to the same type as the hidden state.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: OutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) |

Select this parameter to prevent the fixed-point tools from overriding the Output data type you specify on the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: LockScale
Values: 'off' (default) | 'on'

Specify the rounding mode for fixed-point operations. For more information, see Rounding Modes (Fixed-Point Designer).

Block parameters always round to the nearest representable value. To control the rounding of a block parameter, enter an expression using a MATLAB® rounding function in the mask field.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: RndMeth
Values: 'Floor' (default) | 'Ceiling' 'Convergent' 'Nearest' 'Round' 'Simplest' 'Zero'

Specify whether integer overflows saturate or wrap.

For example, the maximum value that the signed 8-bit integer int8 can represent is 127. Any block operation result greater than the maximum value causes overflow of the 8-bit integer.

Tips

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: SaturateOnIntegerOverflow
Values: 'off' (default) | 'on'

The block casts the value of the InputWeights property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InputWeightsDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the RecurrentWeights property of the object that you specify with the Layer parameter to this data type. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: RecurrentWeightsDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the Bias property of the object that you specify with the Layer parameter to this data type.The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: BiasDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

The block casts the value of the HiddenState property of the object that you specify with theLayer parameter to this data type.The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

This parameter affects only the initial hidden state, _h_0. To cast later hidden state values, use theHidden state parameter. For more information, see Gated Recurrent Unit Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InitialHiddenStateDataTypeStr
Values: 'Inherit: Inherit via back propagation' (default) | 'Inherit: Inherit from 'Constant value''

Choose the data type for the output of the subsystemForIteratorSubsystem/HiddenState inside theGRU Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the subsystem computes the hidden state h t as

, where ⊙ denotes the Hadamard product (element-wise multiplication of vectors). For more information, see Gated Recurrent Unit Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: HiddenStateDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Keep LSB' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input' 'Inherit: Same as accumulator'

Choose the data type for the output of the Product block InputWeightsMatrixMultiply/W*x inside theGRU Layer block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product block computes the product of the input weights (W) and the input at the time step (x t). For more information, see Gated Recurrent Unit Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: InputWeightsMatrixMulitplyOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Match scaling' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Choose the data type for the output of the Matrix Multiply blocks inside these subsystems inside theGRU Layer block.

The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType. When you select Inherit: Inherit via internal rule, Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware.

For a time step t, the Product block computes the product of the recurrent weights (R) and the hidden state at the previous time step (h _t_-1). For more information, see Gated Recurrent Unit Layer.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: RecurrentWeightsMatrixMulitplyOutDataTypeStr
Values: 'Inherit: Inherit via internal rule' (default) | 'Inherit: Keep MSB' 'Inherit: Match scaling' 'Inherit: Inherit via back propagation' 'Inherit: Same as first input'

Execution

Specify the discrete interval between sample time hits or specify another type of sample time, such as continuous (0) or inherited (-1). For more options, see Types of Sample Time (Simulink).

By default, the block inherits its sample time based on the context of the block within the model.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: SampleTime
Data Types: char
Values: '-1' (default) | scalar

Extended Capabilities

Version History

Introduced in R2025a