def test_lower_bounds_inequalities(): """Test that the expected inequalities are verified.""" # Toy dataset rng = np.random.RandomState(42) n_samples_train, n_samples_test, n_timestamps = 20, 30, 60 window_size = 0.1 X_train = rng.randn(n_samples_train, n_timestamps) X_test = rng.randn(n_samples_test, n_timestamps) # DTW X_dtw = pairwise_distances(X_test, X_train, dtw) region = sakoe_chiba_band(n_timestamps, window_size=window_size) X_dtw_window = pairwise_distances(X_test, X_train, dtw_sakoechiba, window_size=window_size) # Lower bounds lb_yi = lower_bound_yi(X_train, X_test) lb_kim = lower_bound_kim(X_train, X_test) lb_keogh = lower_bound_keogh(X_train, X_test, region) lb_improved = lower_bound_improved(X_train, X_test, region) # Sanity check EPS = 1e-8 np.testing.assert_array_less(lb_yi, X_dtw + EPS) np.testing.assert_array_less(lb_kim, X_dtw + EPS) np.testing.assert_array_less(lb_keogh, X_dtw_window + EPS) np.testing.assert_array_less(lb_improved, X_dtw_window + EPS) np.testing.assert_array_less(lb_keogh, lb_improved + EPS)
def test_actual_results_lower_bound_yi(X_train, X_test, arr_desired): """Test that the actual results are the expected ones.""" arr_actual = lower_bound_yi(X_train, X_test) np.testing.assert_allclose(arr_actual, arr_desired, atol=1e-5, rtol=0)
def test_check_consistent_lengths(X, Y, err_msg): """Test 'lower_bound_yi' parameter validation.""" with pytest.raises(ValueError, match=re.escape(err_msg)): lower_bound_yi(X, Y)