Esempio n. 1
0
def test_can_get_params():
    s = InvertedEncoding1D()
    param_out = s.get_params()
    assert param_out.get('channel_exp') == 5
    logger.info('Returned Parameters: ' + str(param_out.get('n_channels')) +
                ', ' + str(param_out.get('range_start')) + ', ' +
                str(param_out.get('range_stop')))
Esempio n. 2
0
def test_can_instantiate():
    s = InvertedEncoding1D()
    assert s, "Invalid InvertedEncoding1D instance"
    s2 = InvertedEncoding2D(stim_xlim=[0, 1],
                            stim_ylim=[0, 1],
                            stimulus_resolution=[1, 1])
    assert s2, "Invalid InvertedEncoding2D instance"
Esempio n. 3
0
def test_can_set_params():
    s = InvertedEncoding1D()
    s.set_params(n_channels=10,
                 stimulus_mode='circular',
                 range_start=-90,
                 range_stop=270,
                 channel_exp=4,
                 verbose=False)
Esempio n. 4
0
def test_can_predict_from_data():
    Invt_model = InvertedEncoding1D()
    Invt_model.fit(X, y)
    m_reconstruct = []
    for j in np.arange(dim):
        preds = Invt_model.predict(X2[n_ * j:n_ * (j + 1), :])
        tmp = circmean(np.deg2rad(preds))
        m_reconstruct.append(np.rad2deg(tmp))
    logger.info('Reconstructed angles: ' + str(m_reconstruct))
Esempio n. 5
0
def test_data_dimensions():
    x = np.random.rand(5, 10, 2)
    s = InvertedEncoding1D()
    with pytest.raises(ValueError):
        s.fit(x, np.random.rand(5))
    s2 = InvertedEncoding2D(stim_xlim=[-1, 1],
                            stim_ylim=[-1, 1],
                            stimulus_resolution=10)
    with pytest.raises(ValueError):
        s2.fit(x, np.random.rand(5))
Esempio n. 6
0
def test_data_amount():
    x = np.random.rand(5, 1000)
    s = InvertedEncoding1D()
    with pytest.raises(ValueError):
        s.fit(x, np.random.rand(5))
        assert s, "Invalid data"
    s2 = InvertedEncoding2D(stim_xlim=[-1, 1],
                            stim_ylim=[-1, 1],
                            stimulus_resolution=10)
    with pytest.raises(ValueError):
        s2.fit(x, np.random.rand(5))
Esempio n. 7
0
def test_stimulus_mask_shift_positive():
    Invt_model = InvertedEncoding1D(6,
                                    5,
                                    range_start=10,
                                    range_stop=190,
                                    stimulus_resolution=60)
    chans, _ = Invt_model._define_channels()
    Invt_model.set_params(channels_=chans)
    with pytest.warns(RuntimeWarning):
        C = Invt_model._define_trial_activations(np.array([70]))
        tmp_C = np.repeat([0, 1, 0], 60) @ chans.transpose()
        assert np.all((C - tmp_C) < 1e-7)
Esempio n. 8
0
def test_instantiate_improper_range():
    with pytest.raises(ValueError):
        s = InvertedEncoding1D(6,
                               5,
                               'halfcircular',
                               range_start=20,
                               range_stop=0)
        assert s, "Invalid InvertedEncoding1D instance"
    with pytest.raises(ValueError):
        s2 = InvertedEncoding2D(stim_xlim=[0, -1],
                                stim_ylim=[0, -1],
                                stimulus_resolution=[10, 10])
        assert s2, "Invalid InvertedEncoding2D instance"
    with pytest.raises(ValueError):
        s2 = InvertedEncoding2D(stim_xlim=[0],
                                stim_ylim=[-1, 0],
                                stimulus_resolution=10)
        assert s2, "Invalid InvertedEncoding2D instance"
Esempio n. 9
0
def test_cannot_instantiate_1d_channels():
    with pytest.raises(ValueError):
        s = InvertedEncoding1D(n_channels=0)
        assert s, "Invalid InvertedEncoding1D instance"
Esempio n. 10
0
def test_stimulus_mode():
    with pytest.raises(ValueError):
        s = InvertedEncoding1D(6, 5, 'random')
        assert s, "Invalid InvertedEncoding1D instance"
Esempio n. 11
0
def test_stimulus_resolution_odd():
    Invt_model = InvertedEncoding1D(stimulus_resolution=59)
    with pytest.raises(NotImplementedError):
        Invt_model.fit(X, y)
Esempio n. 12
0
def test_cannot_score():
    with pytest.raises(ValueError):
        Invt_model = InvertedEncoding1D()
        Invt_model.fit(X, y)
        score = Invt_model.score(X2.transpose(), y)
        logger.info('Scores: ' + str(score))
Esempio n. 13
0
def test_can_score():
    Invt_model = InvertedEncoding1D()
    Invt_model.fit(X, y)
    score = Invt_model.score(X2, y)
    logger.info('Scores: ' + str(score))
Esempio n. 14
0
def test_can_fit_data():
    Invt_model = InvertedEncoding1D()
    Invt_model.fit(X, y)
Esempio n. 15
0
def test_range_stimulus_mode_halfcirc():
    with pytest.raises(ValueError):
        s = InvertedEncoding1D(6, 5, 'halfcircular', -10, 350)
        assert s, "Invalid InvertedEncoding1D instance"
Esempio n. 16
0
def test_1d_stimulus_resolution():
    s = InvertedEncoding1D(6, 5, stimulus_resolution=360)
    assert s.stim_res == 360
Esempio n. 17
0
def test_extra_data_dimensions():
    with pytest.raises(ValueError):
        n, dim1, dim2 = 300, 3, 3
        X = np.random.rand(n // 3, dim1, dim2)
        Invt_model = InvertedEncoding1D()
        Invt_model.fit(X, y)
Esempio n. 18
0
def test_ill_conditioned_train_data():
    Invt_model = InvertedEncoding1D()
    with pytest.raises(ValueError):
        X = np.array([[0, 0, 0], [1, 1, 1]])
        Invt_model.fit(X, np.array([0, 0, 0]))
Esempio n. 19
0
def test_cannot_fit_data():
    with pytest.raises(ValueError):
        Invt_model = InvertedEncoding1D()
        Invt_model.fit(X.transpose(), y)
Esempio n. 20
0
def test_can_fit_circular_space():
    s = InvertedEncoding1D(6, 5, 'circular', range_stop=360)
    s.fit(X, y)
Esempio n. 21
0
def test_mismatched_observations():
    with pytest.raises(ValueError):
        Invt_model = InvertedEncoding1D()
        Invt_model.fit(X, y[:-50])
Esempio n. 22
0
def test_cannot_predict_from_data():
    Invt_model = InvertedEncoding1D()
    Invt_model.fit(X, y)
    with pytest.raises(ValueError):
        _ = Invt_model.predict(X2[0:n_, :].transpose())