DTW: Run the Dynamic Time Warping Algorithm on Two Trajectories

Description Usage Arguments Details Value Author(s) References Examples

Description

A function to calculate the dynamic time warping value between two trajectories.

Usage

1
DTW(traj1, traj2, pointSpacing=-1)

Arguments

traj1

An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points.

traj2

A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points.

pointSpacing

An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited.

Details

The dynamic time warping algorithm (DTW) calculates the smallest warp path for the two trajectories. This is the DTW version discussed by Berndt & Clifford (1994). Several variations of calculating the warping cost exist. In this version, the warping path is equal to the sum of the distances at each point along the path. Please see the references for more information.

Value

A floating point value representing the smallest warp path is returned. If a problem occurs, then a string containing information about the problem is returned.

Author(s)

Kevin Toohey

References

Berndt, D. and Clifford, J. (1994) Using Dynamic Time Warping to Find Patterns in Time Series. Paper presented at the KDD workshop.

Examples

1
2
3
4
5
6
7
# Creating two trajectories.
path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4)
path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4)

# Running the dynamic time warping algorithm with point spacing 
# set to 4.
DTW(path1, path2, 4)

Example output

[1] 16

SimilarityMeasures documentation built on May 1, 2019, 10:06 p.m.