Patterns

patterns.calc_cost(cl1_len, cl2_len, num_cl1, num_cl2)[source]

Assign a cost to a pattern based on if the majority of its occurances are observed in regions of a time series that are annotated with the same binary label. The cost calculation takes into account a possible difference in the total lengths of the segments.

Args:

cl1_len: Total length of the time series that belong to the class 1. cl2_len: Total length of the time series that belong to the class 2. num_cl1: Number of occurances of the pattern in regions that belong to cl1. num_cl2: Number of occurances of the pattern in regions that belong to cl2.

Return: The label name of the region that the pattern is contained in, as well as the normalized number of

occurences.

patterns.calculate_motif_stats(p, mask, k, m, ez, radius, segment_labels)[source]

Calculate some useful statistics for the motifs found.

Args:

p: A profile object as it is defined in the matrixprofile foundation python library. mask: Binary mask used to annotate the time series. m: The window size (length of the motif). ez: The exclusion zone used. radius: The radius that has been used in the experiment. segment_labels: List of the two labels that characterize the time series.

Return: List of the statistics

patterns.compute_mp_av(mp, index, m, df, k)[source]

Given a matrix profile, a matrix profile index, the window size and the DataFrame that contains the timeseries. Create a matrix profile object and add the corrected matrix profile after applying the complexity av. Uses an extended version of the apply_av function from matrixprofile foundation that is compatible with multi-dimensional timeseries. The implementation can be found here (https://github.com/MORE-EU/matrixprofile/blob/master/matrixprofile/transform.py)

Args:

mp: A matrix profile. index: The matrix profile index that accompanies the matrix profile. window: The subsequence window size. ts: The timeseries that was used to calculate the matrix profile.

Return:

Updated profile with an annotation vector

patterns.pattern_loc(start, end, mask, segment_labels)[source]

Considering that a time series is characterized by regions belonging to two different labels.

Args:

start: The starting index of the pattern. end: The ending index of the pattern. mask: Binary mask used to annotate the time series. segment_labels: List of the two labels that characterize the time series.

Return: The label name of the region that the pattern is contained in.

patterns.pick_subspace_columns(df, mps, idx, k, m, include)[source]

Given a multi-dimensional time series as a pandas Dataframe, keep only the columns that have been used for the creation of the k-dimensional matrix profile.

Args:

df: The DataFrame that contains the multidimensional time series. mps: The multi-dimensional matrix profile. Each row of the array corresponds to each matrix profile for a given dimension (i.e., the first row is the 1-D matrix profile and the second row is the 2-D matrix profile). idx: The multi-dimensional matrix profile index where each row of the array corresponds to each matrix profile index for a given dimension. k: If mps and idx are one-dimensional k can be used to specify the given dimension of the matrix profile. The default value specifies the 1-D matrix profile. If mps and idx are multi-dimensional, k is ignored. m: The subsequence window size. Should be the same as the one used to create the multidimensional matrix profile that is the input. include: A list of the column names that must be included in the constrained multidimensional motif search.

Return:

The list of subspace columns

patterns.to_mpf(mp, index, window, ts)[source]

Using a matrix profile, a matrix profile index, the window size and the timeseries used to calculate the previous, create a matrix profile object that is compatible with the matrix profile foundation library (https://github.com/matrix-profile-foundation/matrixprofile). This is useful for cases where another library was used to generate the matrix profile.

Args:

mp: A matrix profile. index: The matrix profile index that accompanies the matrix profile. window: The subsequence window size. ts: The timeseries that was used to calculate the matrix profile.

Return:

The Matrixprofile structure