Skip to content

Commit 8844eb1

Browse files
committed
Adapted tests to be semi-supervised
1 parent c5bbc96 commit 8844eb1

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

aeon/anomaly_detection/series/distance_based/tests/test_rockad.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
def test_rockad_univariate():
1111
"""Test ROCKAD univariate output."""
1212
rng = check_random_state(seed=2)
13-
series = rng.normal(size=(100,))
14-
series[50:58] -= 5
13+
train_series = rng.normal(size=(100,))
14+
test_series = rng.normal(size=(100,))
15+
test_series[50:58] -= 5
1516

1617
ad = ROCKAD(
1718
n_estimators=100,
@@ -22,7 +23,8 @@ def test_rockad_univariate():
2223
stride=1,
2324
)
2425

25-
pred = ad.fit_predict(series, axis=0)
26+
ad.fit(train_series, axis=0)
27+
pred = ad.predict(test_series, axis=0)
2628

2729
assert pred.shape == (100,)
2830
assert pred.dtype == np.float64
@@ -32,9 +34,10 @@ def test_rockad_univariate():
3234
def test_rockad_multivariate():
3335
"""Test ROCKAD multivariate output."""
3436
rng = check_random_state(seed=2)
35-
series = rng.normal(size=(100, 3))
36-
series[50:58, 0] -= 5
37-
series[87:90, 1] += 0.1
37+
train_series = rng.normal(size=(100, 3))
38+
test_series = rng.normal(size=(100, 3))
39+
test_series[50:58, 0] -= 5
40+
test_series[87:90, 1] += 0.1
3841

3942
ad = ROCKAD(
4043
n_estimators=1000,
@@ -45,7 +48,8 @@ def test_rockad_multivariate():
4548
stride=1,
4649
)
4750

48-
pred = ad.fit_predict(series, axis=0)
51+
ad.fit(train_series, axis=0)
52+
pred = ad.predict(test_series, axis=0)
4953

5054
assert pred.shape == (100,)
5155
assert pred.dtype == np.float64
@@ -55,21 +59,28 @@ def test_rockad_multivariate():
5559
def test_rockad_incorrect_input():
5660
"""Test ROCKAD incorrect input."""
5761
rng = check_random_state(seed=2)
58-
series = rng.normal(size=(100,))
62+
train_series = rng.normal(size=(100,))
63+
test_series = rng.normal(size=(5,))
5964

6065
with pytest.raises(ValueError, match="The window size must be at least 1"):
6166
ad = ROCKAD(window_size=0)
62-
ad.fit_predict(series)
67+
ad.fit(train_series)
6368
with pytest.raises(ValueError, match="The stride must be at least 1"):
6469
ad = ROCKAD(stride=0)
65-
ad.fit_predict(series)
70+
ad.fit(train_series)
6671
with pytest.raises(
6772
ValueError, match=r"Window count .* has to be larger than n_neighbors .*"
6873
):
6974
ad = ROCKAD(stride=1, window_size=100)
70-
ad.fit_predict(series)
75+
ad.fit(train_series)
7176
with pytest.warns(
7277
UserWarning, match=r"Power Transform failed and thus has been disabled."
7378
):
7479
ad = ROCKAD(stride=1, window_size=5)
75-
ad.fit_predict(series)
80+
ad.fit(train_series)
81+
with pytest.raises(
82+
ValueError, match=r"window shape cannot be larger than input array shape"
83+
):
84+
ad = ROCKAD(stride=1, window_size=10)
85+
ad.fit(train_series)
86+
ad.predict(test_series)

0 commit comments

Comments
 (0)