Main Content

findDiscord

Find the locations of top discords from the matrix profile of a time series

Since R2024b

Description

Return Local Discord Locations

locs = findDiscord(MP,MPI) returns the starting locations locs of local discords of a time series from its matrix profile vector MP and matrix profile index vector MPI as computed by the matrixProfile command.

A local discord is defined as the subsequence that differs the most from the rest of the time series, based on its Euclidean distance from other subsequences in the time series. That is, the local discord is defined as the maximally different subsequence of data from the rest of the time series. matrixProfile determines these distances and findDiscord parses the results.

example

locs = findDiscord(___,Name=Value) specifies additional parameters using one or more name-value arguments in addition to the input arguments in previous syntaxes. For example, to limit the number of discords that findDiscord returns to 5, set MaxNumDiscords to 5.

example

Plot Top Discords

findDiscord(___) plots the location of the top discords on the matrix profile curve.

example

Examples

collapse all

Load the data, which consists of T1. T1 is a timetable containing armature current measurements of a degrading DC motor.

load matrix_profile_data T1

Specify the time series variable X to T1.MotorCurrent and the query segment length to 100.

X = T1.MotorCurrent;
len = 100;

Calculate the matrix profile.

[MP,MPI] = matrixProfile(X,len);

Plot the matrix profile.

matrixProfile(X,len)

Matrix Profile Plots. The Time-Series plot is on the top. Overlays of yellow and purple on the plotted data show the two top motif pairs and the discord. The Matrix Profile plot, which plots the distances, is in the middle. The Subsequences plot is on the bottom, and shows the subsequences for the top two motif pairs and the discord together.

The profile shows the two top motif pairs, or segments that agree best with their neighbors, occur at locations 6717 and 3119. These locations are consistent with minima in the matrix profile plot.

The profile also shows a single discord at location 9797. This subsequence visibly deviates from the motif subsequences for much of its length.

Use findDiscord to find more discords, which are the locations of segments with the furthest distances from their neighbors. Show the top four locations.

locs = findDiscord(MP,MPI);
toplocs = locs(1:4)
toplocs = 4×1

        9797
        9800
        9802
        9792

Show the corresponding distances.

topdist = MP(toplocs)
topdist = 4×1

    8.3894
    8.2062
    8.1517
    7.9777

Plot the findDiscord results.

findDiscord(MP,MPI)

findDiscord Plots. The Time-Series plot is on the top. The Matrix Profile plot is in the middle. The Matrix Profile Discord plot is on the bottom. This plot shows a number of discords that are overlapping or close together.

Discords that are close to each other are probably part of the same anomaly. You need to identify only one discord for such a segment. Improve the segment separation and limit the number of discords to 10.

findDiscord(MP,MPI,MinSeparation=40,MaxNumDiscords=10)

findDiscord Plots. The Time-Series plot is on the top. The Matrix Profile plot is in the middle. The Matrix Profile Discord plot is on the bottom, and now shows discrete discord instances.

The highest discord is at location 9797, as the original matrix profile showed. The plot also shows significant discords in other locations.

Input Arguments

collapse all

Matrix profile containing the z-normalized Euclidean distances between each subsequence of a specified length and all other subsequences in the time series, specified as a vector. MP is an output of the matrixProfile command.

Matrix profile index containing the indices of the starting locations of the subsequences that correspond to each distance value in MP. MPI is an output of the matrixProfile command.

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: loc = findDiscord(MP,MPI,MaxNumDiscords=5) limits the number of discords that findDiscord returns to 5.

Minimum separation between discords, specified as a nonnegative scalar. When MinSeparation is greater than its default value of 0, findDiscord selects only the largest local discords in the matrix profile and ignores all other discords within the specified separation distance.

Maximum number of discords to find, specified as a positive integer scalar. finddiscord returns the discords in descending order of importance, from the largest to the smallest values of the matrix profile vector. If MaxNumDiscords is not specified, finddiscord returns all discords.

Output Arguments

collapse all

Starting locations of discords in MP, specified as an integer vector. The elements of locs are sorted in order of importance, indicated by the discord distance.

Version History

Introduced in R2024b