dtwPlotDensity

dtw.dtwPlotDensity(d, normalize=False, xlab='Query index', ylab='Reference index', **kwargs)

Display the cumulative cost density with the warping path overimposed

The plot is based on the cumulative cost matrix. It displays the optimal alignment as a “ridge” in the global cost landscape.

Details

The alignment must have been constructed with the keep_internals=True parameter set.

If normalize is True, the average cost per step is plotted instead of the cumulative one. Step averaging depends on the [stepPattern()] used.

Parameters:
  • d – an alignment result, object of class dtw

  • normalize – show per-step average cost instead of cumulative cost

  • xlab – label for the query axis

  • ylab – label for the reference axis

  • ... – additional parameters forwarded to plotting functions

Examples

>>> from dtw import *

A study of the “Itakura” parallelogram

A widely held misconception is that the “Itakura parallelogram” (as described in the original article) is a global constraint. Instead, it arises from local slope restrictions. Anyway, an “itakuraWindow”, is provided in this package. A comparison between the two follows.

The local constraint: three sides of the parallelogram are seen

>>> (query, reference) = dtw_test_data.sin_cos()
>>> ita = dtw(query, reference, keep_internals=True, step_pattern=typeIIIc)
>>> dtwPlotDensity(ita)                              

Symmetric step with global parallelogram-shaped constraint. Note how long (>2 steps) horizontal stretches are allowed within the window.

>>> ita = dtw(query, reference, keep_internals=True, window_type=itakuraWindow)
>>> dtwPlotDensity(ita)