Пример #1
0
def test_square_predict(data_random_square):
    data = data_random_square

    model = SSPOR()
    model.fit(data)
    sensors = model.get_selected_sensors()
    assert data.shape == model.predict(data[:, sensors]).shape
Пример #2
0
def test_not_fitted(data_vandermonde):
    x = data_vandermonde
    model = SSPOR()

    # Should not be able to call any of these methods before fitting
    with pytest.raises(NotFittedError):
        model.predict(x)
    with pytest.raises(NotFittedError):
        model.get_selected_sensors()
    with pytest.raises(NotFittedError):
        model.get_all_sensors()
    with pytest.raises(NotFittedError):
        model.set_number_of_sensors(20)
    with pytest.raises(NotFittedError):
        model.score(x)
    with pytest.raises(NotFittedError):
        model.reconstruction_error(x)
Пример #3
0
def test_prefit_basis(data_random):
    data = data_random
    basis = Identity()
    basis.fit(data)

    # This data should be ignored during the fit
    data_to_ignore = nan * data_random

    model = SSPOR(basis=basis)
    model.fit(data_to_ignore, prefit_basis=True)
    assert not any(isnan(model.get_selected_sensors()))
Пример #4
0
def test_predict_accuracy(data_vandermonde_testing):
    # Polynomials up to degree 10 on [0, 1]
    data, x_test = data_vandermonde_testing

    model = SSPOR()
    model.fit(data, seed=1)
    model.set_number_of_sensors(8)
    sensors = model.get_selected_sensors()
    assert sqrt(mean((x_test - model.predict(x_test[sensors])) ** 2)) <= 1.0e-3

    # Should also work for row vectors
    x_test = x_test.reshape(1, -1)
    assert sqrt(mean((x_test - model.predict(x_test[:, sensors])) ** 2)) <= 1.0e-3
Пример #5
0
def test_predict(data_random):
    data = data_random

    n_sensors = 5
    model = SSPOR(n_sensors=n_sensors)
    model.fit(data)

    # Wrong size input for predict
    # (should only pass data at sensor locations)
    with pytest.raises(ValueError):
        model.predict(data)

    # Rectangular case
    sensors = model.get_selected_sensors()
    assert data.shape == model.predict(data[:, sensors]).shape
Пример #6
0
def test_n_sensors(data_random):

    # Check for bad inputs
    with pytest.raises(ValueError):
        model = SSPOR(n_sensors=0)
    with pytest.raises(ValueError):
        model = SSPOR(n_sensors=5.4)
    with pytest.raises(ValueError):
        model = SSPOR(n_sensors="1")
    with pytest.raises(ValueError):
        model = SSPOR(n_sensors=[1])

    n_sensors = 5
    x = data_random
    model = SSPOR(n_sensors=n_sensors)
    model.fit(x)

    assert len(model.get_selected_sensors()) == n_sensors
Пример #7
0
def test_set_number_of_sensors(data_vandermonde):
    x = data_vandermonde
    max_sensors = x.shape[1]

    model = SSPOR()
    model.fit(x)

    with pytest.raises(ValueError):
        model.set_number_of_sensors(max_sensors + 1)
    with pytest.raises(ValueError):
        model.set_number_of_sensors(0)
    with pytest.raises(ValueError):
        model.set_number_of_sensors(1.5)
    with pytest.raises(ValueError):
        model.set_number_of_sensors("3")

    model.set_number_of_sensors(15)
    assert len(model.get_selected_sensors()) == 15
Пример #8
0
def test_sensor_selector_properties(data_random):
    data = data_random
    model = SSPOR().fit(data)

    assert all(model.get_all_sensors() == model.all_sensors)
    assert all(model.get_selected_sensors() == model.selected_sensors)