DynamicTimeWarping / dtw-python

Python port of R's Comprehensive Dynamic Time Warp algorithms package
https://dynamictimewarping.github.io
GNU General Public License v3.0
279 stars 35 forks source link

.T method mutates the object #76

Closed vspinu closed 10 months ago

vspinu commented 1 year ago

Describe the bug

Currently .T() method mutates step pattern objects which might result in unexpected behavior, especially with built-in patterns.

To Reproduce

from dtw.stepPattern import asymmetric
print(asymmetric)
Step pattern recursion:
 g[i,j] = min(
     g[i-1,j  ] +     d[i  ,j  ] ,
     g[i-1,j-1] +     d[i  ,j  ] ,
     g[i-1,j-2] +     d[i  ,j  ] ,
 ) 
Normalization hint: N
tt = asymmetric.T()
print(asymmetric)
Step pattern recursion:
 g[i,j] = min(
     g[i  ,j-1] +     d[i  ,j  ] ,
     g[i-1,j-1] +     d[i  ,j  ] ,
     g[i-2,j-1] +     d[i  ,j  ] ,
 ) 
Normalization hint: M

Version

dtw: '1.3.0'

vspinu commented 1 year ago

If this is an expected behavior, maybe a copy method could be added instead?

tonigi commented 1 year ago

Ouch! Thanks for spotting it. No, step patterns should be immutable. A modified copy should be returned. Will fix asap.

tonigi commented 10 months ago

Hopefully fixed in ae3b3657a1dd2d793fb5346e188826de15e0b4c1 and 1.3.1