Distances

Lockstep Distances

tssearch.distances.lockstep_distances.braycurtis_distance(x, y, weight=None)[source]

Computes the Braycurtis distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Braycurtis distance value.

Return type:

float

tssearch.distances.lockstep_distances.canberra_distance(x, y, weight=None)[source]

Computes the Canberra distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Canberra distance value.

Return type:

float

tssearch.distances.lockstep_distances.chebyshev_distance(x, y, weight=None)[source]

Computes the Chebyshev distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Chebyshev distance value.

Return type:

float

tssearch.distances.lockstep_distances.correlation_distance(x, y, weight=None)[source]

Computes the correlation distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Correlation distance value.

Return type:

float

tssearch.distances.lockstep_distances.cosine_distance(x, y, weight=None)[source]

Computes the cosine distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Cosine distance value.

Return type:

float

tssearch.distances.lockstep_distances.euclidean_distance(x, y, weight=None)[source]

Computes the Euclidean distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Euclidean distance value.

Return type:

float

tssearch.distances.lockstep_distances.hamming_distance(x, y, weight=None)[source]

Computes the Hamming distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Hamming distance value.

Return type:

float

tssearch.distances.lockstep_distances.mahalanobis_distance(x, y, weight=None)[source]

Computes the Mahalanobis distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Mahalanobis distance value.

Return type:

float

tssearch.distances.lockstep_distances.manhattan_distance(x, y, weight=None)[source]

Computes the Manhattan distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Manhattan distance value.

Return type:

float

tssearch.distances.lockstep_distances.minkowski_distance(x, y, weight=None, p=3)[source]

Computes the Minkowski distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
  • p (int) – Lp norm distance degree.
Returns:

Minkowski distance value.

Return type:

float

tssearch.distances.lockstep_distances.pearson_correlation(x, y, beta=None)[source]

Computes the Pearson correlation between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • beta (float) – Beta coefficient.
Returns:

Pearson correlation value.

Return type:

float

tssearch.distances.lockstep_distances.short_time_series_distance(x, y, tx=None, ty=None)[source]

Computes the short time series distance (STS) between two time series.

Reference: Möller-Levet, C. S., Klawonn, F., Cho, K., and Wolkenhauer, O. (2003).

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • tx (nd-array) – Sampling index of time series x.
  • ty (nd-array) – Sampling index of time series y.
Returns:

Short time series distance value.

Return type:

float

tssearch.distances.lockstep_distances.sqeuclidean_distance(x, y, weight=None)[source]

Computes the squared Euclidean distance between two time series.

If the time series do not have the same length, an interpolation is performed.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
  • weight (nd-array (Default: None)) – query weight values.
Returns:

Squared Euclidean distance value.

Return type:

float

Elastic Distances

tssearch.distances.elastic_distances.dlp(x, y, p=2)[source]

Computes Lp norm distance between two time series.

Parameters:
  • x (nd-array) – Time series x (query).
  • y (nd-array) – Time series y.
  • p (int) – Lp norm distance degree for local cost computation.
Returns:

Return type:

The Lp distance.

tssearch.distances.elastic_distances.dtw(x, y, weight=None, **kwargs)[source]

Computes Dynamic Time Warping (DTW) of two time series.

Parameters:
  • x (nd-array) – Time series x (query).
  • y (nd-array) – Time series y.
  • dist (function) – The distance used as a local cost measure. None defaults to the squared euclidean distance.
  • **kwargs
  • below (See) –
  • do_sign_norm (bool) -- (*) – If True the signals will be normalized before computing the DTW, (default: False)
  • do_dist_norm (bool) -- (*) – If True the DTW distance will be normalized by dividing the summation of the path dimension. (default: True)
  • window (String) -- (*) – Selects the global window constrains. Available options are None and sakoe-chiba. (default: None)
  • factor (Float) -- (*) – Selects the global constrain factor. (default: min(xl, yl) * .50)
Returns:

  • d (float) – The DTW distance.
  • ac (nd-array) – The accumulated cost matrix.
  • path (nd-array) – The optimal warping path between the two sequences.

tssearch.distances.elastic_distances.lcss(x, y, eps=1, **kwargs)[source]

Computes the Longest Common Subsequence (LCSS) distance between two numeric time series.

Parameters:
  • x (nd-array) – Time series x (query).
  • y (nd-array) – Time series y.
  • eps (float) – Amplitude matching threshold.
  • **kwargs
  • below (See) –
  • window (String) -- (*) – Selects the global window constrains. Available options are None and sakoe-chiba. (default: None)
Returns:

  • d (float) – The LCSS distance.
  • ac (nd-array) – The similarity matrix.
  • path (nd-array) – The optimal path between the two sequences.

tssearch.distances.elastic_distances.twed(x, y, tx, ty, nu=0.001, lmbda=1.0, p=2, report='distance')[source]

Computes Time Warp Edit Distance (TWED) of two time series.

Reference :
Marteau, P.; F. (2009). “Time Warp Edit Distance with Stiffness Adjustment for Time Series Matching”. IEEE Transactions on Pattern Analysis and Machine Intelligence. 31 (2): 306–318. arXiv:cs/0703033 http://people.irisa.fr/Pierre-Francois.Marteau/
Parameters:
  • x (nd-array) – Time series x (query).
  • y (nd-array) – Time series y.
  • tx (nd-array) – Time stamp time series x.
  • ty (nd-array) – Time stamp time series y.
  • nu (int) –
    Stiffness parameter (nu >= 0)
    nu = 0, TWED distance measure on amplitude. nu > 0, TWED distance measure on amplitude x time.
  • lmbda (int) – Penalty for deletion operation (lmbda >= 0).
  • p (int) – Lp norm distance degree for local cost computation.
  • report (str) – distance, cost matrix, path.
Returns:

  • d (float) – The TWED distance.
  • ac (nd-array) – The accumulated cost matrix.
  • path (nd-array) – The optimal warping path between the two sequences.

Time Distances

tssearch.distances.time_distances.tam(x, y)[source]

Calculates the Time Alignment Measurement (TAM) based on an optimal warping path between two time series.

Reference: Folgado et. al, Time Alignment Measurement for Time Series, 2016.

Parameters:
  • x (nd-array) – Time series x.
  • y (nd-array) – Time series y.
Returns:

  • In case report=instants the number of indexes in advance, delay and phase
  • will be returned.
  • For report=ratios, the ratio of advance, delay and phase.
  • will be returned. In case report=distance, only the TAM will be returned.