idtw2vec | R Documentation |
Update the DTW distance for new observations of two time series.
idtw2vec(Q, newObs, dist_method = c("norm1", "norm2", "norm2_square"), step_pattern = c("symmetric2", "symmetric1"), gcm_lc = NULL, gcm_lr = NULL, nC = NULL, ws = NULL)
Q |
Either |
newObs |
time series as vector or matrix, or if |
dist_method |
character, describes the method of distance measure. See also |
step_pattern |
character, describes the step pattern. See also |
gcm_lc |
vector, last column of global cost matrix of previous calculation. If NULL (necessary for the initial calculation), then DTW is calculated and the last column and last row are returned to start upcoming incremental calculations. (default = NULL) |
gcm_lr |
vector, last row of global cost matrix of previous calculation (default = NULL). |
nC |
integer, is the length of the original time series C, of which newObs are the new observations. Length of time series C exclusive new observations, such that |
ws |
integer, describes the window size for the sakoe chiba window. If NULL, then no window is applied. (default = NULL) |
If new observations are recorded only for C and the only interest is a fast update of the DTW distance, the last row is not required, neither for the current nor for future incremental calculations.
If Q
is a cost matrix, it needs to store either the distances of Q
and new observations of C
(running calculations, in that case gcm_lc != NULL), or it stores the distances of Q
and the entire time series C
(initial calculation, in that case gcm_lc = NULL).
If newObs
is a time series, it stores either new Observations of C
(running calculations) or the complete time series C
(initial calculation).
no matrices are allocated, no matrices are returned
distance |
the DTW distance |
gcm_lc_new |
the last column of the new global cost matrix |
gcm_lr_new |
the last row of the new global cost matrix. Only if the input vector |
normalized_distance |
the normalized DTW distance, see also |
Leodolter, M.; Pland, C.; Brändle, N; IncDTW: An R Package for Incremental Calculation of Dynamic Time Warping. Journal of Statistical Software, 99(9), 1-23. doi: 10.18637/jss.v099.i09
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
#--- Do the vector-based incremental DTW # calculation and compare it with the basic Q <- cumsum(rnorm(100)) C <- Q[11:100] + rnorm(90, 0, 0.5) # initial calculation res0 <- idtw2vec(Q = Q, newObs = C, gcm_lc = NULL) # incremental calculation for new observations nobs <- rnorm(10) res1 <- idtw2vec(Q, newObs = nobs, gcm_lc = res0$gcm_lc_new) # compare with result from scratch res2 <- dtw2vec(Q, c(C, nobs)) res1$distance - res2$distance #--- Perform an incremental DTW calculation with a # customized distance function. d_cos <- function(x, y){ 1 - sum(x * y)/(sqrt(sum(x^2)) * sqrt(sum(y^2))) } x <- matrix(rnorm(100), ncol = 5, nrow = 20) y <- matrix(rnorm(150), ncol = 5, nrow = 30) cm1 <- cm(x, y, dist_method = d_cos) # initial calculation res0 <- idtw2vec(Q = cm(x, y[1:20,], dist_method = d_cos), newObs = "cm") # incremental calculation for new observations res1 <- idtw2vec(Q = cm(x, y[21:30,], d_cos), newObs = "cm", gcm_lc = res0$gcm_lc_new)$distance # compare with result from scratch res2 <- dtw2vec(Q = cm1, C = "cm")$distance res1 - res2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.