trainDetector
Description
Examples
Train Convolutional Signal Anomaly Detector
Load the file sineWaveAnomalyData.mat
, which contains two sets of synthetic three-channel sinusoidal signals.
sineWaveNormal
contains 10 sinusoids of stable frequency and amplitude. Each signal has a series of small-amplitude impact-like imperfections. The signals have different lengths and initial phases. Plot the first three normal signals.
load sineWaveAnomalyData sl = 3; tiledlayout("vertical") ax = zeros(sl,1); for kj = 1:sl ax(kj) = nexttile; plot(sineWaveNormal{kj}) title("Normal Signal") end
sineWaveAbnormal
contains three signals, all of the same length. Each signal in the set has an anomaly.
All channels of the first signal have an abrupt change in frequency that lasts for a finite time.
The second signal has a finite-duration amplitude change in one of its channels.
The third signal has spikes at random times in all channels.
Plot the three signals with anomalies.
for kj = 1:sl plot(ax(kj),sineWaveAbnormal{kj}) title(ax(kj),"Signal with Anomalies") end
Create a convolutional autoencoder object to detect the anomalies in the abnormal signals. Specify that the signals used for both training and testing all have three channels.
D = deepSignalAnomalyDetector(sl);
Use the trainDetector
function to train the convolutional neural network using the anomaly-free data.
Use the training options for the adaptive moment estimation (Adam) optimizer. For more information, see
trainingOptions
(Deep Learning Toolbox).Use the CPU to train the network.
Specify a maximum number of 100 epochs to use for training.
Use a mini-batch size of 64.
Display the training progress as a plot.
opts = trainingOptions("adam",ExecutionEnvironment="cpu", ... MaxEpochs=100,MiniBatchSize=64, ... Verbose=false,Plots="training-progress"); trainDetector(D,sineWaveNormal,opts)
Input Arguments
d
— Anomaly detector
deepSignalAnomalyDetectorCNN
object | deepSignalAnomalyDetectorLSTM
object | deepSignalAnomalyDetectorLSTMForecaster
object
Anomaly detector, specified as a deepSignalAnomalyDetectorCNN
object, a
deepSignalAnomalyDetectorLSTM
object, or a deepSignalAnomalyDetectorLSTMForecaster
object. Use the
deepSignalAnomalyDetector
function to create
d
.
data
— Training data set
Nc-column matrix | M-element cell array | timetable | datastore
Training data set, specified as one of these:
Nc-column matrix — A single multichannel signal observation (M = 1), where Nc is equal to the value of the
NumChannels
property of the detector.M-element cell array — M multichannel signal observations, where each cell contains an Nc-column matrix.
Timetable — A single multichannel signal observation, contained in a MATLAB® timetable. The timetable must contain increasing, uniformly-sampled, and finite values. The timetable can have:
A single variable containing an Nc-column matrix, where each column corresponds to a signal channel.
Nc variables, where each variable contains a vector that corresponds to a signal channel.
Datastore — A
signalDatastore
,audioDatastore
(Audio Toolbox), orarrayDatastore
object. The detector uses thereadall
function to read all the signal observations contained in the datastore at once. You can also use aCombinedDatastore
orTransformedDatastore
object containing any of the supported datastores.
op
— Training options
TrainingOptionsADAM
object (default) | TrainingOptionsSGDM
object | TrainingOptionsRMSProp
object
Training options, specified as a TrainingOptionsADAM
,
TrainingOptionsSGDM
, or TrainingOptionsRMSProp
object. Use trainingOptions
(Deep Learning Toolbox) to create the object.
If the
ModelType
property of the detector is specified as"convautoencoder"
or"lstmforecaster"
, the training options default to aTrainingOptionsADAM
(Deep Learning Toolbox) object.If the
ModelType
property of the detector is specified as"lstmautoencoder"
, the training options default to aTrainingOptionsADAM
(Deep Learning Toolbox) object withSequenceLength
equal to 128.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The trainDetector
function
supports GPU array input with these usage notes and limitations:
The ExecutionEnvironment
option must be "gpu"
or
"auto"
when the input data is:
A
gpuArray
A cell array containing
gpuArray
objectsA datastore that outputs cell arrays containing
gpuArray
objects
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2023a
See Also
Objects
deepSignalAnomalyDetectorCNN
|deepSignalAnomalyDetectorLSTM
|deepSignalAnomalyDetectorLSTMForecaster
Functions
detect
|getModel
|plotAnomalies
|plotLoss
|plotLossDistribution
|resetState
|saveModel
|updateDetector
Topics
- Detect Anomalies in Signals Using deepSignalAnomalyDetector
- Detect Anomalies in Machinery Using LSTM Autoencoder
- Detect Anomalies in ECG Data Using Wavelet Scattering and LSTM Autoencoder in Simulink (DSP System Toolbox)
- Anomaly Detection in Industrial Machinery Using Three-Axis Vibration Data (Predictive Maintenance Toolbox)
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)