# NOT RUN {
# }
# NOT RUN {
#--- univariate case
noise <- function(nr) cumsum(rnorm(nr))
set.seed(123)
nx <- 500
nh <- 40
nfits <- 5
nn <- nx - nfits * nh# nnoise
nn <- nn/nfits
h <- sin(1:nh)
hnorm <- IncDTW::norm( h , type="01")
x <- noise(0)
for(i in 1:nfits){
x <- c(x, noise(nn) ,
h * abs(rnorm(1, 10,10))+ rnorm(1, 0, 10))
}
# DO norm and DO lower bound
result <- rundtw(h, x, normalize = '01', ws = 10, threshold = Inf, lower_bound = TRUE)
## have a look into the result and get best indices with lowest distance
minima <- find_peaks(result$dist, w = nh, get_min = TRUE)
par(mfrow=c(2,1))
plot(x, type = "l")
for(i in minima) lines(x = i:(i+nh-1), y = x[i:(i+nh-1)], col="red")
plot(result$dist, xlim=c(1, nx))
points(x = minima, y = result$dist[minima], col="red", pch=16)
# DO min-max-norm and DO lower bound
rundtw(h, x, normalize = '01', ws = 10, threshold = Inf, lower_bound = TRUE)
# DO z-norm and DO lower bound
rundtw(h, x, normalize = 'z', ws = 10, threshold = NULL, lower_bound = TRUE)
# DONT norm and DONT lower bound
rundtw(h, x, normalize = 'none', ws = 10, threshold = NULL, lower_bound = FALSE)
# kNN: DO z-norm and DO lower bound
rundtw(h, x, normalize = '01', ws = 10, k = 3)
#--- multivariate case
noise <- function(nr, nc) matrix(cumsum(rnorm(nr * nc)), nrow = nr, ncol = nc)
nx <- 500
nh <- 50
nc <- 2
nfits <- 5
nn <- nx - nfits * nh# nnoise
nn <- nn/nfits
h <- noise(nh, nc)
hnorm <- IncDTW::norm( h , type="01")
x <- matrix(numeric(), ncol=nc)
for(i in 1:nfits){
x <- rbind(x, noise(nn, nc), h)
}
# DO min-max-norm and DO lower bound
rundtw(h, x, normalize = '01', ws = 10, threshold = Inf, lower_bound = TRUE)
# DO z-norm and DO lower bound
rundtw(h, x, normalize = 'z', ws = 10, threshold = NULL, lower_bound = TRUE)
# DONT norm and DONT lower bound
rundtw(h, x, normalize = 'none', ws = 10, threshold = NULL, lower_bound = FALSE)
#--- C is a list of multivariate time series
noise <- function(nr, nc) matrix(cumsum(rnorm(nr * nc)), nrow = nr, ncol = nc)
nx <- 500
nh <- 50
nc <- 2
h <- noise(nh, nc)
hnorm <- IncDTW::norm( h , type="01")
x1 <- rbind(noise(100, nc), h, noise(20, nc))
x2 <- rbind(noise(10, nc), h, noise(50, nc))
x3 <- rbind(noise(200, nc), h, noise(30, nc))
x <- list(x1, x2, x3)
# DO min-max-norm and DO lower bound
rundtw(h, x, normalize = '01', ws = 10, threshold = Inf, lower_bound = TRUE, k = 3)
# DO z-norm and DO lower bound
rundtw(h, x, normalize = 'z', ws = 10, threshold = Inf, lower_bound = TRUE, k = 3)
# DONT norm and DONT lower bound
rundtw(h, x, normalize = 'none', ws = 10, threshold = Inf, lower_bound = TRUE, k = 3)
# }
Run the code above in your browser using DataLab