WarpingCorrespondence

WarpingCorrespondence[s1,s2]

gives the time warping (DTW) similarity path between sequences s1 and s2.

WarpingCorrespondence[s1,s2,win]

uses a window specified by win for local search.

Details and Options

• WarpingCorrespondence is also known as dynamic time warping.
• WarpingCorrespondence returns {{n1,,nk},{m1,,mk}} of nondecreasing positions such that s1ni correspond to s2mi.
• The returned positions attempt to minimize the distance over all possible such positions, and with the constraint that all elements of s1 and s2 are represented as some s1ni and s2mj, respectively.
• Compute the effective distance using WarpingDistance.
• The sequences si can be lists of numeric or Boolean scalars or vectors.
• Possible settings for the search window win are:
•  Automatic a full search r a slanted band window of radius {"SlantedBand",r} a slanted band window of radius {"Band",r} band window of radius (Sakoe-Chiba) {"Parallelogram",a} parallelogram window placed at origin with slopes and (Itakura)
• A smaller typically gives a faster but less optimal result. If , then has no effect.
• The following options are supported:
•  DistanceFunction Automatic the distance function to be used Method Automatic the variant of DTW to use
• WarpingCorrespondence accepts a option with settings:
•  Automatic automatically determine distance function EuclideanDistance Euclidean distance ManhattanDistance Manhattan or "city block" distance BinaryDistance 0 if elements are equal; 1 otherwise ChessboardDistance Chebyshev or sup norm distance SquaredEuclideanDistance squared Euclidean distance NormalizedSquaredEuclideanDistance normalized squared Euclidean distance CosineDistance angular cosine distance CorrelationDistance correlation coefficient distance BrayCurtisDistance Total[Abs[u-v]]/Total[Abs[u+v]] CanberraDistance Total[Abs[u-v]/(Abs[u]+Abs[v])] MatchingDissimilarity matching dissimilarity between Boolean vectors
• By default, the following distance functions are used:
•  EuclideanDistance numeric data MatchingDissimilarity Boolean data
• Using , all elements of s2 are matched with all elements of s1.
• Using Method->{"MatchingInterval"match}, s2 can be matched with a subsequence of s1. Possible settings for match include:
•  Automatic a full match "Flexible" flexible at both ends "FlexibleEnd" flexible only at the end of the interval

Examples

open allclose all

Basic Examples(1)

Find the time warping correspondence between two sequences:

Plot the correspondence between indices:

Find the time warped versions:

The warped versions are approximately equal:

Scope(9)

Data(6)

Find the time warping correspondence between two real-valued vectors:

Find the time warping correspondence between two sequences of vectors:

Find the time warping correspondence between two Boolean vectors:

Sequences of Boolean-valued vectors:

Sequences of quantities with compatible units:

Two-dimensional quantity arrays:

Search Window(3)

By default, the search is not locally constrained:

Specify a radius for the search window:

A search radius of 2 allows you to find the optimal alignment:

Use a band of radius 1:

Use a parallelogram of slope 3:

For signals of equal length, the "Band" window is equivalent to the "SlantedBand" window:

Options(4)

DistanceFunction(3)

With Boolean sequences, WarpingCorrespondence uses MatchingDissimilarity:

Find correspondences between two sequences using different distance functions:

In case of one-dimensional signals, some distance functions are equivalent:

Euclidean, Manhattan, and the chessboard distance are always the same:

Normalized Euclidean distance and correlation distance are the same:

For Boolean data, matching dissimilarity and binary distance are the same:

Method(1)

Compare the result of full search to a flexible search:

Visually compare the results:

Applications(2)

Visualize the time warping correspondence by drawing lines between corresponding points:

Apply it to some data:

Compare the first quarter of 2017 of the HPQ stock prices with historical data from 2010 to 2016:

Get historic data:

Find the best matching subsequence of historical data:

Detect the historical interval most similar to quarter one of 2017:

Visually compare recent data and the best historical match:

Predict the stock prices for the next 30 days based on historical data:

Properties & Relations(7)

The two sequences need not have the same length:

The warping path of two equal sequences goes along a diagonal line:

Smaller values of the search window radius emphasize speed of computation:

There may be a tradeoff with quality of the computation:

When computing the full correspondence, WarpingCorrespondence is symmetric:

The function is not symmetric when matching subsequences:

Adding to or subtracting from values of one sequence may result in a different correspondence:

Adding to or subtracting from both sequences will not affect the result when distance function is induced by a norm (translation invariant):

This is true for Euclidean, Manhattan, and some more:

Using distance functions that are not translation invariant may produce different correspondence:

Relation with WarpingDistance:

Find the time warped sequences using the correspondence:

WarpingDistance gives the sum of all the distances between corresponding elements:

Possible Issues(3)

All elements in the two sequences must be commensurate:

Elements in the two sequences should be of the same type:

If the specified window is too narrow to find a correspondence, a larger window is automatically used:

Wolfram Research (2016), WarpingCorrespondence, Wolfram Language function, https://reference.wolfram.com/language/ref/WarpingCorrespondence.html.

Text

Wolfram Research (2016), WarpingCorrespondence, Wolfram Language function, https://reference.wolfram.com/language/ref/WarpingCorrespondence.html.

CMS

Wolfram Language. 2016. "WarpingCorrespondence." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/WarpingCorrespondence.html.

APA

Wolfram Language. (2016). WarpingCorrespondence. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WarpingCorrespondence.html

BibTeX

@misc{reference.wolfram_2024_warpingcorrespondence, author="Wolfram Research", title="{WarpingCorrespondence}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/WarpingCorrespondence.html}", note=[Accessed: 17-July-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_warpingcorrespondence, organization={Wolfram Research}, title={WarpingCorrespondence}, year={2016}, url={https://reference.wolfram.com/language/ref/WarpingCorrespondence.html}, note=[Accessed: 17-July-2024 ]}