Dasha
Dasha

Reputation: 1

Constrained Dynamic Time Warping in R

I am comparing two time series in R using Dynamic Time Warping. The two time series reflect how two sets of raters responded to a stimulus over time. I'm finding, though, that the default DTW function is warping too much (e.g., in the plot, you can see that a point on the pink line from 40 seconds is being aligned with a point on the blue line at 0 seconds). I would like to have some "wiggle room" of a few seconds maximum for the warping. I found some papers on this, but cannot actually get anything to work for myself.

I think I can use the window.size function for this, but I don't know how to implement it. To produce the default DTW, I used:

alignment <- dtw(Listeners, Speaker)

alignment$distance

plot(dtw(Listeners, Speaker, keep=TRUE), xaxp  = c(0, 10, 10), 
          yaxp = c(0, 10, 10), type="twoway", col=c('blue', 'magenta'))

DTW plot: the blue and pink lines represent how to groups of raters reacted to a stimulus over the course of 80 seconds

Upvotes: 0

Views: 293

Answers (1)

Dasha
Dasha

Reputation: 1

I found an easy solution and figured I would share it here in case it helps anyone else:

alignment<-dtw(Listeners, Speaker, keep=TRUE, step=asymmetric, window.type=sakoeChibaWindow, window.size=2)

alignment$distance

plot(dtw(Listeners,Speaker, keep=TRUE, step=asymmetric, window.type=sakoeChibaWindow, window.size=2), xaxp  = c(0,10,10), yaxp = c(0,10,10), type="twoway", col=c('blue', 'magenta'))

I used the Sakoe-Chiba band window type here, with a size of 2. This makes sense for my data because I would expect a maximum variation in response time of about 2 seconds. For more information about choosing window type and size, this is a very helpful source: https://www.jstatsoft.org/article/view/v031i07

Upvotes: 0

Related Questions