Tuesday, December 25, 2012

Dynamic Time Warping - UCR Suite in C#

So, as mentioned in this comment, to achieve fast DTW calculations, one way is to use "lower bounds" in the DTW process, the UCR Suite is a great example of how this can be acheived.

I wanted to post this in my blog a long time ago, just didn't have the time to do everything for this.
the UCR Suite is written in C++ and since it's really easy moving around pointers than it is in C# safe code, I understand the choice of language.
However, with some thought the same code could be written in C# and be even faster and more efficient.

So, since i am primarily a .net coder, and wanted to only use managed code and no unsafe exceptions, I had to take the C++ code and port it to C# code.

When built in "Release" configurations it is quite faster than the C++ Suite.

Prof. Eamonn Keogh and company did a great job optimizing DTW and the applications are endless.

I've placed the C# Code as a Visual Studio 2010 Solution on github.
Get the code here!

This code is written without unsafe code.
I might publish another unsafe version for even better performance.

2 comments:

  1. can u please tell or post a doc here which can briefly explain how actually it searches the query in data. In all the papers published they have just shown that , they are using equilidean distances, Z-normalization and some minimum bound technique for reducing calculation. But no one
    have told about how actually it does the search.

    ReplyDelete
  2. Erez, nice work... I too have worked on converting the UCR code to C# and have wrestled with the pointer math. In your conversion, it looks like you read the input file all at once, where as, in the original code it looks like they read the input file in chunks. Is that correct? If true, is that how you eliminated the pointer issues. Thanks, David

    ReplyDelete