simpledtw
Dynamic Time Warping for Trend Classification, Signal Alignment and Trend Classification
dtw
dtw(series_1, series_2, norm_func=np.linalg.norm)
Computes Dynamic Time Warping (DTW) distance and alignment between two sequences.
This implementation calculates the optimal alignment path and cost matrix between two time series, allowing for flexible comparison of segments with temporal shifts. It is used in PyTrendy to classify trends (e.g., gradual vs abrupt) by comparing segments to reference signals.
Parameters:
-
(series_1array) –First time series to compare. Should be a 1D or 2D array of numeric values.
-
(series_2array) –Second time series to compare. Must be of compatible shape with
series_1. -
(norm_funccallable, default:norm) –Function to compute distance between elements. Defaults to
np.linalg.norm.
Returns:
-
tuple(tuple[list[tuple[int, int]], float | floating, list[list[int]], list[list[int]], ndarray]) –A 5-element tuple containing:
matches(list of tuple): Optimal alignment path as index pairs.cost(float): Final DTW distance (bottom-right of cost matrix).mappings_series_1(list of list): Mapping from each index inseries_1to indices inseries_2.mappings_series_2(list of list): Mapping from each index inseries_2to indices inseries_1.matrix(ndarray): Full DTW cost matrix.
Credits
This is directly extracted from the simpledtw GitHub repository.
Source code in pytrendy/simpledtw.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |