Skip to content

AlignerDtwNumba

AlignerDtwNumba

class AlignerDtwNumba(weighted: bool = False, derivative: bool = False, window=None, itakura_max_slope=None, bounding_matrix: ndarray = None, g: float = 0.0)[source]

Interface to sktime native dtw aligners, with derivative or weighting.

Interface to simple dynamic time warping (DTW) alignment, and the following weighted/derivative versions:

  • WDTW - weighted dynamic time warping - ``weighted=True, derivative=False`

  • DDTW - derivative dynamic time warping - weighted=False, derivative=True

  • WDDTW - weighted derivative dynamic time warping - weighted=True, derivative=True

sktime interface to the efficient numba implementations provided by distance_alignment_path in sktime.dists_kernels._numba_distances.

This estimator provides performant implementation of time warping for:

  • time series of equal length

  • the Euclidean pairwise distance

For unequal length time series, use sktime.aligners.AlignerDTW. To use arbitrary pairwise distances, use sktime.aligners.AlignerDTWfromDist. (for derivative DTW, pipeline an alignment distance with Differencer)

The distances are also available in sktime.dists_kernels.dtw as pairwise transformers.

Note that the more flexible options above may be less performant.

DTW was originally proposed in [1], DTW computes the distance between two time series by considering their alignments during the calculation. This is done by measuring the pointwise distance (normally using Euclidean) between all elements of the two time series and then using dynamic programming to find the warping path that minimises the total pointwise distance between realigned series.

DDTW is an adaptation of DTW originally proposed in [2]. DDTW attempts to improve on dtw by better account for the ‘shape’ of the time series. This is done by considering y axis data points as higher level features of ‘shape’. To do this the first derivative of the sequence is taken, and then using this derived sequence a dtw computation is done.

WDTW was first proposed in [3], it adds a multiplicative weight penalty based on the warping distance. This means that time series with lower phase difference have a smaller weight imposed (i.e less penalty imposed) and time series with larger phase difference have a larger weight imposed (i.e. larger penalty imposed).

WDDTW was first proposed in [3] as an extension of DDTW. By adding a weight to the derivative it means the alignment isn’t only considering the shape of the time series, but also the phase.

Parameters:
weightedbool, optional, default=False

whether a weighted version of the distance is computed False = unmodified distance, i.e., dtw distance or derivative dtw distance True = weighted distance, i.e., weighted dtw or derivative weighted dtw

derivativebool, optional, default=False

whether the distance or the derivative distance is computed False = unmodified distance, i.e., dtw distance or weighted dtw distance True = derivative distance, i.e., derivative dtw distance or derivative wdtw

window: int, defaults = None

Sakoe-Chiba window radius one of three mutually exclusive ways to specify bounding matrix if None, does not use Sakoe-Chiba window if int, uses Sakoe-Chiba lower bounding window with radius window. If window is passed, itakura_max_slope will be ignored.

itakura_max_slope: float, between 0. and 1., default = None

Itakura parallelogram slope one of three mutually exclusive ways to specify bounding matrix if None, does not use Itakura parallelogram lower bounding if float, uses Itakura parallelogram lower bounding, with slope gradient itakura_max_slope

bounding_matrix: optional, 2D np.ndarray, default=None

one of three mutually exclusive ways to specify bounding matrix must be of shape (len(X), len(X2)), len meaning number time points, where X, X2 are the two time series passed in transform Custom bounding matrix to use. If provided, then window and itakura_max_slope are ignored. The matrix should be structured so that indexes considered in bound should be the value 0. and indexes outside the bounding matrix should be infinity.

g: float, optional, default = 0. Used only if ``weighted=True``.

Constant that controls the curvature (slope) of the function; that is, g controls the level of penalisation for the points with larger phase difference.

Attributes:
is_fitted

Whether fit has been called.

References

[1]

H. Sakoe, S. Chiba, “Dynamic programming algorithm optimization for spoken word recognition,” IEEE Transactions on Acoustics, Speech and Signal Processing, vol. 26(1), pp. 43–49, 1978.

[2]

Keogh, Eamonn & Pazzani, Michael. (2002). Derivative Dynamic Time Warping. First SIAM International Conference on Data Mining. 1. 10.1137/1.9781611972719.1.

[3] (1,2)

Young-Seon Jeong, Myong K. Jeong, Olufemi A. Omitaomu, Weighted dynamic time

warping for time series classification, Pattern Recognition, Volume 44, Issue 9, 2011, Pages 2231-2240, ISSN 0031-3203, https://doi.org/10.1016/j.patcog.2010.09.022.

Examples

>>> from sktime.utils._testing.series import _make_series
>>> from sktime.alignment.dtw_numba import AlignerDtwNumba
>>>
>>> X0 = _make_series(return_mtype="pd.DataFrame")
>>> X1 = _make_series(return_mtype="pd.DataFrame")
>>> d = AlignerDtwNumba(weighted=True, derivative=True)
>>> align = d.fit([X0, X1]).get_alignment()

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X[, Z])

Fit alignment given series/sequences to align.

get_aligned()

Return aligned version of sequences passed to fit.

get_alignment()

Return alignment for sequences/series passed in fit (iloc indices).

get_alignment_loc()

Return alignment for sequences/series passed in fit (loc indices).

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_distance()

Return overall distance of alignment.

get_distance_matrix()

Return distance matrix of alignment.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.