# NOT RUN {
#--- Compare the incremental calculation with the basic
# calculation from scratch.
Q <- cumsum(rnorm(100))
C <- Q[11:100] + rnorm(90, 0, 0.5)
newObs <- c(2, 3)# new observation
base <- dtw(Q = Q, C = C, ws = 15, return_diffM = TRUE)
base
# recalculation from scratch with new observations
result0 <- dtw(Q = Q, C = c(C, newObs), ws = 15, return_diffM = TRUE)
# the incremental step with new observations
result1 <- idtw(Q, C, ws = 15, newO = newObs, gcm = base$gcm,
dm = base$dm, diffM = base$diffM, return_diffp = TRUE,
return_diffM = TRUE, return_QC = TRUE)
print(result1, digits = 2)
plot(result1)
#--- Compare the incremental calculation with external calculated
# costMatrix cm_add with the basic calculation from scratch.
cm_add <- cm(Q, newObs)
result2 <- idtw(Q = cm_add, C = "cm_add", ws = 15, newO = newObs,
gcm = base$gcm, dm = base$dm)
c(result0$distance, result1$distance, result2$distance)
# }
Run the code above in your browser using DataLab