Global constraints and windowing functions for DTW

Various global constraints (windows) which can be applied to the window.type argument of dtw, including the Sakoe-Chiba band, the Itakura parallelogram, and custom functions.

noWindow(iw, jw, ...); sakoeChibaWindow(iw,jw, window.size,...); slantedBandWindow(iw,jw,query.size,reference.size, window.size,...); itakuraWindow(iw,jw,query.size,reference.size, ...);
index in the query (row) -- automatically set
index in the reference (column) -- automatically set
size of the query time series -- automatically set
size of the reference time series -- automatically set
window size, used by some windowing functions -- must be set
a windowing function
additional arguments passed to windowing functions

Windowing functions can be passed to the window.type argument in dtw to put a global constraint to the warping paths allowed. They take two integer arguments (plus optional parameters) and must return a boolean value TRUE if the coordinates fall within the allowed region for warping paths, FALSE otherwise.
User-defined functions can read variables reference.size, query.size and window.size; these are pre-set upon invocation. Some functions require additional parameters which must be set (e.g. window.size). User-defined functions are free to implement any window shape, as long as at least one path is allowed between the initial and final alignment points, i.e., they are compatible with the DTW constraints.
The sakoeChibaWindow function implements the Sakoe-Chiba band, i.e. window.size elements around the main diagonal. If the window size is too small, i.e. if reference.size-query.size > window.size, warping becomes impossible.
An itakuraWindow global constraint is still provided with this package. See example below for a demonstration of the difference between a local the two.
The slantedBandWindow (package-specific) is a band centered around the (jagged) line segment which joins element [1,1] to element [query.size,reference.size], and will be window.size columns wide. In other words, the "diagonal" goes from one corner to the other of the possibly rectangular cost matrix, therefore having a slope of M/N, not 1.
dtwWindow.plot visualizes a windowing function. By default it plots a 200 x 220 rectangular region, which can be changed via reference.size and query.size arguments.


Windowing functions return TRUE if the coordinates passed as arguments fall within the chosen warping window, FALSE otherwise. User-defined functions should do the same.


Although dtwWindow.plot resembles object-oriented notation, there is not a such a dtwWindow class currently. A widely held misconception is that the "Itakura parallelogram" (as described in reference [2]) is a global constraint, i.e. a window. To the author's knowledge, it instead arises from the local slope restrictions imposed to the warping path, such as the one implemented by the typeIIIc step pattern.


[1] Sakoe, H.; Chiba, S., Dynamic programming algorithm optimization for spoken word recognition, Acoustics, Speech, and Signal Processing [see also IEEE Transactions on Signal Processing], IEEE Transactions on , vol.26, no.1, pp. 43-49, Feb 1978 URL: http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1163055 [2] Itakura, F., Minimum prediction residual principle applied to speech recognition, Acoustics, Speech, and Signal Processing [see also IEEE Transactions on Signal Processing], IEEE Transactions on , vol.23, no.1, pp. 67-72, Feb 1975. URL: http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1162641

  • noWindow
  • sakoeChibaWindow
  • slantedBandWindow
  • itakuraWindow
  • dtwWindowingFunctions
  • dtwWindow.plot

## Display some windowing functions
dtwWindow.plot(itakuraWindow, main="So-called Itakura parallelogram window")
dtwWindow.plot(slantedBandWindow, window.size=2,
  reference=13, query=17, main="The slantedBandWindow at window.size=2")

## Asymmetric step with Sakoe-Chiba band


             window.size=30                  );

dtwPlot(asyband,type="density",main="Sine/cosine: asymmetric step, S-C window")

Documentation reproduced from package dtw, version 1.18-1, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.