예제 #1
0
def test_identity_feature_names(data_random):
    x = data_random
    model = Identity().fit(x)

    # Default names
    expected_names = [f"x{i}" for i in range(x.shape[1])]
    assert model.get_feature_names() == expected_names

    # Given names
    custome_names = [f"y{i+1}" for i in range(x.shape[1])]
    assert model.get_feature_names(
        input_features=custome_names) == custome_names
예제 #2
0
    def __init__(self, observables=None, differentiator=None, regressor=None):
        if observables is None:
            observables = Identity()
        if differentiator is None:
            differentiator = FiniteDifference()
        if regressor is None:
            regressor = DMD()

        self.observables = observables
        self.differentiator = differentiator
        self.regressor = regressor
예제 #3
0
from numpy import stack
from numpy.testing import assert_allclose
from sklearn.exceptions import NotFittedError
from sklearn.utils.validation import check_is_fitted

from pykoopman.observables import Identity
from pykoopman.observables import Polynomial


@pytest.fixture
def data_small():
    t = linspace(0, 5, 10)
    return stack((t, t**2), axis=1)


@pytest.mark.parametrize("observables", [Identity(), Polynomial()])
def test_if_fitted(observables, data_random):
    x = data_random
    with pytest.raises(NotFittedError):
        observables.transform(x)

    with pytest.raises(NotFittedError):
        observables.inverse(x)

    with pytest.raises(NotFittedError):
        observables.get_feature_names()

    observables.fit(x)
    check_is_fitted(observables)

예제 #4
0
    # Test with a target
    assert model.score(x[::2], y=x[1::2]) > 0.8


def test_score_complex_data(data_random_complex):
    x = data_random_complex
    model = Koopman().fit(x)

    with pytest.raises(ValueError):
        model.score(x, cast_as_real=False)


@pytest.mark.parametrize(
    "observables",
    [
        Identity(),
        Polynomial(),
        TimeDelay(),
        pytest.lazy_fixture("data_custom_observables"),
    ],
)
def test_observables_integration(data_random, observables):
    x = data_random
    model = Koopman(observables=observables).fit(x)
    check_is_fitted(model)

    y = model.predict(x)
    assert y.shape[1] == x.shape[1]


@pytest.mark.parametrize(
예제 #5
0
from pykoopman.observables import CustomObservables
from pykoopman.observables import Identity
from pykoopman.observables import Polynomial
from pykoopman.observables import TimeDelay


@pytest.fixture
def data_small():
    t = linspace(0, 5, 10)
    return stack((t, t**2), axis=1)


@pytest.mark.parametrize(
    "observables",
    [
        Identity(),
        Polynomial(),
        TimeDelay(),
        pytest.lazy_fixture("data_custom_observables"),
    ],
)
def test_if_fitted(observables, data_random):
    x = data_random
    with pytest.raises(NotFittedError):
        observables.transform(x)

    with pytest.raises(NotFittedError):
        observables.inverse(x)

    with pytest.raises(NotFittedError):
        observables.get_feature_names()