Why do DTW distance metrics behave differently? #5814
-
I am new to using sktime, I was wondering why the from sktime.datasets import load_italy_power_demand
from sktime.dists_kernels import DtwDist
from sktime.distances import distance
X, _ = load_italy_power_demand(split="train", return_type="numpy3D")
dtw_dist = DtwDist()
dtw_dist(X[0], X[1])
distance(X[0], X[1], metric='dtw')
distance(X[0], X[1], metric='squared')
>>> [[4.88675167]]
>>> 2.2562779371935555
>>> 4.886751673604364 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Update: I know what is going on, this is not a bug.
So, if you pass I am not sure why it runs with 2D That would explain the behaviour? Old post (incorrect) Hm, that is curious. However, upon closer inspection, Do you perchance know which one is correct? We could calculate
from sktime.distances._numba_utils import (
_compute_pairwise_distance,
_make_3d_series,
)
_x = _make_3d_series(x)
if y is None:
y = x
_y = _make_3d_series(y)
symmetric = np.array_equal(_x, _y)
_metric_callable = _resolve_metric_to_factory(
metric, _x[0], _y[0], _METRIC_INFOS, **kwargs
)
from sktime.distances._numba_utils import to_numba_timeseries
_x = to_numba_timeseries(x)
_y = to_numba_timeseries(y)
_metric_callable = _resolve_metric_to_factory(
metric, _x, _y, _METRIC_INFOS, **kwargs
) |
Beta Was this translation helpful? Give feedback.
Update: I know what is going on, this is not a bug.
dtw_dist
is a pairwise distance, so expects - consistently with all other panel data estimators - input in one of thesktime
Panel
formats, e.g.,numpy3D
with(n_instance, n_variable, n_timepoints)
.So, if you pass
dtw_dist(X, X)
, you will get a matrix where the (0,1)-the and (1,0)-th element are, as expected, 2.256etc.I am not sure why it runs with 2D
numpy
, it seems to assume a single instance with 24 variables and 1 time point. For which the DTW distance is the same as the squared distance, if the inner distance (on scalars) is squared euclidean.That would explain the behaviour?
Old post (incorrect)
Hm, that is curious.
DtwDist
sho…