MODULE REFERENCE
dtw
anomx.data.processing.dtw.dtwDynamic Time Warping (DTW)
DTWAlignment
DTWAlignment(series1: TimeSeries, series2: TimeSeries, cost: CostMatrix)Dynamic Time Warping (DTW) Alignment.
Attributes
- n
The length of
series1- m
The length of
series2- series1
A
TimeSeriesto align withseries2.- series2
A
TimeSeriesto align withseries1.- cost
The
CostMatrixfor DTW.
| Parameter | Type | Default |
|---|---|---|
series1 | TimeSeries | required |
series2 | TimeSeries | required |
cost | CostMatrix | required |
Members
pathmethod
path() -> np.ndarrayGives the index paths from series1 to series2.
Returns
- np.ndarray of shape
(len(path), 2) An array of indices [[i0,j0], [i1,j1], [i2,j2], ...], where i indexes into series1 and j indexes into series2. Indices are in monotonic order, path[n] >= path[n-1]
Returns np.ndarray
distancemethod
distance() -> floatGives the total distance between pair-wise elements in the two series after warping.
Returns
- float
The total distance between pair-wise elements in the two series after warping.
Returns float
mean_distancemethod
mean_distance() -> floatGives the mean distance between pair-wise elements in the two series after warping.
Returns
- float
The mean distance between pair-wise elements in the two series after warping.
Returns float
warpedmethod
warped() -> (TimeSeries, TimeSeries)Warps the two time series according to the warp path returned by DTWAlignment.path(), which minimizes the pair-wise distance. This will bring two time series that are out-of-phase back into phase.
Returns
- (TimeSeries, TimeSeries)
Two new TimeSeries instances of the same length, indexed by pd.RangeIndex.
Returns (TimeSeries, TimeSeries)
dtw
dtw(series1: TimeSeries, series2: TimeSeries, window: Window | None = None, distance: DistanceFunc | None = None, multi_grid_radius: int = -1) -> DTWAlignmentDetermines the optimal alignment between two time series series1 and series2, according to the Dynamic Time Warping algorithm. The alignment minimizes the distance between pair-wise elements after warping. All elements in the two series are matched and are in strictly monotonically increasing order. Considers only the values in the series, ignoring the time axis.
Dynamic Time Warping can be applied to determine how closely two time series correspond, irrespective of phase, length or speed differences.
Parameters
- series1
A
TimeSeriesto align withseries2.- series2
A
TimeSeriesto align withseries1.- window
Optionally, a
Windowused to constrain the search for the optimal alignment: seeSakoeChibaandItakura. Default considers all possible alignments (NoWindow).- distance
Function taking as input either two
floatsfor univariate series or twonp.ndarray, and returning the distance between them.Defaults to the abs difference for univariate-data and the sum of the abs difference for multi-variate series.
- multi_grid_radius
Default radius of
-1results in an exact evaluation of the dynamic time warping algorithm. Without constraints DTW runs in O(nxm) time where n,m are the size of the series. Exact evaluation with no constraints, will result in a performance warning on large datasets.Setting
multi_grid_radiusto a value other than-1, will enable the approximate multi-grid solver, which executes in linear time, vs quadratic time for exact evaluation. Increasing radius trades solution accuracy for performance.
Returns
- DTWAlignment
Helper object for getting warp path, mean_distance, distance and warped time series
| Parameter | Type | Default |
|---|---|---|
series1 | TimeSeries | required |
series2 | TimeSeries | required |
window | Window | None | None |
distance | DistanceFunc | None | None |
multi_grid_radius | int | -1 |
Returns DTWAlignment