WOLFRAM

gives the dynamic time warping (DTW) distance between sequences s1 and s2.

WarpingDistance[s1,s2,win]

uses a window specified by win for local search.

Details and Options

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Find the time warping distance between two sequences of values:

Out[1]=1

Show the correspondence between the sequences:

Out[2]=2

Scope  (10)Survey of the scope of standard use cases

Data  (7)

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

Out[1]=1

Find the time warping distance between two sequences of 2D points:

Out[2]=2

Show the correspondence between the sequences:

Out[3]=3

Find the time warping distance between two Boolean vectors:

Out[1]=1
Out[2]=2
Out[3]=3

Sequences of Boolean-valued vectors:

Out[2]=2

Sequences of quantities with compatible units:

Out[2]=2

All units are converted to base SI units:

Out[3]=3

Two-dimensional quantity arrays:

Out[1]=1
Out[2]=2
Out[3]=3

Find the distance between a sequence of quantities and a sequence of scalars:

Out[2]=2

The scalars are interpreted as if they had a compatible unit from SI base units:

Out[3]=3

Search Window  (3)

By default, the search is not locally constrained:

Out[5]=5
Out[6]=6

Specify a radius for the search window:

Out[7]=7

Increase the radius to find a more optimal alignment:

Out[8]=8

A window size is interpreted as the radius of a slanted band window:

Out[9]=9

Use a band of radius 1:

Out[2]=2

Use a parallelogram of slope 3:

Out[3]=3

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

Out[2]=2

Generalizations & Extensions  (1)Generalized and extended use cases

Compute DTW-Delta (or DTW-D) by normalizing DTW by the Euclidean distance of sequences:

Comparing a sine wave, a distorted sine wave, and a random noise using DTW:

Out[4]=4

Using regular DTW, the sine wave seems to be more similar to the random noise:

Out[26]=26

Using DTW-Delta, the sine wave is more similar to the distorted sine wave:

Options  (6)Common values & functionality for each option

DistanceFunction  (5)

With Boolean sequences, WarpingDistance uses MatchingDissimilarity:

Out[3]=3
Out[4]=4

Compare two sequences using different distance functions:

Out[2]=2

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

Out[2]=2
Out[3]=3
Out[5]=5

In case of one-dimensional signals, NormalizedSquaredEuclideanDistance and CorrelationDistance always return 0:

Out[2]=2
Out[3]=3

For signals containing one element, time warping distance is equal to the distance between elements:

Out[2]=2

Method  (1)

By default, the query sequence will be matched with the entire reference sequence:

Out[3]=3

With "MatchingInterval""FlexibleEnd", any suffix of reference sequence can be omitted:

Out[17]=17

With "MatchingInterval""Flexible", any suffix and prefix of reference can be omitted:

Out[18]=18

Applications  (6)Sample problems that can be solved with this function

Cluster time series of normalized stock values:

Out[3]=3

Find the nearest stock based on normalized stock values:

Out[2]=2

Find the capital city in the EU that had the most similar temperature to Chicago over the last year. Use WarpingDistance to determine the similarity between temperature sequences:

Get the temperature for all capital cities in the European Union:

Out[2]=2

Find the capital city that has the most similar temperatures to Chicago:

Out[4]=4

Compute pairwise distances between temperature time series of all EU capitals:

Out[1]=1
Out[4]=4

Visualize the temperature similarity using a previously computed distance matrix:

Out[5]=5

Compare daily mean humidity for some cities in 2014:

Out[1]=1

Extract humidity of the cities:

Compare extracted data:

Out[3]=3

Compare two ECG signals of heartbeats:

Out[1]=1

Find the distance between the two signals:

Out[2]=2

Properties & Relations  (8)Properties of the function, and connections to other functions

The two sequences need not have the same length:

Out[1]=1

The distance between two equal sequences is always 0:

Out[1]=1

Relation with WarpingCorrespondence:

Find the time warped sequences using the correspondence:

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

Out[4]=4

Smaller window radius results in faster computation:

Out[2]=2

However, using smaller radius may lead to a less optimal alignment, resulting in higher distance values:

Out[3]=3

WarpingDistance is a symmetric function:

Out[1]=1

The "triangle inequality" does not hold:

Out[2]=2

Dynamic time warping is not translation invariant:

Out[2]=2
Out[3]=3

Canonical time warping is translation invariant:

Out[4]=4
Out[5]=5

The time warping distance increases for longer signals:

Out[1]=1
Out[1]=1
Out[2]=2
Out[2]=2

Normalization allows a more reasonable comparison:

Out[3]=3
Out[4]=4

Dividing by the length of the correspondence path is also a common way of normalization:

Out[5]=5
Out[6]=6

Possible Issues  (3)Common pitfalls and unexpected behavior

The search window specified may be too narrow to contain a correspondence path. In that case it will be automatically widened:

Out[3]=3

Two long, similar signals could have a higher distance compared to two short, dissimilar signals:

Out[1]=1
Out[2]=2

Comparing two short, random sequences, which gives a relatively smaller distance:

Out[3]=3
Out[4]=4

Divide by the length of signals:

Out[5]=5
Out[6]=6

Divide by the length of the correspondence path:

Out[7]=7
Out[8]=8

Quantities in input sequences must have compatible units:

Out[2]=2
Wolfram Research (2016), WarpingDistance, Wolfram Language function, https://reference.wolfram.com/language/ref/WarpingDistance.html.
Wolfram Research (2016), WarpingDistance, Wolfram Language function, https://reference.wolfram.com/language/ref/WarpingDistance.html.

Text

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

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

CMS

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

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

APA

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

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

BibTeX

@misc{reference.wolfram_2025_warpingdistance, author="Wolfram Research", title="{WarpingDistance}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/WarpingDistance.html}", note=[Accessed: 06-June-2025 ]}

@misc{reference.wolfram_2025_warpingdistance, author="Wolfram Research", title="{WarpingDistance}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/WarpingDistance.html}", note=[Accessed: 06-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_warpingdistance, organization={Wolfram Research}, title={WarpingDistance}, year={2016}, url={https://reference.wolfram.com/language/ref/WarpingDistance.html}, note=[Accessed: 06-June-2025 ]}

@online{reference.wolfram_2025_warpingdistance, organization={Wolfram Research}, title={WarpingDistance}, year={2016}, url={https://reference.wolfram.com/language/ref/WarpingDistance.html}, note=[Accessed: 06-June-2025 ]}