warp

dtw.warp(d, index_reference=False)

Apply a warping to a given timeseries

Returns the indexing required to apply the optimal warping curve to a given timeseries (warps either into a query or into a reference).

Details

The warping is returned as a set of indices, which can be used to subscript the timeseries to be warped (or rows in a matrix, if one wants to warp a multivariate time series). In other words, warp converts the warping curve, or its inverse, into a function in the explicit form.

Multiple indices that would be mapped to a single point are averaged, with a warning. Gaps in the index sequence are filled by linear interpolation.

Parameters:
  • ddtw object specifying the warping curve to apply

  • index_referenceTrue to warp a reference, False to warp a query

Return type:

A list of indices to subscript the timeseries.

Examples

>>> from dtw import *
>>> import numpy as np

Default test data

>>> (query, reference) = dtw_test_data.sin_cos()
>>> alignment = dtw(query,reference);
>>> wq = warp(alignment,index_reference=False)
>>> wt = warp(alignment,index_reference=True)
>>> import matplotlib.pyplot as plt;            
... plt.plot(reference);
... plt.plot(query[wq]);
... plt.gca().set_title("Warping query")
>>> import matplotlib.pyplot as plt;            
... plt.plot(query);
... plt.plot(reference[wt]);
... plt.gca().set_title("Warping reference")

Asymmetric step makes it “natural” to warp the reference, because every query index has exactly one image (q->t is a function)

>>> alignment = dtw(query,reference,step_pattern=asymmetric)
>>> wt = warp(alignment,index_reference=True);
>>> plt.plot(query, "b-")                       
... plt.plot(reference[wt], "ok", facecolors='none')