Update Metrics
Update performance metrics in incremental learning model given new data
Since R2023b
Libraries:
Statistics and Machine Learning Toolbox /
Incremental Learning
Description
The Update Metrics block outputs the performance metrics of a configured
incremental model for binary classification (incrementalClassificationLinear
), multiclass classification (incrementalClassificationECOC
), or linear regression (incrementalRegressionLinear
), given new data.
Import a trained incremental learning model object into the block by specifying the name of a workspace variable that contains the object. The input port mdl receives a bus signal that represents an incremental learning model fit to streaming data. The input port x receives a chunk of predictor data (observations), and the input port y receives a chunk of responses or labels for measuring the model performance. The output port IsWarm returns a value indicating if the model is warm, which means that it tracks performance metrics. The output port metrics returns the computed performance metrics. The optional input port w receives a chunk of observation weights and the optional input port reset resets the learned parameters .
Examples
Perform Incremental Learning and Track Performance Metrics Using Update Metrics Block
Perform incremental learning and track performance metrics with the Update Metrics block.
- Since R2023b
- Open Live Script
Configure Simulink Template for Rate-Based Incremental Linear Regression
Configure the Simulink Rate-Based Incremental Learning template to perform incremental linear regression.
- Since R2024a
- Open Live Script
Configure Simulink Template for Rate-Based Incremental Linear Classification
Configure the Simulink Rate-Based Incremental Learning template to perform incremental linear classification.
- Since R2024a
- Open Live Script
Configure Simulink Template for Conditionally Enabled Incremental Linear Classification
Configure the Simulink Enabled Execution Incremental Learning template to perform incremental linear classification.
- Since R2024a
- Open Live Script
Configure Simulink Template for Conditionally Enabled Incremental Linear Regression
Configure the Simulink Enabled Execution Incremental Learning template to perform incremental linear regression.
- Since R2024a
- Open Live Script
Ports
Input
Incremental learning model fit to streaming data, specified as a bus signal (see
Composite
Signals
(Simulink)).
Chunk of predictor data, specified as a numeric matrix. The orientation of the variables
and observations is specified by Predictor
data observation dimension. The default orientation is
rows
, which indicates that observations in the
predictor data are oriented along the rows of
x.
The length of the observation responses y and the
number of observations in x must be equal;
y(
is the response of observation j (row or column) in
x.j
)
Note
The block supports only numeric input predictor data. If your
input data includes categorical data, you must prepare an encoded
version of the categorical data. Use dummyvar
to convert
each categorical variable to a numeric matrix of dummy variables.
Then, concatenate all dummy variable matrices and any other numeric
predictors. For more details, see Dummy Variables.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Chunk of responses (labels) for measuring the model performance, specified as a numeric, logical, or enumerated vector.
The length of the observation responses y and the number of
observations in x must be equal;
y(j)
is
the response of observation j (row or column) in
x.
For classification problems:
Each label must correspond to one row of the array.
If y contains a label that is in
mdl.ClassNames
, the block issues an error.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Chunk of observation weights, specified as a vector of positive values. The Update Metrics block weights the observations in x with the corresponding values in w. The size of w must be equal to the number of observations in x.
Dependencies
To enable this port, select the check box for Add input port for observation weights on the Main tab of the Block Parameters dialog box.
Data Types: single
| double
Since R2025a
Reset signal, specified as 0
(false
) or
1
(true
) or a numeric scalar. When the
reset signal is a positive scalar (greater than 0), the block
resets the learned parameters, if any, of the incremental learning model. If any
hyperparameters of mdl are estimated during incremental training,
those get reset as well. mdl.NumPredictors
are always
preserved.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Output
Flag indicating whether the incremental model tracks performance metrics, returned as
logical 0
(false
) or
1
(true
).
Value | Description |
---|---|
1 (true) | The incremental model mdl is
warm. Consequently, the block tracks performance metrics
in the bus signal output. |
0 (false) | The block does not track performance metrics. |
Model performance metrics updated during incremental learning, returned as a matrix with
two columns and m rows, where m is
the number of observations in x. Specify the
performance metrics using Model
performance metrics to track. The block ignores the
metrics specified by the Metrics
property of
mdl.
The columns of metrics are:
Cumulative
— Model performance from the time the model becomes warm (IsWarm
is1
).Window
— Model performance evaluated over all observations within the window specified by theMetricsWindowSize
property of mdl. The software updatesWindow
after it processesMetricsWindowSize
observations.
Data Types: matrix
Parameters
Main
Specify the name of a workspace variable that contains the configured incrementalRegressionLinear
, incrementalClassificationLinear
, or incrementalClassificationECOC
model object.
The predictor data cannot include categorical predictors (
logical
,categorical
,char
,string
, orcell
). If you supply training data in a table, the predictors must be numeric (double
orsingle
). To include categorical predictors in a model, preprocess them by usingdummyvar
before fitting the model.The
NumPredictors
property of the initial model must be a positive integer scalar, and must be equal to the number of predictors in x.The
ScoreTransform
property of the initial model (classification only) cannot be"invlogit"
or an anonymous function.
Programmatic Use
Block Parameter:
InitialLearner |
Type: workspace variable |
Values:
incrementalRegressionLinear model object,
incrementalClassificationLinear model
object, incrementalClassificationECOC model
object |
Default:
"Mdl" |
Loss function for cumulative and window performance metrics to track
during incremental learning. For more details on loss functions, see
loss
.
The following table lists the built-in loss function names:
For Regression Models:
Name Description "mse"
Weighted mean squared error "epsiloninsensitive"
Epsilon-insensitive error Default is
"epsiloninsensitive"
for regression models.For Classification Models:
Name Description "binodeviance"
Binomial deviance "classiferror"
Misclassification error rate "exponential"
Exponential "hinge"
Hinge "logit"
Logistic "quadratic"
Quadratic Note
You can only specify
"classiferror"
forincrementalClassificationECOC
models.
The Update Metrics block ignores the metrics specified by the
Metric
property of
mdl.
Programmatic Use
Block Parameter:
Metric |
Type: character vector |
Values:
"classiferror" | "binodeviance" | "exponential" |
"hinge" | "logit" | "quadratic" | "mse" |
"epsiloninsensitive" |
Default:
"classiferror" (for classification models) |
"epsiloninsensitive" (for regression
models) |
Select the check box to include the input port w for observation weights in the Update Metrics block.
Programmatic Use
Block Parameter:
ShowInputWeights |
Type: character vector |
Values:
"off" | "on" |
Default:
"off" |
Since R2025a
Select the check box to include the input port reset for the reset signal in the Update Metrics block.
Programmatic Use
Block Parameter:
ShowInputReset |
Type: character vector or string |
Values:
"off" | "on" |
Default:
"off" |
Specify the observation dimension of the predictor data. The default value is
rows
, which indicates that observations in the predictor data are
oriented along the rows of x.
Programmatic Use
Block Parameter:
ObservationsIn |
Type: character vector |
Values:
"rows" | "columns" |
Default:
"rows" |
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 Update Metrics block inherits sample time based on the context of the block within the model.
Programmatic Use
Block Parameter:
SystemSampleTime |
Type: string scalar or character vector |
Values: scalar |
Default:
"–1" |
Data Types
Fixed-Point Operational Parameters
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 into the mask field using a MATLAB® rounding function.
Programmatic Use
Block Parameter:
RndMeth |
Type: character vector |
Values:
"Ceiling" | "Convergent" | "Floor" | "Nearest" | "Round" | "Simplest" |
"Zero" |
Default:
"Floor" |
Specify whether overflows saturate or wrap.
Action | Rationale | Impact on Overflows | Example |
---|---|---|---|
Select this check box
( | Your model has possible overflow, and you want explicit saturation protection in the generated code. | Overflows saturate to either the minimum or maximum value that the data type can represent. | The maximum value that the |
Clear this check box
( | You want to optimize the efficiency of your generated code. You want to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors (Simulink). | Overflows wrap to the appropriate value that the data type can represent. | The maximum value that the |
Programmatic Use
Block Parameter:
SaturateOnIntegerOverflow |
Type: character vector |
Values:
"off" | "on" |
Default:
"off" |
Select this parameter to prevent the fixed-point tools from overriding the data type you specify for the block. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).
Programmatic Use
Block Parameter:
LockScale |
Type: character vector |
Values:
"off" | "on" |
Default:
"off" |
Data Type
Specify the data type for the metrics output. The type can be inherited, specified
directly, or expressed as a data type object such as
Simulink.NumericType
.
For more information about data types, see Control Data Types of Signals (Simulink).
Click the Show data type
assistant button
to display the Data Type
Assistant, which helps you set the data type attributes.
For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Programmatic Use
Block Parameter:
MetricsDataTypeStr |
Type: character vector |
Values: "double" |
"single" | "half" |
"int8" | "uint8" |
"int16" | "uint16" |
"int32" | "uint32" |
"int64" | "uint64" |
"boolean" |
"fixdt(1,16,0)" |
"fixdt(1,16,2^0,0)" | "<data
type expression>" |
Default: "double" |
Specify the lower value of the metrics output range that Simulink® checks.
Simulink uses the minimum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
The Metrics data type Minimum parameter does not saturate or clip the actual metrics output. To do so, use the Saturation (Simulink) block instead.
Programmatic Use
Block Parameter:
MetricsOutMin |
Type: character vector |
Values:
"[]" | scalar |
Default:
"[]" |
Specify the upper value of the metrics output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
The Metrics data type Maximum parameter does not saturate or clip the actual metrics output. To do so, use the Saturation (Simulink) block instead.
Programmatic Use
Block Parameter:
MetricsOutMax |
Type: character vector |
Values:
"[]" | scalar |
Default:
"[]" |
Specify the data type for the response output from the predict block (IncrementalRegressionLinear Predict, IncrementalClassificationLinear Predict, IncrementalClassificationECOC Predict etc.) that is internal to the Update Metrics block. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType
.
When you select Inherit: auto
, the block uses a rule that inherits a data type.
For more information about data types, see Control Data Types of Signals (Simulink).
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Programmatic Use
Block Parameter:
PredictResponseDataTypeStr |
Type: character vector or string |
Values: "Inherit: auto" | "double" | "single" | "half" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "boolean" | "fixdt(1,16,0)" | "fixdt(1,16,2^0,0)" | "<data type expression>" |
Default: "Inherit: auto" |
Specify the lower value of the internal predict response output range that Simulink checks.
Simulink uses the minimum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
The Predict response data type Minimum parameter does not saturate or clip the actual predict response output. To do so, use the Saturation (Simulink) block instead.
Programmatic Use
Block Parameter: PredictResponseOutMin |
Type: string or numeric scalar |
Values: "[]" | scalar |
Default: "[]" |
Specify the upper value of the internal predict response output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
The Predict response data type Maximum parameter does not saturate or clip the actual predict response output. To do so, use the Saturation (Simulink) block instead.
Programmatic Use
Block Parameter: PredictResponseOutMax |
Type: string or numeric scalar |
Values: "[]" | scalar |
Default: "[]" |
Specify the data type for the loss value output used internally by the Update Metrics block to evaluate the cumulative loss and the loss over the window specified by the MetricsWindowSize
property of mdl. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType
.
When you select Inherit: auto
, the block uses a rule that inherits a data type.
For more information about data types, see Control Data Types of Signals (Simulink).
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Programmatic Use
Block Parameter: LossDataTypeStr |
Type: character vector |
Values: "Inherit: auto" | "double" | "single" | "half" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "boolean" | "fixdt(1,16,0)" | "fixdt(1,16,2^0,0)" | "<data type expression>" |
Default: "Inherit: auto" |
Specify the lower value of the internal loss output range that Simulink checks.
Simulink uses the minimum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Programmatic Use
Block Parameter: LossOutMin |
Type: character vector |
Values: "[]" | scalar |
Default: "[]" |
Specify the upper value of the internal loss output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Programmatic Use
Block Parameter: LossOutMax |
Type: character vector |
Values: "[]" | scalar |
Default: "[]" |
Specify the data type for the additional response output from the predict block (IncrementalRegressionLinear Predict, IncrementalClassificationLinear Predict, or IncrementalClassificationECOC Predict) that is internal to the Update Metrics 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
, the block uses an internal rule to determine the additional predict data type. The internal rule chooses a data type that optimizes numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware. The software cannot always optimize efficiency and numerical accuracy at the same time.
For more information about data types, see Control Data Types of Signals (Simulink).
Click the Show data type assistant
button to display the Data Type Assistant,
which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Programmatic Use
Block Parameter: AdditionalPredictDataTypeStr |
Type: character vector |
Values: "Inherit: Inherit via internal rule" | "double" | "single" | "half" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "boolean" | "fixdt(1,16,0)" | "fixdt(1,16,2^0,0)" | "<data type expression>" |
Default: "Inherit: Inherit via internal rule" |
Specify the upper value of the additional predict output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
The Additional predict data type Maximum parameter does not saturate or clip the actual additional predict. To do so, use the Saturation (Simulink) block instead.
Programmatic Use
Block Parameter: AdditionalPredictOutMax |
Type: string or numeric scalar |
Values: "[]" | scalar |
Default: "[]" |
Specify the data type for additional operations on the loss value used internally by the
Update Metrics block to evaluate the cumulative loss and
the loss over the window specified by the
MetricsWindowSize
property of
mdl. 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
, the block uses an internal rule to determine the
additional loss data type. The internal rule chooses a data type that
optimizes numerical accuracy, performance, and generated code size,
while taking into account the properties of the embedded target
hardware. The software cannot always optimize efficiency and numerical
accuracy at the same
time.
For more information about data types, see Control Data Types of Signals (Simulink).
Click the Show data type assistant
button to display the Data Type Assistant,
which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant (Simulink).
Programmatic Use
Block Parameter:
AdditionalLossDataTypeStr |
Type: character vector |
Values: "Inherit:
Inherit via internal rule" |
"double" | "single" |
"half" | "int8" |
"uint8" | "int16" |
"uint16" | "int32" |
"uint32" | "int64" |
"uint64" | "boolean" |
"fixdt(1,16,0)" |
"fixdt(1,16,2^0,0)" | "<data
type expression>" |
Default: "Inherit:
Inherit via internal rule" |
Specify the lower value of the additional loss output range that Simulink checks.
Simulink uses the minimum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Programmatic Use
Block Parameter:
AdditionalLossOutMin |
Type: character vector |
Values:
"[]" | scalar |
Default:
"[]" |
Specify the upper value of the additional loss output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking for some blocks (see Specify Minimum and Maximum Values for Block Parameters (Simulink)).
Simulation range checking (see Specify Signal Ranges (Simulink) and Enable Simulation Range Checking (Simulink)).
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 software-in-the-loop (SIL) mode or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Programmatic Use
Block Parameter:
AdditionalLossOutMax |
Type: character vector |
Values:
"[]" | scalar |
Default:
"[]" |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced in R2023bThe Update Metrics has a new reset inport that allows the resetting of the learned parameters, if any, of the incremental learning model. If any hyperparameters of the model are estimated during incremental training, those get reset as well. Use the reset signal when performing drift-aware learning to reset the model parameters when drift is detected.
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: .
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)