Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative discrepancy #5

Closed
asardaes opened this issue Dec 16, 2017 · 10 comments
Closed

Negative discrepancy #5

asardaes opened this issue Dec 16, 2017 · 10 comments

Comments

@asardaes
Copy link

asardaes commented Dec 16, 2017

Hello, I'm testing this python version of soft-DTW and I am seeing the following:

import sdtw
import numpy as np
x = np.array([0,0,0,-0.033203,-0.057491,-0.08566,-0.11358,-0.13903,-0.16222,-0.18402])
y = np.array([0,0,0,-0.048463,-0.073921,-0.10089,-0.12832,-0.1578,-0.19184,-0.23162])
x = x.reshape(-1,1)
y = y.reshape(-1,1)
from sklearn.metrics.pairwise import euclidean_distances
D = euclidean_distances(x,y, squared=True)
sdtw_obj = sdtw.SoftDTW(D)
sdtw_obj.compute()
#> -14.175522634015779

It seems counter intuitive to obtain negative values for a discrepancy, but maybe it is normal in this case? I would like to corroborate.

@mblondel
Copy link
Owner

This is expected behavior. The smoothing of the min based on the log-sum-exp can lead to negative values. In addition, like the original DTW, soft-DTW doesn't fulfill the triangle inequality.

@asardaes
Copy link
Author

Ok, thanks for the confirmation.

On a similar note, if I set y to x.copy() I get a non-zero value. Is this also expected?

@mblondel
Copy link
Owner

Indeed, soft-DTW(x, x) is not zero because soft-DTW considers all paths, not just the diagonal one. soft-DTW is most useful when you want to differentiate it.

@asardaes
Copy link
Author

I see, thanks for the clarification. One last question if you don't mind: is soft-DTW always symmetric?

@mblondel
Copy link
Owner

It is.

@asardaes
Copy link
Author

Thanks!

@Maghoumi
Copy link

Maghoumi commented May 12, 2019

I know this issue was closed, but could you @mblondel kindly clarify something please:
When used as a loss metric, how should one interpret this negative dissimilarity number?

Imagine that my goal is to reduce the soft-DTW dissimilarity between two sequences x and y using gradient descent. If the dissimilarity score for some values of x and y is negative, how should one proceed? Can I always minimize the abs(sdtw(x, y)) or do I need to handle negative cases as a special case?

Thanks in advance,

@mblondel
Copy link
Owner

Essentially, soft-dtw returns as value the log partition function of a probabilistic model (more precisely a conditional random field over alignments). This is why the value can be negative, just as the log likelihood can be negative.

If you care about non-negativity, a debiasing/normalization is proposed by @marcocuturi in #10.

@Maghoumi
Copy link

Thanks a lot for the clarification and the prompt response @mblondel.

I had seen @marcocuturi's formula and the blog post, but I think I need to study it more to understand what it does and how it's applicable to my problem.

@stellarpower
Copy link

Is a negative loss still usable? I.e. that as the loss continues to drop more negative, the signals are closer together than they were? Or is it something that needs correcting for in gradient descent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants