# dynamic time warping (DTW): unexpected results

on the wave of the suggestions given to me on this topic I started (time series similarities: which techniques for each transformation?) I decided to give another try at Dynamic Time Warping but I newly found myself at "en empasse" due to the fact that DTW is unable to capture basic structures in the data.

Example: I am comparing 2 time series that were built by adding to a linear component (bx) a trigonometric fluctuation (sin(ax)). the two series only differ by a,b assigned, the underlying function does NOT change.

visually,

PROBLEM: as the image suggets, by construction, the DTW tranformation should assign as end point a much further point thus casting serious doubts on the method viability when inserting a trend (essentially rendering it useless for my purposes)

my code in R:

library(dtw)

query <- c(0, 0.358690844053802, 0.699770102643102, 1.00682518110537, 1.26575983949234, 1.46575385983424, 1.59999968293183, 1.66616586469212, 1.66655580005627, 1.60795090864843, 1.50114895801364, 1.36022895524296, 1.20159265291649, 1.0428479233163, 0.901610020416749, 0.794302339331523, 0.735038317110301, 0.734660594701695, 0.800002853612282, 0.93342458117311, 1.13265043743753, 1.39092515955778)
reference <- c(0, 0.899770102643102, 1.66575983949234, 2.19999968293183, 2.46655580005627, 2.50114895801364, 2.40159265291649, 2.30161002041675, 2.3350383171103, 2.60000285361228, 3.13265043743753, 3.89747345780267, 4.79681469820686, 5.69700859233483, 6.46416133227289, 6.99999207330592, 7.26814112499755, 7.30390285169987, 7.20477794259013, 7.10437405559822, 7.13664121032796, 7.4000155363007)

alignmentOBE <- dtw(
query,
reference,
step=asymmetric,
open.end=TRUE,
keep=TRUE);

# open.end=FALSE,
# open.begin=TRUE
# step=symmetric1,

plot(alignmentOBE,type="two",off=1);


QUESTION: I am doing something wrong (parametrization, etc) or the model is unable to capture some features by hypothesis?

• You might want to take a look at this simple Python implementation, it may give you some sense about how it works: github.com/talcs/simpledtw – SomethingSomething May 28 '18 at 11:47

Relevant constraints could be a band such as Sakoe-Chiba band or R-K-Band. As the documentation to your function in R says, you can use these constraints by varying the step.pattern here
1. Introduce further constraints using the window.type argument. Specifically check the results for: "itakura" as window.type