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')))
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)
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))
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)
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"
def test_can_instantiate(): s = InvertedEncoding() assert s, "Invalid InvertedEncoding instance"
def test_can_fit_circular_space(): s = InvertedEncoding(6, 5, 'circular', range_stop=360) s.fit(X, y)
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"
def test_stimulus_mode(): with pytest.raises(ValueError): s = InvertedEncoding(6, 5, 'random') assert s, "Invalid InvertedEncoding instance"
def test_can_score(): Invt_model = InvertedEncoding() Invt_model.fit(X, y) score = Invt_model.score(X2, y) logger.info('Scores: ' + str(score))
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())
def test_mismatched_observations(): with pytest.raises(ValueError): Invt_model = InvertedEncoding() Invt_model.fit(X, y[:-50])
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)
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]))
def test_cannot_fit_data(): with pytest.raises(ValueError): Invt_model = InvertedEncoding() Invt_model.fit(X.transpose(), y)
def test_stimulus_resolution(): s = InvertedEncoding(6, 5, stimulus_resolution=360) assert s.stim_res == 360
def test_cannot_instantiate_channels(): with pytest.raises(ValueError): s = InvertedEncoding(n_channels=0) assert s, "Invalid InvertedEncoding instance"
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))
def test_range_stimulus_mode_halfcirc(): with pytest.raises(ValueError): s = InvertedEncoding(6, 5, 'halfcircular', -10, 350) assert s, "Invalid InvertedEncoding instance"
def test_stimulus_resolution_odd(): Invt_model = InvertedEncoding(stimulus_resolution=59) with pytest.raises(NotImplementedError): Invt_model.fit(X, y)
def test_data_dimensions(): x = np.random.rand(5, 10, 2) s = InvertedEncoding() with pytest.raises(ValueError): s.fit(x, np.random.rand(5))
def test_can_fit_data(): Invt_model = InvertedEncoding() Invt_model.fit(X, y)