ahwillia / affinewarp

An implementation of piecewise linear time warping for multi-dimensional time series alignment
MIT License
162 stars 36 forks source link

Sample frequency changed after time warp #17

Closed Wasabi111 closed 2 years ago

Wasabi111 commented 2 years ago

Hey Alex,

I have a simple question when I read the paper Discovering Precise Temporal Patterns in Large Scale Neural Recordings through Robust and Interpretable Time Warping. Since linear warping functions will compress or stretch the signal, the time length of the neural activity will change. In discrete time series, the total data points remain the same. That means the sample frequency which is points divided by time length will changed too. Thus, the frequencies of neural activities will change. I wonder if this frequency change exists and how you deal with it. Thank you!

Best, Dongming

ahwillia commented 2 years ago

Hi Dongming,

For shift-only warping, there is no change in the sampling frequency but you are correct that for linear / piecewise linear warping the effective sampling frequency changes when you apply the inverse warping functions to the data.

Note that we apply the inverse warping functions only for visualization purposes. If you read the methods section carefully, you'll see we optimize the model we always apply the warping to the "template" and never to the data itself. This is a subtle, but important point. It means that the sampling frequency of the data isn't messed with while we fit the model.

Let me know if that answers your question.

Wasabi111 commented 2 years ago

Hi Alex.

Thanks for your answer. It is very useful!

May I comprehend it as that you segment the data to many activities and warp the same activities to a "template", so you get templates for different activities. Although the warping function may change sampling frequencies, the "template" has fix time length and points thus sets the same sampling frequencies. If so. you do interpolation or remove some points while warping to the "template". Since "template" will not be inverse warpped to the data, the data sampling frequency remains unchanged.

ahwillia commented 2 years ago

Yes that's correct, the sampling frequency of the data is not changed for the purposes of model fitting. One could say that the "sampling frequency" of the template is changed via linear interpolation. Note that the template isn't really sampled at all -- it is a parameter of the model that is learned during optimization. So in a sense we can upsample/downsample the template without loss of precision because it is an idealized function.

Wasabi111 commented 2 years ago

Thank you very much, Alex!