Learn R Programming

dtwclust (version 3.1.1)

GAK: Fast global alignment kernels

Description

Distance based on (triangular) global alignment kernels.

Usage

GAK(x, y, ..., sigma = NULL, window.size = NULL, normalize = TRUE, logs = NULL, error.check = TRUE)

Arguments

x, y
Time series. A multivariate series should have time spanning the rows and variables spanning the columns.
...
Currently ignored.
sigma
Parameter for the Gaussian kernel's width. See details for the interpretation of NULL.
window.size
Parameterization of the constraining band (T in Cuturi (2011)). See details.
normalize
Normalize the result by considering diagonal terms.
logs
Optionally, a matrix with max(NROW(x), NROW(y)) + 1 rows and 3 columns to use for the logarithm calculations. Used internally for memory optimization. If provided, it will be modified in place by C code, except in the parallel version in proxy::dist which ignores it for thread-safe reasons.
error.check
Check data inconsistencies?

Value

The logarithm of the GAK if normalize = FALSE, otherwise 1 minus the normalized GAK. The value of sigma is assigned as an attribute of the result.

Details

This function uses the Triangular Global Alignment Kernel (TGAK) described in Cuturi (2011). It supports series of different length and multivariate series, so long as the ratio of the series' lengths don't differ by more than 2 (or less than 0.5).

The window.size parameter is similar to the one used in DTW, so NULL signifies no constraint, and its value should be greater than 1 if used with series of different length.

The Gaussian kernel is parameterized by sigma. Providing NULL means that the value will be estimated by using the strategy mentioned in Cuturi (2011) with a constant of 1. This estimation is subject to randomness, so consider estimating the value once and re-using it (the estimate is returned as an attribute of the result). See the examples.

For more information, refer to the package vignette and the referenced article.

References

Cuturi, M. (2011). Fast global alignment kernels. In Proceedings of the 28th international conference on machine learning (ICML-11) (pp. 929-936).

Examples

Run this code

## Not run: 
# data(uciCT)
# 
# set.seed(832)
# GAKd <- proxy::dist(zscore(CharTraj), method = "gak",
#                     pairwise = TRUE, window.size = 18L)
# 
# # Obtained estimate of sigma
# sigma <- attr(GAKd, "sigma")
# 
# # Use value for clustering
# dtwclust(CharTraj, k = 20L,
#          distance = "gak", centroid = "shape",
#          sigma = sigma,
#          control = list(trace = TRUE,
#                         window.size = 18L))
# ## End(Not run)

Run the code above in your browser using DataLab