Warping and elastic similarity#

Elastic similarity measures and time warping.

Sample-level DTW and its variants (dtw), edit distances, soft-DTW and kernels (elastic), segment-level correlation-based warping (segment_dtw), episode alignment (alignment), averaging (averaging), path diagnostics (diagnostics) and parameter learning (learning).

DTW and its variants, edit and kernel measures, soft-DTW, correlation-based and segment-level warping, episode alignment, averaging, diagnostics and learning.

Classes#

DTWResult(distance, path, cost_matrix, ...)

Distance, warping path and accumulated cost matrix of one alignment.

CBDTW([n_segments, n_components, statistic, ...])

Correlation-based dynamic time warping (Bankó and Abonyi, 2012).

PLADistance([n_segments, kind, weights, ...])

Dissimilarities of piecewise linear approximations: MPLA, SPLA and the mixed MDPLA measure (Bankó and Abonyi, 2015).

MixedSegmentDistance([weights, level_scale])

Weighted multivariate segment dissimilarity (a generalization of MDPLA).

SegmentModel(start, stop, mean, cov, ...)

Descriptor of one segment: location, level, trend and correlation structure.

ElasticEnsemble([metrics])

1-NN ensemble of elastic distances (after Lines and Bagnall, 2015).

Functions#

dtw(x, y[, window, metric, step, penalty, ...])

DTW distance of two (multivariate) series.

dtw_path(x, y[, window, metric, step, penalty])

Full DTW result: distance, optimal warping path (L, 2), local and accumulated cost matrices.

dtw_independent(x, y[, window, metric, step])

Independent multivariate DTW: the sum of the DTW distances of the variables, each warped separately (DTW_I).

ddtw(x, y[, window, metric, step])

Derivative DTW: DTW of the Keogh--Pazzani derivative estimates.

wdtw(x, y[, g, w_max, metric])

Weighted DTW: the local cost of cell (i, j) is multiplied by \(w_{max}/(1+\exp(-g(|i-j|-m_c)))\), where \(m_c\) is half of the length; large phase differences are penalized smoothly.

adtw(x, y[, penalty, metric])

Amerced DTW: every non-diagonal (warping) step costs an additional penalty (Herrmann and Webb, 2023).

shape_dtw(x, y[, width, descriptor, window, ...])

shapeDTW: DTW on local shape descriptors of every sample; the optimal path is used to accumulate the raw sample distances (Zhao and Itti, 2018).

fast_dtw(x, y[, radius, metric, min_size])

FastDTW (Salvador and Chan, 2007): project the path found at a coarser resolution, expand it by radius cells and refine.

lb_kim(x, y)

LB_Kim lower bound of DTW (squared Euclidean local cost): first and last samples.

lb_keogh(query, candidate, radius)

LB_Keogh lower bound of band-constrained DTW (squared Euclidean cost, equal lengths): the distance of the candidate from the envelope of the query.

subsequence_dtw(query, series[, metric, step])

Best warped match of query inside a longer series.

local_cost_matrix(x, y[, metric])

Local cost matrix C[i, j] = d(x_i, y_j).

window_mask(n, m[, window])

Admissible cells of the warping path.

lcss(x, y[, epsilon, delta])

LCSS distance \(1-LCSS/\min(T_x,T_y)\).

edr(x, y[, epsilon, normalize])

Edit distance on real sequences; with normalize divided by the longer length.

erp(x, y[, g])

Edit distance with real penalty; gaps cost the distance to the reference value g (scalar or vector).

twed(x, y[, nu, lam, tx, ty])

Time warp edit distance with stiffness nu and edit penalty lam; tx, ty are time stamps (default: sample indices).

msm(x, y[, c])

Move--split--merge distance with split/merge cost c; multivariate series are compared channel by channel (sum, the independent strategy of Shifaz et al., 2023).

soft_dtw(x, y[, gamma, metric])

Soft-DTW value \(\mathrm{dtw}_\gamma=-\gamma\log\sum_A e^{-\langle A,C\rangle/\gamma}\); tends to DTW as \(\gamma\to0\).

soft_dtw_alignment(x, y[, gamma, metric])

Soft-DTW value and the expected alignment matrix \(E=\nabla_C\,\mathrm{dtw}_\gamma(C)\): a fuzzy warping path whose entries are the probabilities that two samples are aligned under the Gibbs distribution over all alignments.

soft_dtw_divergence(x, y[, gamma])

Soft-DTW divergence \(\mathrm{dtw}_\gamma(x,y)-\tfrac12 (\mathrm{dtw}_\gamma(x,x)+\mathrm{dtw}_\gamma(y,y))\ge0\), zero iff \(x=y\) (Blondel et al., 2021).

gak(x, y[, sigma, triangular, normalize, log])

Global alignment kernel with a Gaussian local kernel.

ncc(x, y)

Coefficient-normalized cross-correlation sequence of two series (summed over the channels), computed with the FFT; length T_x+T_y-1.

sbd(x, y[, return_shift])

Shape-based distance \(1-\max_w NCC_w(x,y)\) of k-Shape (in [0, 2]); with return_shift also the optimal shift of y.

segment_models(X, segmentation[, ...])

Descriptors of the segments of X.

segment_local_cost(A, B[, local, weights, scale])

Local cost matrix between two sequences of segment models.

segment_dtw(A, B[, local, window, step, ...])

DTW over two sequences of segment models.

segpca_distance(x, y[, n_segments, n_components])

SEGPCA baseline: equal numbers of PCA-homogeneous segments compared index by index with \(1-s_{PCA}\) (no warping).

align(a, b, substitution[, gap, method, ...])

Pairwise alignment of two symbol sequences.

align_episodes(e1, e2[, gap, method, ...])

Alignment of two episode sequences (Balaskó, Bankó and Abonyi, 2007).

episode_distance(e1, e2, **kwargs)

Dissimilarity \(1-\text{score}/10\) of two episode sequences.

episode_dtw(e1, e2[, w_primitive, ...])

DTW over episode sequences (an mvtsa extension).

dba(collection[, n_iter, init, length, ...])

DTW barycenter averaging of a (multivariate) collection.

soft_dtw_barycenter(collection[, gamma, ...])

Soft-DTW barycenter by L-BFGS on the average's samples.

medoid(collection[, metric, return_index])

Medoid of a collection under any distance function.

path_statistics(path[, n, m])

Statistics of one warping path (L, 2).

tightness_of_warping(collection, path_fn[, ...])

Tightness of warping (ToW) of a data set under one local dissimilarity.

warping_function(path[, n])

Warping function \(\varphi(i)\): the mean index of the second series aligned to sample i of the first.

loo_1nn_accuracy(D, labels)

Leave-one-out 1-NN accuracy from a distance matrix.

learn_window(collection, labels[, ...])

Band width maximizing the LOO 1-NN accuracy (ties: the narrowest).

learn_segment_weights(model, collection, labels)

Grid search of the weights of a segment-level measure.

Constants#

STEP_PATTERNS

LOCAL_DISTANCES

Built-in immutable sequence.