wildboar.distance.dtw#

Module Contents#

Functions#

ddtw_distance(x, y, *[, r])

Compute the derivative dynamic time warping distance

dtw_alignment(x, y, *[, r, weight, out])

Compute the Dynamic time warping alignment matrix

dtw_distance(x, y, *[, r])

Compute the dynamic time warping distance

dtw_envelop(x, *[, r])

Compute the envelop for LB_keogh

dtw_lb_keogh(x[, y, lower, upper, r])

The LB_keogh lower bound

dtw_mapping([x, y, alignment, r, return_index])

Compute the optimal warping path between two series or from a given

dtw_pairwise_distance(x[, r])

Compute the distance between all pairs of rows

jeong_weight(n[, g])

Weighting described by Jeong et. al. (2011) using g as the penalty control.

wddtw_distance(x, y, *[, r, g])

Compute the weighted derivative dynamic time warping distance

wdtw_alignment(x, y, *[, r, g, out])

Weighted dynamic time warping alignment

wdtw_distance(x, y, *[, r, g])

Compute the weighted dynamic time warping distance

wildboar.distance.dtw.ddtw_distance(x, y, *, r=1.0)[source]#

Compute the derivative 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 (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

Returns:

distance – The dynamic time warping distance

Return type:

float

See also

dtw_distance

compute the dtw distance

wildboar.distance.dtw.dtw_alignment(x, y, *, r=1.0, weight=None, out=None)[source]#

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 (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

  • out (array-like of shape (x_timestep, y_timestep), optional) – Store the warping path in this array.

  • weight (array-like of shape (max(x_timestep, y_timestep), ), optional) – A weighting vector to penalize warping.

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_distance

compute the dtw distance

References

Jeong, Y., Jeong, M., Omitaomu, O. (2021)

Weighted dynamic time warping for time series classification. Pattern Recognition 44, 2231-2240

wildboar.distance.dtw.dtw_distance(x, y, *, r=1.0)[source]#

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 (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

Returns:

distance – The dynamic time warping distance

Return type:

float

See also

dtw_alignment

compute the dtw alignment matrix

wildboar.distance.dtw.dtw_envelop(x, *, r=1.0)[source]#

Compute the envelop for LB_keogh

Parameters:
  • x (array-like of shape (x_timestep,)) – The time series

  • r (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

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)[source]#

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, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

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)[source]#

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, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

  • 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

wildboar.distance.dtw.dtw_pairwise_distance(x, r=1.0)[source]#

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 warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

Returns:

distances – The distance between pairs of rows

Return type:

ndarray of shape (n_samples, n_samples)

wildboar.distance.dtw.jeong_weight(n, g=0.05)[source]#

Weighting described by Jeong et. al. (2011) using g as the penalty control.

\[w(x)=\frac{1}{1+e^{-g(x-m/2)}}\]
Parameters:
  • n (int) – The number of weights.

  • g (float, optional) – Penalty control.

Returns:

weight – The weights

Return type:

ndarray of shape (n, )

References

Jeong, Y., Jeong, M., Omitaomu, O. (2021)

Weighted dynamic time warping for time series classification. Pattern Recognition 44, 2231-2240

wildboar.distance.dtw.wddtw_distance(x, y, *, r=1.0, g=0.05)[source]#

Compute the weighted derivative 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 (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

  • g (float, optional) – Penalization for points deviating the diagonal.

Returns:

distance – The dynamic time warping distance

Return type:

float

See also

dtw_distance

compute the dtw distance

wildboar.distance.dtw.wdtw_alignment(x, y, *, r=1.0, g=0.5, out=None)[source]#

Weighted dynamic time warping alignment

Parameters:
  • x (array-like of shape (x_timestep,)) – The first time series

  • y (array-like of shape (y_timestep,)) – The second time series

  • r (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

  • g (float, optional) –

    Weighting described by Jeong et. al. (2011) using \(g\) as penalty control.

    \[w(x)=\frac{w_{max}}{1+e^{-g(x-m/2)}},\]

  • 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)

References

Jeong, Y., Jeong, M., Omitaomu, O. (2021)

Weighted dynamic time warping for time series classification. Pattern Recognition 44, 2231-2240

wildboar.distance.dtw.wdtw_distance(x, y, *, r=1.0, g=0.05)[source]#

Compute the weighted 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 (float, optional) – The warping window in [0, 1] as a fraction of max(x_timestep, y_timestep)

  • g (float, optional) – Penalization for points deviating the diagonal.

Returns:

distance – The dynamic time warping distance

Return type:

float

See also

dtw_distance

compute the dtw distance