Main Content

plotHistogram

Plot histogram of anomaly scores and detection threshold

Since R2025a

Description

plotHistogram(detector,data1) plots computes the anomaly scores for the detector detector using the data in data1, and plots a histogram of the scores along with the threshold in detector.threshold.

Use this syntax, for example, when you have trained a detector using the normal data in data1, and you want to examine the score distribution and the threshold placement.

For an example of using plotHistogram as part of the detector development workflow, see Train and Test TCN Anomaly Detector.

plotHistogram(detector,data1,data2) plots the histograms for two sets of data, data1 and data2, together in the same figure.

Use this syntax, for example, when you have both normal data and test data and you want to view the histogram of the associated anomaly scores together. You can use this syntax without running detect first.

plotHistogram(___,Name=Value) sets additional options using one or more name-value arguments.

Input Arguments

collapse all

Trained anomaly detector model, specified as a TcnDetector, DeepantDetector, UsadDetector, or VaelstmDetector object.

Time series data for computing the first or only set of anomaly scores to plot, specified as a matrix, a cell array, or a timetable. Typically, data1 contains the training data that was used for training TcnDetector and consists of only normal data, with no known anomalies or abnormal data.

When data1 contains m sets of signals, each of which contain n = detector.NumChannels channels, the possible formats are these:

  • n-column matrix that consists of a single multichannel signal (m=1).

  • Cell array with m cells that each contain a matrix that has NumChannels columns.

  • Timetable that contains a single multichannel signal , arranged in one of two possible ways.

    • The n channels are distributed in the columns of a matrix that the timetable contains in a single variable

    • The n channels are represented by n timetable variables that each contain a vector.

    In either case, the timetable must contain finite, increasing, and uniformly sampled time values.

Time series data for computing the second set of anomaly scores to plot, specified as a matrix, a cell array, or a timetable. Typically, data2 consists of test data, and can contain a mix of abnormal and normal data.

When data2 contains m sets of signals, each of which contain n = detector.NumChannels channels, the possible formats are these:

  • n-column matrix that consists of a single multichannel signal (m=1).

  • Cell array with m cells that each contain a matrix that has NumChannels columns.

  • Timetable that contains a single multichannel signal , arranged in one of two possible ways.

    • The n channels are distributed in the columns of a matrix that the timetable contains in a single variable

    • The n channels are represented by n timetable variables that each contain a vector.

    In either case, the timetable must contain finite, increasing, and uniformly sampled time values.

Name-Value Arguments

expand all

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: plotHistogram(detectortcn,data,MiniBatchSize=64) plots a histogram of data for the TCN detector detectortcn and specifies a mini-batch size of 64 for detection.

TCN, DeepAnt, and VAELSTM Detectors Only

expand all

Mini-batch size that is used in detect, specified as a positive integer scalar.

You must set this argument if detect uses a MiniBatchSize value of anything other than default size of 128.

TCN and DeepAnt Detectors Only

expand all

Execution environment that determines what hardware resources the software uses to run the network, specified as "auto", "gpu", or "cpu".

  • "auto" — Use the GPU if it is available, or, if not, the CPU.

  • "gpu" — Use the GPU.

  • "cpu" — Use the CPU.

Version History

Introduced in R2025a