nickgillian / grt

gesture recognition toolkit
853 stars 286 forks source link

DTW fix #154

Closed terziman closed 5 years ago

terziman commented 5 years ago

Simple fix for DTW to reduce prediction time.

I stumbled on one edge case that made predictions for DTW potentially take hours because the dynamic programming approach was not working as expected. Indeed, when paths in the distance matrix append to have a cost of zero, the cost of the path would be recomputed every time, independently of the sign of the value (-0 < 0 is always false).

This lead in my case to re-computation of the end path every time, i.e. millions of time, which basically froze the application.

Instead of doing a simple inferior test, the proposed fix leverage the standard signbit function to test the actual sign of the value, even if the value is equal to zero, therefore fixing the dynamic programming approach.

nickgillian commented 5 years ago

Thanks for catching and fixing this edge case! Apologies this took so long to merge.