dispel.signal.dtw module#

A module dedicated to the Dynamic Time Warping.

dispel.signal.dtw.get_dtw_distance(user, reference)[source]#

Extract information about DTW metrics.

This implementation is using Dynamic Time Warping (fastdtw library) to compute the similarity measures between the user and the model paths. This algorithm returns the coupling measure value (which is the value of the similarity metric) and the attributions between a model point and the user points close enough to be considered as a potential similar point (i.e. attributions == [(m0, u0),(m1, u1),(m1, u2), (m1, u3), (m2, u1), (m2, u2), (m2, u2), (m2, u3), (m2,u4),...] with mi the ith model point index and uj the jth user point index). Then, we isolate the minimum distance between each model point and attributed user points. Those measures are in fact equivalent to those obtained with the variant Fréchet similarity measure algorithm with a back propagation. This implementation is around 30 times faster than the mentioned Fréchet algorithm.

Parameters:
  • user (DataFrame) – A pandas data frame composed of the user paths or his up sampled ones.

  • reference (DataFrame) – The reference trajectory corresponding to the current level.

Returns:

A pandas data frame which contains the DTW coupling measure, the mean and median minimum euclidean distance between the closest attributions, the standard deviation of minimum euclidean distance between the closest attributions and the sum of all the minimum euclidean distance between the closest attributions.

Return type:

pandas.Series

dispel.signal.dtw.get_minimal_matches(actual, expected, distance=2)[source]#

Compute minimal euclidean distance between actual and expected paths.

Based on the Dynamic Time Warping algorithm (fastdtw library), compute all the detected attributions between an actual and an expected trajectory and then extract the minimum ones.

Parameters:
  • actual (DataFrame) – The actual trajectory (x and y coordinates).

  • expected (DataFrame) – The expected trajectory (x and y coordinates).

  • distance (int) – The chosen metric to compute DTW, 2 being by default and means euclidean distance.

Returns:

A coupling measure and a pandas data frame with minimal attributions indexes for actual and expected trajectories and the euclidean distance between each attribution.

Return type:

Tuple[float, pandas.DataFrame]