Namespace Matrix

namespace khivamatrix

Functions

af::array khiva::matrixslidingDotProduct(af::array q, af::array t)

Calculates the sliding dot product of the time series ‘q’ against t.

Return
array Returns an array with as many elements as ‘t’ in the first dimension and as many elements as the last dimension of ‘q’ in the last dimension.
Parameters
  • q: Array whose first dimension is the length of the query time series and the last dimension is the number of time series to calculate.
  • t: Array with the second time series in the first dimension.

void khiva::matrixmeanStdev(af::array t, af::array &a, long m, af::array &mean, af::array &stdev)

Calculates the moving average and standard deviation of the time series ‘t’.

Parameters
  • t: Input time series. Multiple time series.
  • a: Auxiliary array to be used in the function calculateDistanceProfile. Use the overloaded method without this parameter.
  • m: Window size.
  • mean: Output array containing the moving average.
  • stdev: Output array containing the moving standard deviation.

void khiva::matrixmeanStdev(af::array t, long m, af::array &mean, af::array &stdev)

Calculates the moving average and standard deviation of the time series ‘t’.

Parameters
  • t: Input time series. Multiple time series.
  • m: Window size.
  • mean: Output array containing the moving average.
  • stdev: Output array containing the moving standard deviation.

af::array khiva::matrixgenerateMask(long m, long batchSize, long batchStart, long tsLength, long nTimeSeries = 1)

Function to generate a band matrix of batchSizeXtsLength with the offset batchStart.

Return
af::array With the resulting band.
Parameters
  • m: Subsequence length used to generate a band of m/2 at each side.
  • batchSize: Size of the first dimension.
  • batchStart: Offset of the band matrix.
  • tsLength: Size of the second dimension of the matrix.
  • nTimeSeries: Number of time series to generate the mask for.

void khiva::matrixcalculateDistanceProfile(af::array qt, af::array a, af::array sum_q, af::array sum_q2, af::array mean_t, af::array sigma_t, af::array mask, af::array &distance, af::array &index)

Calculates the distance between ‘q’ and the time series ‘t’, which produced the sliding. Multiple queries can be computed simultaneously in the last dimension of ‘q’.

Parameters
  • qt: The sliding dot product of ‘q’ and ‘t’.
  • a: Auxiliary array computed using the meanStdev function. This array contains a precomputed fixed value to speed up the distance calculation.
  • sum_q: Sum of the values contained in ‘q’.
  • sum_q2: Sum of squaring the values contained in ‘q’.
  • mean_t: Moving average of ‘t’ using a window size equal to the number of elements in ‘q’.
  • sigma_t: Moving standard deviation of ‘t’ using a window size equal to the number of elements in ‘q’.
  • mask: Mask band matrix to filter the trivial match of a subsequence with itself.
  • distance: Resulting minimal distance.
  • index: Position where the minimum is occurring.

void khiva::matrixcalculateDistanceProfile(af::array qt, af::array a, af::array sum_q, af::array sum_q2, af::array mean_t, af::array sigma_t, af::array &distance, af::array &index)

Calculates the distance between ‘q’ and the time series ‘t’, which produced the sliding. Multiple queries can be computed simultaneously in the last dimension of ‘q’.

Parameters
  • qt: The sliding dot product of ‘q’ and ‘t’.
  • a: Auxiliary array computed using the meanStdev function. This array contains a precomputed fixed value to speed up the distance calculation.
  • sum_q: Sum of the values contained in ‘q’.
  • sum_q2: Sum of squaring the values contained in ‘q’.
  • mean_t: Moving average of ‘t’ using a window size equal to the number of elements in ‘q’.
  • sigma_t: Moving standard deviation of ‘t’ using a window size equal to the number of elements in ‘q’.
  • distance: Resulting minimal distance.
  • index: Position where the minimum is occurring.

void khiva::matrixmass(af::array q, af::array t, af::array a, af::array mean_t, af::array sigma_t, af::array mask, af::array &distance, af::array &index)

Calculates the Mueen distance.

Parameters
  • q: Array whose first dimension is the length of the query time series and the last dimension is the number of time series to calculate.
  • t: Array with the second time series in the first dimension.
  • a: Auxiliary array computed using the meanStdev function. This array contains a precomputed fixed value to speed up the distance calculation.
  • mean_t: Moving average of ‘t’ using a window size equal to the number of elements in ‘q’.
  • sigma_t: Moving standard deviation of ‘t’ using a window size equal to the number of elements in ‘q’.
  • mask: Specifies the elements that should not be considered in the computation.
  • distance: Resulting minimal distance.
  • index: Position where the minimum is occurring.

void khiva::matrixmass(af::array q, af::array t, af::array a, af::array mean_t, af::array sigma_t, af::array &distance, af::array &index)

Calculates the Mueen distance.

Parameters
  • q: Array whose first dimension is the length of the query time series and the last dimension is the number of time series to calculate.
  • t: Array with the second time series in the first dimension.
  • a: Auxiliary array computed using the meanStdev function. This array contains a precomputed fixed value to speed up the distance calculation.
  • mean_t: Moving average of ‘t’ using a window size equal to the number of elements in ‘q’.
  • sigma_t: Moving standard deviation of ‘t’ using a window size equal to the number of elements in ‘q’.
  • distance: Resulting minimal distance.
  • index: Position where the minimum is occurring.

void khiva::matrixstomp(af::array ta, af::array tb, long m, af::array &profile, af::array &index)

STOMP algorithm to calculate the matrix profile between ‘ta’ and ‘tb’ using a subsequence length of ‘m’.

Parameters
  • ta: Query time series.
  • tb: Reference time series.
  • m: Subsequence length.
  • profile: The matrix profile, which reflects the distance to the closer element of the subsequence from ‘ta’ in ‘tb’.
  • index: The matrix profile index, which points to where the aforementioned minimum is located.

void khiva::matrixstomp(af::array t, long m, af::array &profile, af::array &index)

STOMP algorithm to calculate the matrix profile between ‘t’ and itself using a subsequence length of ‘m’. This method filters the trivial matches.

Parameters
  • t: Query and reference time series.
  • m: Subsequence length.
  • profile: The matrix profile, which reflects the distance to the closer element of the subsequence from ‘t’ in a different location of itself.
  • index: The matrix profile index, which points to where the aforementioned minimum is located.

void khiva::matrixfindBestNMotifs(af::array profile, af::array index, long n, af::array &motifs, af::array &motifsIndices, af::array &subsequenceIndices)

This function extracts the best N motifs from a previously calculated matrix profile.

Parameters
  • profile: The matrix profile containing the minimum distance of each subsequence.
  • index: The matrix profile index containing where each minimum occurs.
  • n: Number of motifs to extract.
  • motifs: The distance of the best N motifs.
  • motifsIndices: The indices of the best N motifs.
  • subsequenceIndices: The indices of the query sequences that produced the minimum reported in the motifs output array.

void khiva::matrixfindBestNDiscords(af::array profile, af::array index, long n, af::array &discords, af::array &discordsIndices, af::array &subsequenceIndices)

This function extracts the best N discords from a previously calculated matrix profile.

Parameters
  • profile: The matrix profile containing the minimum distance of each subsequence.
  • index: The matrix profile index containing where each minimum occurs.
  • n: Number of discords to extract.
  • discords: The distance of the best N discords.
  • discordsIndices: The indices of the best N discords.
  • subsequenceIndices: The indices of the query sequences that produced the discords reported in the discords output array.