FastDTW

0.3.4 · maintenance · verified Wed Apr 15

FastDTW is a Python implementation of the FastDTW algorithm, which provides optimal or near-optimal alignments with an O(N) time and memory complexity for Dynamic Time Warping (DTW) of time series. The current version is 0.3.4, with its last release in October 2019, suggesting a maintenance rather than active development phase.

Warnings

Install

Imports

Quickstart

This example calculates the Dynamic Time Warping distance and the corresponding warping path between two time series (x and y) using the Euclidean distance metric for point-to-point comparison. Numpy arrays are used for time series data, and scipy's euclidean distance is passed to fastdtw. The 'dist' parameter can accept any function that computes a distance between two points.

import numpy as np
from scipy.spatial.distance import euclidean
from fastdtw import fastdtw

x = np.array([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]], dtype=float)
y = np.array([[2, 2], [3, 3], [4, 4]], dtype=float)

distance, path = fastdtw(x, y, dist=euclidean)

print(f"DTW Distance: {distance}")
print(f"Warping Path: {path}")

view raw JSON →