wildboar.distance.dtw#
Module Contents#
Functions#
|
Compute the Dynamic time warping alignment matrix |
|
Compute the dynamic time warping distance |
|
Compute the distance between all pairs of rows |
|
Compute the envelop for LB_keogh |
|
The LB_keogh lower bound |
|
Compute the optimal warping path between two series or from a given |
- wildboar.distance.dtw.dtw_alignment(x, y, r=1.0, out=None)#
Compute the Dynamic time warping alignment matrix
- Parameters:
x (array-like of shape (x_timestep,)) – The first time series
y (array-like of shape (y_timestep,)) – The second time series
r (int or float, optional) –
The warping window
if float in [0, 1] a fraction of max(x_timestep, y_timestep)
if int the exact warping window (max(1, r))
out (array-like of shape (x_timestep, y_timestep), optional) – Store the warping path in this array.
- Returns:
alignment – The dynamic time warping alignment matrix
- Return type:
ndarray of shape (x_timestep, y_timestep)
Notes
If only the distance between two series is required use dtw_distance instead
See also
dtw_distancecompute the dtw distance
- wildboar.distance.dtw.dtw_distance(x, y, r=1.0, scale=False)#
Compute the dynamic time warping distance
- Parameters:
x (array-like of shape (x_timestep, )) – The first time series
y (array-like of shape (y_timestep, )) – The second time series
r (int or float, optional) –
The warping window
if float in [0, 1] a fraction of max(x_timestep, y_timestep)
if int the exact warping window (max(1, r))
scale (bool, optional) – If True, x and y are standardized before calculation
- Returns:
distance – The dynamic time warping distance
- Return type:
float
See also
dtw_alignmentcompute the dtw alignment matrix
- wildboar.distance.dtw.dtw_pairwise_distance(x, r=1.0)#
Compute the distance between all pairs of rows
- Parameters:
x (array-like of shape (n_samples, n_timestep)) – An array of samples
r (float or int, optional) –
The size of the warping window
if float in [0, 1] a fraction of x_timestep
if int the exact warping window (max(1, r))
- Returns:
distances – The distance between pairs of rows
- Return type:
ndarray of shape (n_samples, n_samples)
- wildboar.distance.dtw.dtw_envelop(x, r=1.0)#
Compute the envelop for LB_keogh
- Parameters:
x (array-like of shape (x_timestep,)) – The time series
r (float or int, optional) –
The size of the warping window
if float in [0, 1] a fraction of x_timestep
if int the exact warping window (max(1, r))
- Returns:
lower (ndarray of shape (x_timestep,)) – The min value of the envelop
upper (ndarray of shape (x_timestep,)) – The max value of the envelop
References
- Keogh, E. (2002).
Exact indexing of dynamic time warping. In 28th International Conference on Very Large Data Bases.
- wildboar.distance.dtw.dtw_lb_keogh(x, y=None, *, lower=None, upper=None, r=1.0)#
The LB_keogh lower bound
- Parameters:
x (array-like of shape (x_timestep,)) – The first time series
y (array-like of shape (x_timestep,), optional) – The second time series (same size as x)
lower (ndarray of shape (x_timestep,), optional) – The min value of the envelop
upper (ndarray of shape (x_timestep,), optional) – The max value of the envelop
r (float or int, optional) –
The size of the warping window
if float in [0, 1] a fraction of x_timestep
if int the exact warping window (max(1, r))
- Returns:
min_dist (float) – The cumulative minimum distance.
lb_keogh (ndarray of shape (x_timestep,),) – The lower bound at each time step
Notes
if y=None, both lower and upper must be given
if y is given, lower and upper are ignored
if lower and upper is given and y=None, r is ignored
References
- Keogh, E. (2002).
Exact indexing of dynamic time warping. In 28th International Conference on Very Large Data Bases.
- wildboar.distance.dtw.dtw_mapping(x=None, y=None, *, alignment=None, r=1, return_index=False)#
Compute the optimal warping path between two series or from a given alignment matrix
- Parameters:
x (array-like of shape (x_timestep,), optional) – The first time series
y (array-like of shape (y_timestep,), optional) – The second time series
alignment (ndarray of shape (x_timestep, y_timestep), optional) – Precomputed alignment
r (float or int, optional) –
if float, the warping path is a fraction of
return_index (bool, optional) – Return the indices of the warping path
- Returns:
indicator (ndarray of shape (x_timestep, y_timestep)) – Boolean array with the dtw path
(x_indices, y_indices) (tuple, optional) – The indices of the first and second dimension of the optimal alignment path.
Notes
either x and y or alignment must be provided
if alignment is given x and y are ignored
if alignment is given r is ignored