Test that CSP component ordering works as expected.
()
| 469 | |
| 470 | |
| 471 | def test_csp_component_ordering(): |
| 472 | """Test that CSP component ordering works as expected.""" |
| 473 | x, y = deterministic_toy_data(["class_a", "class_b"]) |
| 474 | |
| 475 | csp = CSP(component_order="invalid") |
| 476 | with pytest.raises(ValueError, match="Invalid value"): |
| 477 | csp.fit(x, y) |
| 478 | |
| 479 | # component_order='alternate' only works with two classes |
| 480 | csp = CSP(component_order="alternate") |
| 481 | with pytest.raises(ValueError): |
| 482 | csp.fit(np.zeros((3, 0, 0)), ["a", "b", "c"]) |
| 483 | |
| 484 | p_alt = CSP(component_order="alternate").fit(x, y).patterns_ |
| 485 | p_mut = CSP(component_order="mutual_info").fit(x, y).patterns_ |
| 486 | |
| 487 | # This permutation of p_alt and p_mut is explained by the particular |
| 488 | # eigenvalues of the toy data: [0.06, 0.1, 0.5, 0.8]. |
| 489 | # p_alt arranges them to [0.8, 0.06, 0.5, 0.1] |
| 490 | # p_mut arranges them to [0.06, 0.1, 0.8, 0.5] |
| 491 | assert_array_almost_equal(p_alt, p_mut[[2, 0, 3, 1]]) |
| 492 | |
| 493 | |
| 494 | @pytest.mark.filterwarnings("ignore:.*Only one sample available.*") |
nothing calls this directly
no test coverage detected