Beispiel #1
0
def test_can_get_params():
    s = InvertedEncoding()
    param_out = s.get_params()
    logger.info('Returned Parameters: ' +
                str(param_out.get('n_channels')) +
                ', ' + str(param_out.get('range_start')) +
                ', ' + str(param_out.get('range_stop')))
Beispiel #2
0
def test_can_set_params():
    s = InvertedEncoding()
    s.set_params(n_channels=10,
                 stimulus_mode='circular',
                 range_start=-90,
                 range_stop=270,
                 channel_exp=4,
                 verbose=False)
Beispiel #3
0
def test_can_predict_from_data():
    Invt_model = InvertedEncoding()
    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))
Beispiel #4
0
def test_stimulus_mask_shift_positive():
    Invt_model = InvertedEncoding(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)
Beispiel #5
0
def test_instantiate_improper_range():
    with pytest.raises(ValueError):
        s = InvertedEncoding(6, 5, 'halfcircular', range_start=20,
                             range_stop=0)
        assert s, "Invalid InvertedEncoding instance"
Beispiel #6
0
def test_can_instantiate():
    s = InvertedEncoding()
    assert s, "Invalid InvertedEncoding instance"
Beispiel #7
0
def test_can_fit_circular_space():
    s = InvertedEncoding(6, 5, 'circular', range_stop=360)
    s.fit(X, y)
Beispiel #8
0
def test_data_amount():
    x = np.random.rand(5, 1000)
    s = InvertedEncoding()
    with pytest.raises(ValueError):
        s.fit(x, np.random.rand(5))
        assert s, "Invalid data"
Beispiel #9
0
def test_stimulus_mode():
    with pytest.raises(ValueError):
        s = InvertedEncoding(6, 5, 'random')
        assert s, "Invalid InvertedEncoding instance"
Beispiel #10
0
def test_can_score():
    Invt_model = InvertedEncoding()
    Invt_model.fit(X, y)
    score = Invt_model.score(X2, y)
    logger.info('Scores: ' + str(score))
Beispiel #11
0
def test_cannot_predict_from_data():
    Invt_model = InvertedEncoding()
    Invt_model.fit(X, y)
    with pytest.raises(ValueError):
        _ = Invt_model.predict(X2[0:n_, :].transpose())
Beispiel #12
0
def test_mismatched_observations():
    with pytest.raises(ValueError):
        Invt_model = InvertedEncoding()
        Invt_model.fit(X, y[:-50])
Beispiel #13
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 = InvertedEncoding()
        Invt_model.fit(X, y)
Beispiel #14
0
def test_ill_conditioned_train_data():
    Invt_model = InvertedEncoding()
    with pytest.raises(ValueError):
        X = np.array([[0, 0, 0], [1, 1, 1]])
        Invt_model.fit(X, np.array([0, 0, 0]))
Beispiel #15
0
def test_cannot_fit_data():
    with pytest.raises(ValueError):
        Invt_model = InvertedEncoding()
        Invt_model.fit(X.transpose(), y)
Beispiel #16
0
def test_stimulus_resolution():
    s = InvertedEncoding(6, 5, stimulus_resolution=360)
    assert s.stim_res == 360
Beispiel #17
0
def test_cannot_instantiate_channels():
    with pytest.raises(ValueError):
        s = InvertedEncoding(n_channels=0)
        assert s, "Invalid InvertedEncoding instance"
Beispiel #18
0
def test_cannot_score():
    with pytest.raises(ValueError):
        Invt_model = InvertedEncoding()
        Invt_model.fit(X, y)
        score = Invt_model.score(X2.transpose(), y)
        logger.info('Scores: ' + str(score))
Beispiel #19
0
def test_range_stimulus_mode_halfcirc():
    with pytest.raises(ValueError):
        s = InvertedEncoding(6, 5, 'halfcircular', -10, 350)
        assert s, "Invalid InvertedEncoding instance"
Beispiel #20
0
def test_stimulus_resolution_odd():
    Invt_model = InvertedEncoding(stimulus_resolution=59)
    with pytest.raises(NotImplementedError):
        Invt_model.fit(X, y)
Beispiel #21
0
def test_data_dimensions():
    x = np.random.rand(5, 10, 2)
    s = InvertedEncoding()
    with pytest.raises(ValueError):
        s.fit(x, np.random.rand(5))
Beispiel #22
0
def test_can_fit_data():
    Invt_model = InvertedEncoding()
    Invt_model.fit(X, y)