WarpingDistance
Details and Options



- WarpingDistance gives the minimal distance for any correspondence between the reference sequence s1 and the query sequence s2.
- The distance is given by
, where s1〚ni〛 and s2〚mi〛 are corresponding elements.
- Compute the effective correspondence using WarpingCorrespondence.
- 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 - WarpingDistance accepts a DistanceFunctiond 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 Method->Automatic, 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 allBasic Examples (1)Summary of the most common use cases
Scope (10)Survey of the scope of standard use cases
Data (7)
Find the time warping distance between two real-valued vectors:

https://wolfram.com/xid/0bc63utsee9zifm-k639lv

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

https://wolfram.com/xid/0bc63utsee9zifm-vftgtj

https://wolfram.com/xid/0bc63utsee9zifm-nzbrvi

Show the correspondence between the sequences:

https://wolfram.com/xid/0bc63utsee9zifm-kkfpw7

Find the time warping distance between two Boolean vectors:

https://wolfram.com/xid/0bc63utsee9zifm-uxok45


https://wolfram.com/xid/0bc63utsee9zifm-vw8iqp


https://wolfram.com/xid/0bc63utsee9zifm-by8gpk

Sequences of Boolean-valued vectors:

https://wolfram.com/xid/0bc63utsee9zifm-xz644a

https://wolfram.com/xid/0bc63utsee9zifm-w482wo

Sequences of quantities with compatible units:

https://wolfram.com/xid/0bc63utsee9zifm-mqt072

https://wolfram.com/xid/0bc63utsee9zifm-g4ussc

All units are converted to base SI units:

https://wolfram.com/xid/0bc63utsee9zifm-bulhww

Two-dimensional quantity arrays:

https://wolfram.com/xid/0bc63utsee9zifm-9hl3wz


https://wolfram.com/xid/0bc63utsee9zifm-3zzrt4


https://wolfram.com/xid/0bc63utsee9zifm-lyzqtd

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

https://wolfram.com/xid/0bc63utsee9zifm-t63o31

https://wolfram.com/xid/0bc63utsee9zifm-sa985d

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

https://wolfram.com/xid/0bc63utsee9zifm-7868fq

Search Window (3)
By default, the search is not locally constrained:

https://wolfram.com/xid/0bc63utsee9zifm-sg6rii

https://wolfram.com/xid/0bc63utsee9zifm-0ssudd


https://wolfram.com/xid/0bc63utsee9zifm-oo5tn9

Specify a radius for the search window:

https://wolfram.com/xid/0bc63utsee9zifm-l3ll0

Increase the radius to find a more optimal alignment:

https://wolfram.com/xid/0bc63utsee9zifm-lheg5a

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

https://wolfram.com/xid/0bc63utsee9zifm-cyze5m


https://wolfram.com/xid/0bc63utsee9zifm-i4tkpv

https://wolfram.com/xid/0bc63utsee9zifm-c3cgs

Use a parallelogram of slope 3:

https://wolfram.com/xid/0bc63utsee9zifm-b83fy6

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

https://wolfram.com/xid/0bc63utsee9zifm-ec6w55

https://wolfram.com/xid/0bc63utsee9zifm-hht6a8

Generalizations & Extensions (1)Generalized and extended use cases
Compute DTW-Delta (or DTW-D) by normalizing DTW by the Euclidean distance of sequences:

https://wolfram.com/xid/0bc63utsee9zifm-e9gays
Comparing a sine wave, a distorted sine wave, and a random noise using DTW:

https://wolfram.com/xid/0bc63utsee9zifm-3obxg0

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

https://wolfram.com/xid/0bc63utsee9zifm-zvjwze


https://wolfram.com/xid/0bc63utsee9zifm-5hscww

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

https://wolfram.com/xid/0bc63utsee9zifm-ntzf1d

Options (6)Common values & functionality for each option
DistanceFunction (5)
With Boolean sequences, WarpingDistance uses MatchingDissimilarity:

https://wolfram.com/xid/0bc63utsee9zifm-1ofaka

https://wolfram.com/xid/0bc63utsee9zifm-6teu7z


https://wolfram.com/xid/0bc63utsee9zifm-dh6s7c

Compare two sequences using different distance functions:

https://wolfram.com/xid/0bc63utsee9zifm-ikif28

https://wolfram.com/xid/0bc63utsee9zifm-9y0te

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

https://wolfram.com/xid/0bc63utsee9zifm-ta5zbe

https://wolfram.com/xid/0bc63utsee9zifm-w8fyrf


https://wolfram.com/xid/0bc63utsee9zifm-f79u0n


https://wolfram.com/xid/0bc63utsee9zifm-cb00zk

https://wolfram.com/xid/0bc63utsee9zifm-oemoud

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

https://wolfram.com/xid/0bc63utsee9zifm-dcxpfl

https://wolfram.com/xid/0bc63utsee9zifm-bx6sw


https://wolfram.com/xid/0bc63utsee9zifm-dmruwr

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

https://wolfram.com/xid/0bc63utsee9zifm-b68o6i

https://wolfram.com/xid/0bc63utsee9zifm-3vp5nc

Method (1)
By default, the query sequence will be matched with the entire reference sequence:

https://wolfram.com/xid/0bc63utsee9zifm-rjldr5

https://wolfram.com/xid/0bc63utsee9zifm-zqjyih

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

https://wolfram.com/xid/0bc63utsee9zifm-zmawxq

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

https://wolfram.com/xid/0bc63utsee9zifm-zp8lao

Applications (6)Sample problems that can be solved with this function
Cluster time series of normalized stock values:

https://wolfram.com/xid/0bc63utsee9zifm-8dvqyv

https://wolfram.com/xid/0bc63utsee9zifm-0zmwng

Find the nearest stock based on normalized stock values:

https://wolfram.com/xid/0bc63utsee9zifm-3ykokt

https://wolfram.com/xid/0bc63utsee9zifm-jz29t3

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:

https://wolfram.com/xid/0bc63utsee9zifm-keceww
Get the temperature for all capital cities in the European Union:

https://wolfram.com/xid/0bc63utsee9zifm-v6m2gh


https://wolfram.com/xid/0bc63utsee9zifm-zt3ldt
Find the capital city that has the most similar temperatures to Chicago:

https://wolfram.com/xid/0bc63utsee9zifm-sz3lwd

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

https://wolfram.com/xid/0bc63utsee9zifm-vj1tme


https://wolfram.com/xid/0bc63utsee9zifm-hleri4

https://wolfram.com/xid/0bc63utsee9zifm-57zhti

https://wolfram.com/xid/0bc63utsee9zifm-f9n73v

Visualize the temperature similarity using a previously computed distance matrix:

https://wolfram.com/xid/0bc63utsee9zifm-47r6ne

Compare daily mean humidity for some cities in 2014:

https://wolfram.com/xid/0bc63utsee9zifm-8fmf8o

Extract humidity of the cities:

https://wolfram.com/xid/0bc63utsee9zifm-hqub3b

https://wolfram.com/xid/0bc63utsee9zifm-dip99x

Compare two ECG signals of heartbeats:

https://wolfram.com/xid/0bc63utsee9zifm-eddq3v

Find the distance between the two signals:

https://wolfram.com/xid/0bc63utsee9zifm-e35xj5

Properties & Relations (8)Properties of the function, and connections to other functions
The two sequences need not have the same length:

https://wolfram.com/xid/0bc63utsee9zifm-rk7mnt

The distance between two equal sequences is always 0:

https://wolfram.com/xid/0bc63utsee9zifm-87tyjr

Relation with WarpingCorrespondence:

https://wolfram.com/xid/0bc63utsee9zifm-rwm58t

https://wolfram.com/xid/0bc63utsee9zifm-3ih6b1
Find the time warped sequences using the correspondence:

https://wolfram.com/xid/0bc63utsee9zifm-z9idpu
WarpingDistance gives the sum of all the distances between corresponding elements:

https://wolfram.com/xid/0bc63utsee9zifm-2xvltj

Smaller window radius results in faster computation:

https://wolfram.com/xid/0bc63utsee9zifm-udwdjx

https://wolfram.com/xid/0bc63utsee9zifm-r7xql

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

https://wolfram.com/xid/0bc63utsee9zifm-yod0tl

WarpingDistance is a symmetric function:

https://wolfram.com/xid/0bc63utsee9zifm-cs6o1

The "triangle inequality" does not hold:

https://wolfram.com/xid/0bc63utsee9zifm-xylps8

https://wolfram.com/xid/0bc63utsee9zifm-7ogzxe

Dynamic time warping is not translation invariant:

https://wolfram.com/xid/0bc63utsee9zifm-qg9yrx

https://wolfram.com/xid/0bc63utsee9zifm-p8v1z0


https://wolfram.com/xid/0bc63utsee9zifm-uhubw0

Canonical time warping is translation invariant:

https://wolfram.com/xid/0bc63utsee9zifm-p6sm2u


https://wolfram.com/xid/0bc63utsee9zifm-w2lssc

The time warping distance increases for longer signals:

https://wolfram.com/xid/0bc63utsee9zifm-w4hiky



https://wolfram.com/xid/0bc63utsee9zifm-52o9kz


Normalization allows a more reasonable comparison:

https://wolfram.com/xid/0bc63utsee9zifm-o7llsz


https://wolfram.com/xid/0bc63utsee9zifm-3t718w

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

https://wolfram.com/xid/0bc63utsee9zifm-n4rdw8


https://wolfram.com/xid/0bc63utsee9zifm-na3fh6

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:

https://wolfram.com/xid/0bc63utsee9zifm-ybs66a


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

https://wolfram.com/xid/0bc63utsee9zifm-uep9ps


https://wolfram.com/xid/0bc63utsee9zifm-9e2v3u

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

https://wolfram.com/xid/0bc63utsee9zifm-idwshy


https://wolfram.com/xid/0bc63utsee9zifm-tfo25s

Divide by the length of signals:

https://wolfram.com/xid/0bc63utsee9zifm-jhk7im


https://wolfram.com/xid/0bc63utsee9zifm-2ico1r

Divide by the length of the correspondence path:

https://wolfram.com/xid/0bc63utsee9zifm-m3x44c


https://wolfram.com/xid/0bc63utsee9zifm-k1zgn5

Quantities in input sequences must have compatible units:

https://wolfram.com/xid/0bc63utsee9zifm-64r3v0

https://wolfram.com/xid/0bc63utsee9zifm-h1t42l


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
]}
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
]}