def test_fun_window_agg(self):
        """Verify that the anomaly score aggregation works as intended"""
        # window = 2, alternating anomaly scores
        window = 2
        scorer = KMeansScorer(window=window)
        anomaly_scores = TimeSeries.from_values(np.resize([1, -1], 10))
        aggreg_scores = scorer._fun_window_agg([anomaly_scores], window=window)[0]
        # in the last window, the score is not zeroed
        np.testing.assert_array_almost_equal(
            aggreg_scores.values(), np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, -1]]).T
        )
        assert aggreg_scores.time_index.equals(anomaly_scores.time_index)

        # window = 3, increment of 2 anomaly scores
        window = 3
        scorer = KMeansScorer(window=window)
        anomaly_scores = linear_timeseries(length=10, start_value=2, end_value=20)
        aggreg_scores = scorer._fun_window_agg([anomaly_scores], window=window)[0]
        # on the last "window" values, difference of only 1 between consecutive aggregated scores
        np.testing.assert_array_almost_equal(
            aggreg_scores.values(), np.array([[4, 6, 8, 10, 12, 14, 16, 18, 19, 20]]).T
        )
        assert aggreg_scores.time_index.equals(anomaly_scores.time_index)

        # window = 6, increment of 2 anomaly scores
        window = 6
        scorer = KMeansScorer(window=window)
        anomaly_scores = linear_timeseries(length=10, start_value=2, end_value=20)
        aggreg_scores = scorer._fun_window_agg([anomaly_scores], window=window)[0]
        # on the last "window" values, difference of only 1 between consecutive aggregated scores
        np.testing.assert_array_almost_equal(
            aggreg_scores.values(), np.array([[7, 9, 11, 13, 15, 16, 17, 18, 19, 20]]).T
        )
        assert aggreg_scores.time_index.equals(anomaly_scores.time_index)

        # window = 7, increment of 2 anomaly scores
        window = 7
        scorer = KMeansScorer(window=window)
        anomaly_scores = linear_timeseries(length=10, start_value=2, end_value=20)
        aggreg_scores = scorer._fun_window_agg([anomaly_scores], window=window)[0]
        # on the last "window" values, difference of only 1 between consecutive aggregated scores
        np.testing.assert_array_almost_equal(
            aggreg_scores.values(),
            np.array([[8, 10, 12, 14, 15, 16, 17, 18, 19, 20]]).T,
        )
        assert aggreg_scores.time_index.equals(anomaly_scores.time_index)
Verify that the anomaly score aggregation works as intended
darts/tests/ad/test_scorers.py