Learn R Programming

dtw (version 1.2-1)

dtwDistanceFunctions: Distance functions for DTW

Description

Compute Euclidean squared distance between two given vectors (default function for dtw).

Usage

euclideanSquared(a, b)
euclideanDistance(a, b)

Arguments

a,b
floating point values

Value

  • Local distance (float).

Details

These distance functions are supplied as an example of what can be passed to the distance.function argument in dtw. Although it makes sense for a and b to be vectors rather than numbers, direct alignment of two multivariate time series is currently not supported natively by dtw (this may change in the future). The user should instead build a local distance matrix, e.g. via a custom function or distance in package analogue, and feed the result into dtw as a matrix first argument.

References

Euclid's Elements, T.L. Heath (translator), Dover (1956).

See Also

distance can build a distance matrix according to several distance definitions.

Examples

Run this code
# A constant vector
z<-numeric(10);     

# dtw between two constant vectors with a squared euclidean distance
# this should be 2^2 times 10 elements = 40
d2<-dtw(z,z+2);
stopifnot(d2$distance==40);

# dtw between two constant vectors with a root squared euclidean distance
# this should be 2 times 10 elements = 20
d1<-dtw(z,z+2,
 	distance.function=function(a,b){return(abs(a-b));})
stopifnot(d1$distance==20);

Run the code above in your browser using DataLab