Learn R Programming

dtwclust (version 3.1.1)

DBA: DTW Barycenter Averaging

Description

A global averaging method for time series under DTW (Petitjean, Ketterlin and Gancarski 2011).

Usage

DBA(X, centroid = NULL, ..., window.size = NULL, norm = "L1", max.iter = 20L, delta = 0.001, error.check = TRUE, trace = FALSE)

Arguments

X
A data matrix where each row is a time series, or a list where each element is a time series. Multivariate series should be provided as a list of matrices where time spans the rows and the variables span the columns.
centroid
Optionally, a time series to use as reference. Defaults to a random series of X if NULL. For multivariate series, this should be a matrix with the same characteristics as the matrices in X.
...
Further arguments for dtw_basic. However, the following are already pre- specified: window.size, norm (passed along), backtrack and gcm.
window.size
Window constraint for the DTW calculations. NULL means no constraint. A slanted band is used by default.
norm
Norm for the local cost matrix of DTW. Either "L1" for Manhattan distance or "L2" for Euclidean distance.
max.iter
Maximum number of iterations allowed.
delta
At iteration i, if all(abs(centroid_{i} - centroid_{i-1}) < delta), convergence is assumed.
error.check
Should inconsistencies in the data be checked?
trace
If TRUE, the current iteration is printed to screen.

Value

The average time series.

Parallel Computing

Please note that running tasks in parallel does not guarantee faster computations. The overhead introduced is sometimes too large, and it's better to run tasks sequentially. The user can register a parallel backend, e.g. with the doParallel package, in order to attempt to speed up the calculations (see the examples).

Details

This function tries to find the optimum average series between a group of time series in DTW space. Refer to the cited article for specific details on the algorithm.

If a given series reference is provided in centroid, the algorithm should always converge to the same result provided the elements of X keep the same values, although their order may change.

The windowing constraint uses a centered window. The calculations expect a value in window.size that represents the distance between the point considered and one of the edges of the window. Therefore, if, for example, window.size = 10, the warping for an observation $x_i$ considers the points between $x_{i-10}$ and $x_{i+10}$, resulting in 10(2) + 1 = 21 observations falling within the window.

References

Petitjean F, Ketterlin A and Gancarski P (2011). ``A global averaging method for dynamic time warping, with applications to clustering.'' Pattern Recognition, 44(3), pp. 678 - 693. ISSN 0031-3203, http://dx.doi.org/10.1016/j.patcog.2010.09.013, http://www.sciencedirect.com/science/article/pii/S003132031000453X.

Examples

Run this code

# Sample data
data(uciCT)

# Obtain an average for the first 5 time series
dtw.avg <- DBA(CharTraj[1:5], CharTraj[[1]], trace = TRUE)

# Plot
matplot(do.call(cbind, CharTraj[1:5]), type = "l")
points(dtw.avg)

# Change the provided order
dtw.avg2 <- DBA(CharTraj[5:1], CharTraj[[1]], trace = TRUE)

# Same result?
all(dtw.avg == dtw.avg2)

## Not run: 
# #### Running DBA with parallel support
# # For such a small dataset, this is probably slower in parallel
# require(doParallel)
# 
# # Create parallel workers
# cl <- makeCluster(detectCores())
# invisible(clusterEvalQ(cl, library(dtwclust)))
# registerDoParallel(cl)
# 
# # DTW Average
# cen <- DBA(CharTraj[1:5], CharTraj[[1]], trace = TRUE)
# 
# # Stop parallel workers
# stopCluster(cl)
# 
# # Return to sequential computations
# registerDoSEQ()
# ## End(Not run)

Run the code above in your browser using DataLab