Learn R Programming

IncDTW (version 1.0.0)

idtw: Incremental Dynamic Time Warping

Description

Wrapper function for the incremental designed C++ calculations of the global cost matrix and the BACKTRACK_cpp that finds the cheapest warping path.

Usage

idtw(Q, C, newO, gcm, dm, diffM = NULL, ws = NULL, 
     return_diffM = FALSE, 
     return_diffp = FALSE, 
     return_QC = FALSE)

Arguments

Q

one dimensional numeric vector

C

one dimensional numeric vector

newO

one dimensional numeric vector of new observations to be appended to C

gcm

global cost matrix, output from dtw(Q=Q, C=C, ws=ws)

dm

direction matrix, output from dtw(Q=Q, C=C, ws=ws)

diffM

differences matrix, output from dtw(Q=Q, C=C, ws=ws)

ws

integer, describes the window size for the sakoe chiba window. If NULL, then no window is applied. (default = NULL)

return_diffM

boolean, if TRUE then the Matrix of differences (not the absolute value) is returned. (default = FALSE)

return_diffp

boolean, if TRUE then the path of differences (not the absolute value) is returned. (default = FALSE)

return_QC

boolean, if TRUE then the input vectors Q and C are appended to the returned list. This is useful for the plot.idtw function. (default = FALSE)

Value

gcm

global cost matrix

dm

direction matrix (3=up, 1=diagonal, 2=left)

wp

warping path

ii

indices of C of the optimal path

jj

indices of Q of the optimal path

diffM

Matrix of differences

diffp

path of differences

Q

input Q

C

input C

Details

The dynamic time warping distance is the element in the last row and last column of the global cost matrix.

References

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. http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1163055

Examples

Run this code
# NOT RUN {
Q <- cumsum(rnorm(100))
C <- Q[11:100] + rnorm(90, 0, 0.5)
tmp <- dtw(Q=Q, C=C, ws = 15, return_diffM = TRUE) # the ordinary calculation
# new observation
newObs <-  c(2,3)
# the incremental step
idtw(Q, C, newO = newObs, gcm=tmp$gcm, dm=tmp$dm, diffM = tmp$diffM, 
return_diffp = TRUE, ws = 15, return_diffM = TRUE) 

# now with integers
Q <- 1:10
C <- 2:20
tmp <- dtw(Q=Q, C=C, ws = 15, return_diffM = TRUE) # the ordinary calculation
# new observation
newObs <-  c(2L,3L)
# the incremental step
tmpnew <- idtw(Q, C, newO = newObs, gcm=tmp$gcm, dm=tmp$dm, diffM = tmp$diffM, 
      return_diffp = TRUE, ws = 15, return_diffM = TRUE) 
str(tmpnew)
# }

Run the code above in your browser using DataLab