Skip to content

Commit

Permalink
TST: Break apart integration test for nan derivatives.
Browse files Browse the repository at this point in the history
Also, make test/differentiation/test_differentiation_methods.py just
test/test_differentiation.py.  Unneccessary nesting.

Previously, test_nan_derivatives asked whether the model fit by SINDy when
FiniteDifference gave NaN endpointswas close to the model fit without nans.
This is an integration test that is really asking whether FiniteDifference is
calculating derivatives in a consistent with drop_endpoints=True and False.

Also, a bit faster but this test was fast to begin with.
  • Loading branch information
Jacob-Stevens-Haas committed May 12, 2023
1 parent 3445cb9 commit f7f48f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ def test_centered_difference_variable_timestep_length():
assert len(centered_difference(x, t) == len(x))


# Fixtures: data sets to be re-used in multiple tests
# data_derivative_1d and data_derivative_2d are defined
# in ../conftest.py
def test_nan_derivatives(data_lorenz):
x, t = data_lorenz
x_dot = FiniteDifference(drop_endpoints=False)(x, t)
x_dot_nans = FiniteDifference(drop_endpoints=True)(x, t)
np.testing.assert_allclose(x_dot_nans[1:-1], x_dot[1:-1])
assert np.isnan(x_dot_nans[:1]).all() and np.isnan(x_dot_nans[-1:]).all()


def test_forward_difference_1d(data_derivative_1d):
Expand Down
15 changes: 0 additions & 15 deletions test/test_pysindy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from sklearn.utils.validation import check_is_fitted

from pysindy import SINDy
from pysindy.differentiation import FiniteDifference
from pysindy.differentiation import SINDyDerivative
from pysindy.differentiation import SmoothedFiniteDifference
from pysindy.feature_library import FourierLibrary
Expand Down Expand Up @@ -81,20 +80,6 @@ def test_improper_shape_input(data_1d):
check_is_fitted(model)


def test_nan_derivatives(data_lorenz):
x, t = data_lorenz
model0 = SINDy(differentiation_method=FiniteDifference(drop_endpoints=False))
model0.fit(x, t)

model = SINDy(differentiation_method=FiniteDifference(drop_endpoints=True))
model.fit(x, t)
check_is_fitted(model)

result = model.score(x, t=t)
expected = model0.score(x, t=t)
np.testing.assert_allclose(result, expected, rtol=1e-4)


@pytest.mark.parametrize(
"data",
[
Expand Down

0 comments on commit f7f48f1

Please sign in to comment.