def test_pham_pos_weight(get_covmats): # Test that weight must be strictly positive n_trials, n_channels, w_val = 5, 3, 2 covmats = get_covmats(n_trials, n_channels) w = w_val * np.ones(n_trials) with pytest.raises(ValueError): # not strictly positive weight w[0] = 0 ajd_pham(covmats, sample_weight=w)
def test_pham(get_covmats): """Test pham's ajd""" n_trials, n_channels, w_val = 5, 3, 2 covmats = get_covmats(n_trials, n_channels) V, D = ajd_pham(covmats) assert V.shape == (n_channels, n_channels) assert D.shape == (n_trials, n_channels, n_channels) Vw, Dw = ajd_pham(covmats, sample_weight=w_val * np.ones(n_trials)) assert_array_equal(V, Vw) # same result as ajd_pham without weight assert_array_equal(D, Dw)
def test_pham_zero_weight(get_covmats): # now test that setting one weight to almost zero it's almost # like not passing the matrix n_trials, n_channels, w_val = 5, 3, 2 covmats = get_covmats(n_trials, n_channels) w = w_val * np.ones(n_trials) V, D = ajd_pham(covmats[1:], sample_weight=w[1:]) w[0] = 1e-12 Vw, Dw = ajd_pham(covmats, sample_weight=w) assert V == approx(Vw, rel=1e-4, abs=1e-8) assert D == approx(Dw[1:], rel=1e-4, abs=1e-8)
def test_pham(): """Test pham's ajd""" Nt = 100 covmats, diags, A = generate_cov(Nt, 3) V, D = ajd_pham(covmats) w = 5 * np.ones(Nt) Vw, Dw = ajd_pham(covmats, sample_weight=w) assert_array_equal(V, Vw) # same result as ajd_pham without weight assert_array_equal(D, Dw) # Test that weight must be strictly positive with pytest.raises(ValueError): # not strictly positive weight w[0] = 0 ajd_pham(covmats, sample_weight=w) # now test that setting one weight to almost zero it's almost # like not passing the matrix V, D = ajd_pham(covmats[1:]) w[0] = 1e-12 Vw, Dw = ajd_pham(covmats, sample_weight=w) assert_allclose(V, Vw, rtol=1e-4, atol=1e-8) assert_allclose(D, Dw[1:], rtol=1e-4, atol=1e-8)
def test_pham(): """Test pham's ajd""" covmats, diags, A = generate_cov(100, 3) V, D = ajd_pham(covmats)