tslearn
tslearn copied to clipboard
Is it possible to plot the DTW-Path-"Matrix" (Sakoe-Chiba Band) If yes how? If not how could we implement this?
What I mean is this: https://tslearn.readthedocs.io/en/stable/_images/sakoe_chiba.png Which is the visualization of the constraints based on the Sakoe-Chiba Settings, described here:
https://tslearn.readthedocs.io/en/stable/user_guide/dtw.html
Thanks a bunch for replies!
Hi @StefanR44
I have this on my side:
import numpy
import matplotlib.pyplot as plt
from tslearn.metrics import sakoe_chiba_mask
def plot_constraints(title, sz):
for pos in range(sz):
plt.plot([-.5, sz - .5], [pos + .5, pos + .5],
color='w', linestyle='-', linewidth=3)
plt.plot([pos + .5, pos + .5], [-.5, sz - .5],
color='w', linestyle='-', linewidth=3)
plt.xticks([])
plt.yticks([])
plt.gca().axis("off")
plt.title(title)
plt.tight_layout()
sz = 10
m = sakoe_chiba_mask(sz, sz, radius=3)
m[m == numpy.inf] = 1.
numpy.fill_diagonal(m, .5)
plt.figure()
plt.imshow(m, cmap="gray")
plot_constraints("Sakoe-Chiba mask of radius $r=3$.", sz)
Let me know if this fits your needs.