Main Content

trainDetector

Train signal anomaly detector

Since R2023a

    Description

    example

    trainDetector(d,data) trains the detector object d on the training data set data.

    example

    trainDetector(d,data,op) specifies training options for the detector.

    Examples

    collapse all

    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

    collapse all

    Anomaly detector, specified as a deepSignalAnomalyDetectorCNN object, a deepSignalAnomalyDetectorLSTM object, or a deepSignalAnomalyDetectorLSTMForecaster object. Use the deepSignalAnomalyDetector function to create d.

    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), or arrayDatastore object. The detector uses the readall function to read all the signal observations contained in the datastore at once. You can also use a CombinedDatastore or TransformedDatastore object containing any of the supported datastores.

    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 a TrainingOptionsADAM (Deep Learning Toolbox) object.

    • If the ModelType property of the detector is specified as "lstmautoencoder", the training options default to a TrainingOptionsADAM (Deep Learning Toolbox) object with SequenceLength equal to 128.

    Extended Capabilities

    Version History

    Introduced in R2023a