Esempio n. 1
0
def _compare_values(v, v2):
    if isinstance(v, np.ndarray):
        assert_array_equal(v, v2)
    elif isinstance(v, dict):
        for key, value in v.items():
            _compare_values(v[key], v2[key])
    elif isinstance(v, np.random.RandomState):
        for s, s2 in zip(v.get_state(), v2.get_state()):
            _compare_values(s, s2)
    else:
        assert_equal(v, v2)
Esempio n. 2
0
def test_mask_iterator():
    # Test the mask iterator length and the shape of the elements
    fs = 200.
    tmin, tmax = -0.05, 0.2
    n_points = 200
    events = np.arange(0, n_points, int(fs * 0.3))
    masks = MaskIterator(events, tmin, tmax, n_points, fs)
    masks_list = [m for m in masks]

    # test that the length is correct
    n_masks_0 = len(masks)
    n_masks_1 = len(masks_list)
    assert_equal(n_masks_0, n_masks_1)

    # test that the masks are of the correct shape
    for mask in masks_list:
        assert_array_equal(mask.shape, (1, n_points))
Esempio n. 3
0
def test_raw_to_mask_no_events():
    # test that no events gives masks entirely False
    raw = create_empty_raw()
    low_sig, high_sig, mask = raw_to_mask(raw,
                                          ixs=0,
                                          events=None,
                                          tmin=None,
                                          tmax=None)
    for one_mask in mask:
        assert_true(np.all(~one_mask))

    # test with no events and tmin, tmax
    tmin, tmax = 0.2, 0.6
    low_sig, high_sig, mask = raw_to_mask(raw,
                                          ixs=0,
                                          events=None,
                                          tmin=tmin,
                                          tmax=tmax)
    for one_mask in mask:
        assert_equal(one_mask[~one_mask].size,
                     int((tmax - tmin) * raw.info['sfreq']))
Esempio n. 4
0
def test_degrees_of_freedom():
    # test the number of fitted parameters in the model
    model_params = {'ordar': 5, 'ordriv': 2, 'criterion': False}
    dar = fast_fitted_model(model_params=model_params)
    assert_equal(dar.degrees_of_freedom(), 6 * 6)

    model_params = {'ordar': 5, 'ordriv': 0, 'criterion': False}
    dar = fast_fitted_model(model_params=model_params)
    assert_equal(dar.degrees_of_freedom(), 6 * 1)

    model_params = {'ordar': 1, 'ordriv': 2, 'criterion': False}
    dar = fast_fitted_model(model_params=model_params)
    assert_equal(dar.degrees_of_freedom(), 2 * 6)

    model_params = {'ordar': 10, 'ordriv': 2, 'criterion': False}
    ar = fast_fitted_model(AR, model_params=model_params)
    assert_equal(ar.degrees_of_freedom(), 10 + 1)

    model_params = {'ordar': 10, 'ordriv': 2, 'criterion': False}
    har = fast_fitted_model(HAR, model_params=model_params)
    assert_equal(har.degrees_of_freedom(), 10 + 6)
Esempio n. 5
0
def test_peak_locking_shape():
    percentiles = [5, 25, 50, 75, 95]
    plkg = PeakLocking(fs=fs,
                       low_fq=low_fq,
                       high_fq_range=high_fq_range,
                       percentiles=percentiles)
    plkg.fit(signal)
    n_high, n_window = plkg.time_frequency_.shape
    n_percentiles, n_window_2 = plkg.time_average_.shape
    assert_equal(n_high, len(high_fq_range))
    assert_equal(n_percentiles, len(percentiles))
    assert_equal(n_window, n_window_2)
Esempio n. 6
0
def test_comod_correct_maximum():
    # Test that the PAC is maximum at the correct location in the comodulogram
    for method in ALL_PAC_METRICS:
        est = ComodTest(method=method, progress_bar=True).fit(signal)
        comod = est.comod_
        # test the shape of the comodulogram
        assert_array_equal(comod.shape, (n_low, n_high))

        # the bicoherence metrics fail this test with current parameters
        if method in BICOHERENCE_PAC_METRICS or method == 'jiang':
            continue

        low_fq_0, high_fq_0, max_pac = est.get_maximum_pac()
        assert_equal(low_fq_0, low_fq)
        assert_equal(high_fq_0, high_fq)
        assert_equal(max_pac, comod.max())
        assert_true(np.all(comod > 0))
Esempio n. 7
0
def test_mask_iterator_length():
    # Test the mask iterator length
    rng = np.random.RandomState(0)
    fs = 200.
    n_points = 200

    tmin, tmax = -0.05, 0.2
    events = np.arange(0, n_points, int(fs * 0.3))
    masks = MaskIterator(events, tmin, tmax, n_points, fs)
    assert_equal(len(masks), 1)

    tmin, tmax = [-0.05, -0.02, 0], [-0.2, -0.2, 0.1]
    events = np.arange(0, n_points, int(fs * 0.3))
    masks = MaskIterator(events, tmin, tmax, n_points, fs)
    assert_equal(len(masks), len(tmin))

    n_kinds = 3
    tmin, tmax = -0.05, 0.2
    events = np.arange(0, n_points, 10)
    events = np.vstack([events, rng.randint(n_kinds, size=len(events))]).T
    masks = MaskIterator(events, tmin, tmax, n_points, fs)
    assert_equal(len(masks), n_kinds)
Esempio n. 8
0
def test_fake_delayed():
    # Test that fake_delayed does nothing but returning the input arg
    assert_equal(twice, _fake_delayed(twice))
    assert_equal(42, _fake_delayed(42))
Esempio n. 9
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])
Esempio n. 10
0
def test_prime_factors():
    # Test that the prime factor decomposition products to the input integer
    for n in range(3, 200, 2):
        factors = prime_factors(n)
        assert_equal(np.product(factors), n)
Esempio n. 11
0
def test_argmax_2d():
    # Test that argmax_2d gives the correct indices of the max
    rng = np.random.RandomState(0)
    a = rng.randn(4, 3)
    i, j = argmax_2d(a)
    assert_equal(a[i, j], a.max())
Esempio n. 12
0
def test_correct_size():
    # Test that the signals are 1D and with the correct number of points
    for n_points_in in np.int_(np.logspace(1, 3, 5)):
        signal = simulate_pac_default(n_points=n_points_in)
        assert_equal(signal.size, n_points_in)
        assert_equal(signal.ndim, 1)