vaelstmAD
Create anomaly detector model that combines variational autoencoder (VAE) and long short-term memory (LSTM) networks to detect anomalies in time series
Since R2025a
Description
creates a detector
= vaelstmAD(numChannels
)VaelstmDetector
model with
numChannels
channels for each time series input to the detector.
After you create the detector model, you can train, test, and modify it to obtain the level of performance you require. For more information about the anomaly detector workflow, see Detecting Anomalies in Time Series Using Deep Learning Detector Models.
detector = vaelstmAD(
sets additional options using one or more name-value arguments.numChannels
,Name=Value)
For example, detector = vaelstmAD(3,Normalization="range")
creates a
detector model for data containing three input channels and with a data normalization method
of "range"
, which, by default, rescales the data range to [0 1].
Input Arguments
Input
Number of input channels in each time series, specified as a positive integer. All time series inputs must have the same number of channels.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: detector = vaelstmAD(3,Normalization="range")
creates a
detector model for data containing three input channels and with a data normalization method
of "range"
, which, by default, rescales the data range to [0 1].
Window
Observation Window Length for each time series segment, specified as a positive integer. The detector uses this value to divide each input time series into segments.
Training stride length of the sliding window in the training stage, specified as a
positive integer. TrainingStride
controls the number of
overlapping samples. If you do not specify TrainingStride
, the
software sets the stride length to the value of 1
to create
nonoverlapping windows.
Detection window length of each time series segment, specified as a positive
integer that is smaller than ObservationWindowLength
. This value
determines the length of the prediction segment that the model uses for
detection.
Detection stride length of sliding window in detection
stage,
specified as a positive integer. DetectionStride
controls the
number of overlapping samples. If you do not specify
DetectionStride
, the software sets the stride length to the
value of DetectionWindowLength
to create nonoverlapping
windows.
Threshold
Method for computing the detection threshold, specified as one of these:
"kSigma"
— Standard deviation of the normalized anomaly scores. The parameter k determines the threshold within the standard deviation levels that identifies an anomaly. The value of k is specified byThresholdParameter
."contaminationFraction"
— Percentage of anomalies within a specified fraction of windows, measured over the entire training set. The fraction value is specified byThresholdParameter
."max"
— Maximum window loss measured over the entire training data set and multiplied byThresholdParameter
."mean"
— Mean window loss measured over the entire training data set and multiplied byThresholdParameter
."median"
— Median window loss measured over the entire training data set and multiplied byThresholdParameter
."manual"
— Manual detection threshold value based onThreshold
."customFunction"
— Custom detection threshold method based onThresholdFunction
.
If you specify ThresholdMethod
, you can also specify
ThresholdParameter
, Threshold
, or
ThresholdParameter
. The available threshold parameter depends
on the specified detection method.
Parameter for determining the detection threshold, specified as a numeric scalar.
The way you specify ThresholdParameter
depends on the
specified value for ThresholdMethod
. This list describes the
specification of ThresholdParameter
for each possible value of
ThresholdMethod
.
"kSigma"
— SpecifyThresholdParameter
as a positive numeric scalar. If you do not specifyThresholdParameter
, the detector sets the threshold to3
."contaminationFraction"
— SpecifyThresholdParameter
as a as a nonnegative scalar less than 0.5. For example, if you specify"contaminationFraction"
as0.05
, then the threshold is set to identify the top 5% of the anomaly scores as anomalous. If you do not specifyThresholdParameter
, the detector sets the threshold to 0.01."max"
,"mean"
, or"median"
— SpecifyThresholdParameter
as a positive numeric scalar. If you do not specifyThresholdParameter
, the detector sets the threshold to1
."customFunction"
or"manual"
—ThresholdParameter
does not apply.
Detection threshold, specified as a positive scalar. The source of the
Threshold
value depends on the setting of
ThresholdMethod
.
If
ThresholdMethod
is"manual"
, you set the value.If
ThresholdMethod
is"customFunction"
, the function you specify inThresholdFunction
computes the value.For other values of
ThresholdMethod
, specifyThresholdParameter
as the input to the specified method. The software uses this method to compute the threshold value.
Function for computing a custom detection threshold, specified as a function
handle. This argument applies only when ThresholdMethod
is
specified as "customFunction"
.
The function must have two inputs:
The first input is a vector of scalar window anomaly scores.
The second input is a vector representing all point-level anomalies.
For example, suppose that the value of
detectionWindowLength
is 10, the value ofdetectionStride
is set to be nonoverlapping, and the time series length is 10001. Then the first input vector has a length of 1000 and the second input vector has a length of 10000.The function must return a positive scalar corresponding to the detection threshold.
Model
Number of convolutional layers in the downsampling section of the model, specified as a positive integer.
Filter size of each convolutional layer in the VAE network, specified as a
positive integer or integer vector. The value of
NumDownsampleLayers
determines how many convolutional layers
the network contains.
If you specify
FilterSize
as a scalar, the size of each filter is the same in all layers.If you specify
FilterSize
as a vector, the size of each filter in the ith vector element is equal to the value ith vector element. The length of the vector must be equal to the number of layers you specified inNumDownsampleLayers
.
Number of filters in each convolutional layer for the VAE network, specified as a positive integer.
Dimensionality of the compressed representation of the input signal by the VAE model, specified as a positive integer. This value impacts the ability of the VAE model to capture the most important features when reconstructing the input data.
Number of hidden units in the LSTM layers, specified as an integer row vector. The length of this vector determines the number of LSTM layers in the LSTM model.
Dropout probability used to avoid overfitting, specified as a nonnegative numeric scalar less than 1. All convolution layers share the same dropout probability.
Normalization
Normalization technique for training and testing, specified as
"zscore"
, "range"
, or
"off"
.
Output Arguments
Anomaly detector model, returned as a VaelstmDetector
object.
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: .
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)