1
$\begingroup$

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, enter image description here

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?

$\endgroup$
1
  • $\begingroup$ 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 $\endgroup$ Commented May 28, 2018 at 11:47

2 Answers 2

1
$\begingroup$

From a theoretic perspective it is a good idea to introduce further constraints when applying DTW. Such constraints can help to prevent cases of pathological warping such as happening in your case.

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

Further, standard DTW is used to compare two time-series of unequal length, normally mapping each start to the start point and end to endpoint. I am not aware of the implementation that you are using but it seems that the warping is considered done, when the total accumulated distance is lower than a threshold. The threshold simply seems to be too high for this example, which is why the warping is aborted / considered done very early.

Therefore my concrete recommendations are:

  1. Introduce further constraints using the window.type argument. Specifically check the results for: "itakura" as window.type
  2. Further please compare the results when setting open.beginn = True

Finally you could update your question with new plots, showing the influence of the parameters.

$\endgroup$
0
0
$\begingroup$

I can't speak to the DTW implimentation in R but the one I've written in python would probably do something similar to this.

Remember, DTW uses the difference in the amplitude of the data points, so although you're moving a long way in x, y isn't moving very far at all.

You could try bringing in some sort of normalisation before comparing your signals and passing those into the routine. You could try subtracting the mean and dividing by the standard deviation (as to whether or not this is a fair pre-processing step to take depends on your data and what you want DTW to try and tell you).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.