dtw_dismat | R Documentation |
Calculate a matrix of pairwise DTW distances for a set of univariate or multivariate time series. The output matrix (or dist object) of DTW distances can easily be applied for clustering the set of time series. Or calculate a vector of DTW distances of a set of time series all relative to one query time series. Parallel computations are possible.
dtw_dismat(lot, dist_method = c("norm1", "norm2", "norm2_square"), step_pattern = c("symmetric2", "symmetric1"), normalize = TRUE, ws = NULL, threshold = NULL, return_matrix = FALSE, ncores = NULL, useRcppParallel = TRUE) dtw_disvec(Q, lot, dist_method = c("norm1", "norm2", "norm2_square"), step_pattern = c("symmetric2", "symmetric1"), normalize = TRUE, ws = NULL, threshold = NULL, ncores = NULL)
Q |
time series, vector (univariate) or matrix (multivariate) |
lot |
List of time series. Each entry of the list is a time series as described in |
dist_method |
character, describes the method of distance measure. See also |
step_pattern |
character, describes the step pattern. See also |
normalize |
logical, whether to return normalized pairwise distances or not. If |
ws |
integer, describes the window size for the sakoe chiba window. If NULL, then no window is applied. (default = NULL) |
threshold |
numeric, the threshold for early abandoning. In the calculation of the global cost matrix a possible path stops as soon as the threshold is reached. Facilitates faster calculations in case of low threshold. (default = FALSE) |
return_matrix |
logical, If FALSE (default) the distance matrix is returned as |
ncores |
integer, number of cores to be used for parallel computation of the distance matrix. If |
useRcppParallel |
logical, if the package RcppParallel (TRUE, default) or parallel (FALSE) is used for parallel computation |
By setting the parameter return_matrix = FALSE
(default) the output value dismat
of dtw_dismat
is a dist
object and can easily be passed to standard clustering functions (see examples).
No matrices are allocated for calculating the pairwise distances.
input |
the function input parameters |
dismat |
the matrix of pairwise DTW distances, either as matrix or dist object |
disvec |
the vector DTW distances |
## Not run: #--- Example for clustering a set of time series by feeding well known # clustering methods with DTW-distance objects. First we simulate # two prototype random walks and some cluster members. The cluster # members are simulated by adding noise and randomly stretching and # comressing the time series, to get time warped time series of # varying lengths. The built clusters are 1:6 and 7:12. set.seed(123) N <- 100 rw_a <- cumsum(rnorm(N)) rw_b <- cumsum(rnorm(N)) sth <- sample(seq(0, 0.2, 0.01), size = 10) cmp <- sample(seq(0, 0.2, 0.01), size = 10) lot <- c(list(rw_a), lapply(1:5, function(i){ simulate_timewarp(rw_a + rnorm(N), sth[i], cmp[i]) }), list(rw_b), lapply(6:10, function(i){ simulate_timewarp(rw_b + rnorm(N), sth[i], cmp[i]) })) # Next get the distance matrix, as dist object. Per default all # minus 1 available cores are used: result <- dtw_dismat(lot = lot, dist_method = "norm2", ws = 50, return_matrix = FALSE) class(result$dismat) # Finally you can cluster the result with the following # well known methods: require(cluster) myclus <- hclust(result$dismat) plot(myclus) summary(myclus) myclus <- agnes(result$dismat) plot(myclus) summary(myclus) myclus <- pam(result$dismat, k=2) plot(myclus) summary(myclus) myclus$medoids ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.