GRU Projected Layer
Gated recurrent unit (GRU) projected layer for recurrent neural network (RNN)
Since R2025a
Libraries:
Deep Learning Toolbox /
Deep Learning Layers /
Sequence Layers
Description
The GRU Projected Layer block represents a recurrent neural network
(RNN) layer that learns dependencies between time steps in time-series and sequence data in
the CT
format (two dimensions corresponding to channels and time steps, in
that order) by using projected learnable weights.
To compress a deep learning network, you can use projected layers. A projected layer is a type of deep learning layer that enables compression by reducing the number of stored learnable parameters. The layer introduces learnable projector matrices Q, replaces multiplications of the form , where W is a learnable matrix, with the multiplication , and stores Q and instead of storing W. Projecting x into a lower dimensional space using Q typically requires less memory to store the learnable parameters and can have similarly strong prediction accuracy.
Reducing the number of learnable parameters by projecting a GRU layer rather than reducing the number of hidden units of the GRU layer maintains the output size of the layer and, in turn, the sizes of the downstream layers, which can result in better prediction accuracy.
The exportNetworkToSimulink
function generates this block to represent a gruProjectedLayer
object.
Limitations
The Layer parameter does not accept
gruProjectedLayer
objects that have theHasStateInputs
orHasStateOutputs
properties set to1
(true
).
Ports
Input
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
The result of applying the GRU projected 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
To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Main
Specify the name of a workspace variable that contains a
gruProjectedLayer
object from a trained network. The
GRU Projected 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:
gruProjectedLayer object |
Default:
'layerObject' |
Data format for the input data. The options use the same
notation as the fmt
argument of the
dlarray
object, except layer blocks do not support the Batch
(B
) dimension and instead assume an observation number of
1
.
Programmatic Use
Block Parameter:
DataFormat |
Type: character vector |
Values:
'CT' |
Default:
'CT' |
Whether to use stateful prediction, specified as a boolean. If
true
, 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, see
Sample- 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 the
sigmoid
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 a
Bias value of | 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:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters (Simulink)) for some blocks.
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
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:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters (Simulink)) for some blocks.
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
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) | <data type expression> |
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.
on
— Overflows saturate to either the minimum or maximum value that the data type can represent.off
— Overflows wrap to the appropriate value that the data type can represent.
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.
With this parameter selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of –128.
With this parameter cleared, the software interprets the overflow-causing value as
int8
, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed asint8
is –126.
Tips
Set this parameter to
on
when your model has a possible overflow and you want explicit saturation protection in the generated code.To optimize the efficiency of your generated code, keep the default
off
setting for this parameter. Using the default setting also helps you avoid overspecifying how the block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors (Simulink).When you select this parameter, saturation applies to every internal operation on the block, not just the output or the result.
In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
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'' | <data type expression> |
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'' | <data type expression> |
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'' | <data type expression> |
The block casts the value of the InputProjector
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
.
For more information, see GRU Projected Layer.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | InputProjectorWeightsDataTypeStr |
Values: | 'Inherit: Inherit via back
propagation' (default) | 'Inherit: Inherit from 'Constant value'' | <data type expression> |
The block casts the value of the OutputProjector
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
.
For more information, see GRU Projected Layer.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | OutputProjectorWeightsDataTypeStr |
Values: | 'Inherit: Inherit via back
propagation' (default) | 'Inherit: Inherit from 'Constant value'' | <data type expression> |
The block casts the value of the HiddenState
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
.
This parameter affects only the initial hidden state, h0. To cast later hidden state values, use the Hidden 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'' | <data type expression> |
Choose the data type for the output of the subsystem
ForIteratorSubsystem/HiddenState
inside the
GRU Projected 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 ht 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' | <data type
expression> |
Choose the data type for the output of the Product
block InputWeightsMatrixMultiply/W*x
inside the
GRU Projected 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 (xt). 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' | <data type
expression> |
Choose the data type for the output of the Matrix Multiply blocks inside these subsystems inside the GRU Projected Layer block.
ForIteratorSubsystem/ResetGateMode/ResetGateMode_after-multiplication/R*h terms
ForIteratorSubsystem/ResetGateMode/ResetGateMode_before-multiplication/R*h terms
ForIteratorSubsystem/ResetGateMode/ResetGateMode_recurrent-bias-after-multiplication/R*h terms
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 (ht-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' | <data type
expression> |
Choose the data type for the output of the Product block
InputWeightsMatrixMultiply/Q_in'*x_full
inside the GRU
Projected 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.
The Product block computes the product of the transposed input projector weights (QinT) and the input (x_full). For more information, see GRU Projected Layer.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | InputProjectorWeightsMatrixMultiplyOutDataTypeStr |
Values: | 'Inherit: Inherit via internal
rule' (default) | 'Inherit: Keep MSB' | 'Inherit: Match scaling' | 'Inherit: Inherit via back propagation' | 'Inherit: Same as first input' | <data type expression> |
Choose the data type for the output of the Matrix Multiply blocks inside these subsystems inside the GRU Projected Layer block.
ForIteratorSubsystem/ResetGateMode/ResetGateMode_after-multiplication/R*h terms/ProjectHiddenState
ForIteratorSubsystem/ResetGateMode/ResetGateMode_before-multiplication/R*h terms/ProjectHiddenState
ForIteratorSubsystem/ResetGateMode/ResetGateMode_before-multiplication/R*h terms/ProjectHadamardProduct
ForIteratorSubsystem/ResetGateMode/ResetGateMode_recurrent-bias-after-multiplication/R*h terms/ProjectHiddenState
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 transposed previous hidden state (ht-1T) and the output projector weights (Qout). For more information, see GRU Projected Layer.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
(Simulink) function.
Parameter: | OutputProjectorWeightsMatrixMultiplyOutDataTypeStr |
Values: | 'Inherit: Inherit via internal
rule' (default) | 'Inherit: Keep MSB' | 'Inherit: Match scaling' | 'Inherit: Inherit via back
propagation' | 'Inherit: Same as first input' | <data type
expression> |
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
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2025a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)