Exemplo n.º 1
0
def test_likelihood_ratio_pac():
    # Test that likelihood_ratio returns a near zero p_value with PAC
    sdar = fast_fitted_model(StableDAR, sigin=_sigin)
    dar = fast_fitted_model(DAR, sigin=_sigin)
    ar = fast_fitted_model(AR, sigin=_sigin)
    har = fast_fitted_model(HAR, sigin=_sigin)

    for h0 in [ar, har]:
        for h1 in [dar, sdar]:
            p_value = h1.likelihood_ratio(h0)
            assert_greater(1e-3, p_value)
Exemplo n.º 2
0
def test_likelihood_ratio_noise():
    # Test that likelihood_ratio returns a positive p_value with noise
    sdar = fast_fitted_model(StableDAR, sigin=_noise)
    dar = fast_fitted_model(DAR, sigin=_noise)
    ar = fast_fitted_model(AR, sigin=_noise)
    har = fast_fitted_model(HAR, sigin=_noise)

    for h0 in [ar, har]:
        for h1 in [dar, sdar]:
            p_value = h1.likelihood_ratio(h0)
            assert_greater(p_value, 0)
Exemplo n.º 3
0
def test_dehumming_improve_snr():
    # Test that dehumming removes the added noise
    rng = np.random.RandomState(0)
    fs = 250.
    enf = 50.
    clean = rng.randn(512)
    noisy = clean.copy()

    # add ENF noise
    time = np.arange(512) / float(fs)
    for harmonic in (1, 2):
        noisy += np.sin(time * 2 * np.pi * enf * harmonic) / harmonic

    for dim in [(1, 512), (512, ), (512, 1)]:
        dehummed = dehummer(
            noisy.reshape(*dim), fs, enf=enf)
        assert_greater(norm(noisy - clean), norm(dehummed.ravel() - clean))
        assert_array_equal(dehummed.shape, dim)

    # test that the dehumming does not accept 2d arrays
    assert_raises(ValueError, dehummer, noisy.reshape(2, 256), fs)
Exemplo n.º 4
0
def test_surrogates():
    # Test the surrogates comodulogram
    for method in ALL_PAC_METRICS:
        msg = 'with method=%s' % method
        if method in BICOHERENCE_PAC_METRICS or method == 'jiang':
            continue

        n_surrogates = 10
        est = ComodTest(method=method, n_surrogates=n_surrogates).fit(signal)
        assert_array_equal(est.comod_.shape, (n_low, n_high), err_msg=msg)
        assert_array_equal(est.surrogates_.shape,
                           (n_surrogates, n_low, n_high),
                           err_msg=msg)

        # z-score
        z_score = est.comod_z_score_
        assert_array_equal(z_score.shape, (n_low, n_high), err_msg=msg)
        if method != 'jiang':  # 'jiang' method does not estimate CFC but CFD
            assert_greater(z_score[1, 1], z_score[-1, -1], msg=msg)

        # surrogate_max
        surrogate_max = est.surrogate_max_
        assert_array_equal(surrogate_max.shape, (n_surrogates, ))
        assert_greater(est.comod_[1, 1], surrogate_max.max(), msg=msg)
        assert_greater(surrogate_max.max(), est.comod_[-1, -1], msg=msg)

    # Smoke test with contours in the plotting function
    est.plot(contour_level=0.01, contour_method='comod_max')
    est.plot(contour_level=3, contour_method='z_score')
    plt.close('all')
Exemplo n.º 5
0
def test_delay_shape():
    est = fast_delay()
    assert_equal(est.neg_log_likelihood_.shape, est.delays_ms_.shape)
    assert_greater(est.neg_log_likelihood_.shape[0], 1)
    i_best = np.nanargmin(est.neg_log_likelihood_)
    assert_equal(est.best_delay_ms_, est.delays_ms_[i_best])