def test_bad_parameters(): with pytest.raises(ValueError): PolynomialLibrary(degree=-1) with pytest.raises(ValueError): PolynomialLibrary(degree=1.5) with pytest.raises(ValueError): PolynomialLibrary(include_interaction=False, interaction_only=True) with pytest.raises(ValueError): FourierLibrary(n_frequencies=-1) with pytest.raises(ValueError): FourierLibrary(n_frequencies=-1) with pytest.raises(ValueError): FourierLibrary(n_frequencies=2.2) with pytest.raises(ValueError): FourierLibrary(include_sin=False, include_cos=False) with pytest.raises(ValueError): library_functions = [lambda x: x, lambda x: x**2, lambda x: 0 * x] function_names = [lambda s: str(s), lambda s: "{}^2".format(s)] CustomLibrary(library_functions=library_functions, function_names=function_names)
], ) def test_simulate(data): x, t = data model = SINDy() model.fit(x, t) x1 = model.simulate(x[0], t) assert len(x1) == len(t) @pytest.mark.parametrize( "library", [ PolynomialLibrary(degree=3), FourierLibrary(n_frequencies=3), pytest.lazy_fixture("data_custom_library"), ], ) def test_libraries(data_lorenz, library): x, t = data_lorenz model = SINDy(feature_library=library) model.fit(x, t) s = model.score(x, t) assert s <= 1 @pytest.mark.parametrize( "data", [
], ) def test_simulate(data): x, t = data model = SINDy() model.fit(x, t) x1 = model.simulate(x[0], t) assert len(x1) == len(t) @pytest.mark.parametrize( "library", [ PolynomialLibrary(degree=3), FourierLibrary(n_frequencies=3), pytest.lazy_fixture("data_custom_library"), PolynomialLibrary() + FourierLibrary(), ], ) def test_libraries(data_lorenz, library): x, t = data_lorenz model = SINDy(feature_library=library) model.fit(x, t) s = model.score(x, t) assert s <= 1 def test_integration_smoothed_finite_difference(data_lorenz): x, t = data_lorenz
def test_fourier_options(data_lorenz): x, t = data_lorenz library = FourierLibrary(include_cos=False) library.fit_transform(x) check_is_fitted(library)
FourierLibrary(n_frequencies=2.2) with pytest.raises(ValueError): FourierLibrary(include_sin=False, include_cos=False) with pytest.raises(ValueError): library_functions = [lambda x: x, lambda x: x**2, lambda x: 0 * x] function_names = [lambda s: str(s), lambda s: "{}^2".format(s)] CustomLibrary(library_functions=library_functions, function_names=function_names) @pytest.mark.parametrize( "library", [ IdentityLibrary(), PolynomialLibrary(), FourierLibrary(), IdentityLibrary() + PolynomialLibrary(), pytest.lazy_fixture("data_custom_library"), ], ) def test_fit_transform(data_lorenz, library): x, t = data_lorenz library.fit_transform(x) check_is_fitted(library) @pytest.mark.parametrize( "library", [ IdentityLibrary(), PolynomialLibrary(),
FourierLibrary(n_frequencies=2.2) with pytest.raises(ValueError): FourierLibrary(include_sin=False, include_cos=False) with pytest.raises(ValueError): library_functions = [lambda x: x, lambda x: x**2, lambda x: 0 * x] function_names = [lambda s: str(s), lambda s: "{}^2".format(s)] CustomLibrary(library_functions=library_functions, function_names=function_names) @pytest.mark.parametrize( "library", [ IdentityLibrary(), PolynomialLibrary(), FourierLibrary(), pytest.lazy_fixture("data_custom_library"), ], ) def test_fit_transform(data_lorenz, library): x, t = data_lorenz library.fit_transform(x) check_is_fitted(library) @pytest.mark.parametrize( "library", [ IdentityLibrary(), PolynomialLibrary(), FourierLibrary(),