Skip to content

Commit

Permalink
fix: call KNNMixin._dtw1d when independent=True (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
eonu authored Apr 13, 2024
1 parent 5062288 commit daf5d70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sequentia/models/knn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _dtwi(self: KNNMixin, A: FloatArray, B: FloatArray) -> float:

def dtw(a: FloatArray, b: FloatArray) -> float:
"""Windowed DTW wrapper function."""
return self._dtw(a, b, window=window)
return self._dtw1d(a, b, window=window)

return np.sum([dtw(A[:, i], B[:, i]) for i in range(A.shape[1])])

Expand Down
20 changes: 17 additions & 3 deletions tests/unit/test_models/knn/test_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,32 @@ def assert_fit(clf: KNNClassifier, /, *, data: SequentialDataset) -> None:

@pytest.mark.parametrize("k", [1, 2, 5])
@pytest.mark.parametrize("weighting", [None, lambda x: np.exp(-x)])
@pytest.mark.parametrize("independent", [False, True])
def test_classifier_e2e(
helpers: t.Any,
request: SubRequest,
k: int,
weighting: t.Callable | None,
dataset: SequentialDataset,
random_state: np.random.RandomState,
*,
k: int,
weighting: t.Callable | None,
independent: bool,
) -> None:
clf = KNNClassifier(k=k, weighting=weighting, random_state=random_state)
clf = KNNClassifier(
k=k,
weighting=weighting,
independent=independent,
random_state=random_state,
)

assert clf.k == k
assert clf.weighting == weighting
assert clf.independent == independent

if independent:
assert clf._dtw().__name__ == "_dtwi"
else:
assert clf._dtw().__name__ == "_dtwd"

data = dataset.copy()
data._X = data._X[:, :1] # only use one feature
Expand Down

0 comments on commit daf5d70

Please sign in to comment.